Skip to content

Commit

Permalink
Merge pull request #90 from P4-Games/feature/login-send-message
Browse files Browse the repository at this point in the history
merge feature/login-send-message into develop
  • Loading branch information
dappsar authored Sep 18, 2024
2 parents 3707cfb + 4291c45 commit f0b3468
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/app/api/_hooks/api-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const endpoints = {
}
},
backend: {
sendMessage: () => getFullBotEndpoint('chatbot/conversations/operator-reply'),
sendMessage: () => getFullBotEndpoint('chatbot/conversations/send-message'),
control: () => getFullBotEndpoint('chatbot/conversations/control')
}
}
33 changes: 12 additions & 21 deletions src/app/api/v1/auth/code/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,34 @@ export async function POST(req: Request) {
// ----------------------------------------------------------------------

async function send2FACode(phone: string, code: number, codeMsg: string) {
// Search last conversationIn User in bot}
let phoneToMsg = phone

// Search last conversationIn User in bot with last 8 phone-digits
console.info('entered send2FACode', phone, code)
const lastUserConversation: LastUserConversation = await getLastConversacionUserId(phone)
console.info('lastUserConversation', phone, lastUserConversation)

if (!lastUserConversation) {
// user not found
console.info('lastUserConversation NOT_FOUND', phone, lastUserConversation)
return false
console.info('lastUserConversation NOT_FOUND, using phone:', phone)
} else {
phoneToMsg = lastUserConversation.channel_user_id
console.info(
'lastUserConversation FOUND, using channel_user_id as phone:',
lastUserConversation.channel_user_id,
lastUserConversation.id
)
}

// Set control to operator
const botControlData = {
data_token: BOT_API_TOKEN,
id: lastUserConversation.id,
control: 'operator'
}
const botControlEndpoint = endpoints.backend.control()
console.info('lastUserConversation pre-post', botControlEndpoint, botControlData)
const botControlOperatorResult = await post(botControlEndpoint, botControlData)
console.info('botControlOperatorResult', botControlOperatorResult)

// Send 2FA code by whatsapp with operator-reply endpoint
const botSendMsgEndpoint = endpoints.backend.sendMessage()
const botSendMsgData = {
data_token: BOT_API_TOKEN,
channel_user_id: lastUserConversation.channel_user_id,
channel_user_id: phoneToMsg,
message: codeMsg.replace('{2FA_CODE}', code.toString())
}
console.info('botSendMsgData', botSendMsgData)
const botSendMsgResult = await post(botSendMsgEndpoint, botSendMsgData)
console.info('botSendMsgResult', botSendMsgResult)

// Restore control to assitance
botControlData.control = 'assistant'
const botControlAssistantResult = await post(botControlEndpoint, botControlData)
console.info('botControlAssistantResult', botControlAssistantResult)

return true
}
2 changes: 1 addition & 1 deletion src/sections/auth/jwt/jwt-login-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function JwtLoginView() {
const router = useRouter()
const [errorMsg, setErrorMsg] = useState('')
const [codeSent, setCodeSent] = useState(false)
const { counting, countdown, startCountdown } = useCountdownSeconds(10)
const { counting, countdown, startCountdown } = useCountdownSeconds(120)
const [selectedCountry, setSelectedCountry] = useState('54')
const searchParams = useSearchParams()
const countryCodes = allCountries
Expand Down

0 comments on commit f0b3468

Please sign in to comment.