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