2
0

🔊 Even more

This commit is contained in:
Baptiste Arnaud
2024-04-17 11:01:34 +02:00
parent 40dfa8cc60
commit fb09706c23

View File

@@ -31,6 +31,7 @@ export const resumeWhatsAppFlow = async ({
phoneNumberId, phoneNumberId,
contact, contact,
}: Props): Promise<{ message: string }> => { }: Props): Promise<{ message: string }> => {
console.log('fire')
const messageSendDate = new Date(Number(receivedMessage.timestamp) * 1000) const messageSendDate = new Date(Number(receivedMessage.timestamp) * 1000)
const messageSentBefore3MinutesAgo = const messageSentBefore3MinutesAgo =
messageSendDate.getTime() < Date.now() - 180000 messageSendDate.getTime() < Date.now() - 180000
@@ -65,6 +66,8 @@ export const resumeWhatsAppFlow = async ({
accessToken: credentials?.systemUserAccessToken, accessToken: credentials?.systemUserAccessToken,
}) })
console.log('incoming message content:', reply)
const session = await getSession(sessionId) const session = await getSession(sessionId)
const isSessionExpired = const isSessionExpired =
@@ -72,6 +75,7 @@ export const resumeWhatsAppFlow = async ({
isDefined(session.state.expiryTimeout) && isDefined(session.state.expiryTimeout) &&
session?.updatedAt.getTime() + session.state.expiryTimeout < Date.now() session?.updatedAt.getTime() + session.state.expiryTimeout < Date.now()
console.log('Process')
const resumeResponse = const resumeResponse =
session && !isSessionExpired session && !isSessionExpired
? await continueBotFlow(reply, { ? await continueBotFlow(reply, {
@@ -87,6 +91,8 @@ export const resumeWhatsAppFlow = async ({
}) })
: { error: 'workspaceId not found' } : { error: 'workspaceId not found' }
console.log('resumeResponse:', resumeResponse)
if ('error' in resumeResponse) { if ('error' in resumeResponse) {
console.log('Chat not starting:', resumeResponse.error) console.log('Chat not starting:', resumeResponse.error)
return { return {