From 9f39c6621fd04103d901ee8234eebc42f0fdff37 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 21 May 2024 14:28:46 +0200 Subject: [PATCH] :bug: (wa) Fix session stuck into reply state --- .../bot-engine/whatsapp/resumeWhatsAppFlow.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts b/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts index 418a39610..852643033 100644 --- a/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts +++ b/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts @@ -69,23 +69,25 @@ export const resumeWhatsAppFlow = async ({ 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 = session && isDefined(session.state.expiryTimeout) && 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 = session && !isSessionExpired ? await continueBotFlow(reply, {