2
0

🐛 (wa) Fix session stuck into reply state

This commit is contained in:
Baptiste Arnaud
2024-05-21 14:28:46 +02:00
parent 618322e13e
commit 9f39c6621f

View File

@@ -69,23 +69,25 @@ export const resumeWhatsAppFlow = async ({
const session = await getSession(sessionId) const session = await getSession(sessionId)
if (session?.isReplying) {
console.log('Is currently replying, skipping...')
return {
message: 'Message received',
}
}
await setIsReplyingInChatSession({
existingSessionId: session?.id,
newSessionId: sessionId,
})
const isSessionExpired = const isSessionExpired =
session && session &&
isDefined(session.state.expiryTimeout) && isDefined(session.state.expiryTimeout) &&
session?.updatedAt.getTime() + session.state.expiryTimeout < Date.now() session?.updatedAt.getTime() + session.state.expiryTimeout < Date.now()
if (session?.isReplying) {
if (!isSessionExpired) {
console.log('Is currently replying, skipping...')
return {
message: 'Message received',
}
}
} else {
await setIsReplyingInChatSession({
existingSessionId: session?.id,
newSessionId: sessionId,
})
}
const resumeResponse = const resumeResponse =
session && !isSessionExpired session && !isSessionExpired
? await continueBotFlow(reply, { ? await continueBotFlow(reply, {