From ce17ce506197f6f2b928ae955f8bb6d97c30b05e Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 26 Feb 2024 13:54:41 +0100 Subject: [PATCH] :bug: (whatsapp) Fix webhook when having 2 phone numbers in same WA account --- apps/viewer/src/features/whatsapp/api/receiveMessage.ts | 1 + packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/apps/viewer/src/features/whatsapp/api/receiveMessage.ts b/apps/viewer/src/features/whatsapp/api/receiveMessage.ts index b3ca08121..b580e9f15 100644 --- a/apps/viewer/src/features/whatsapp/api/receiveMessage.ts +++ b/apps/viewer/src/features/whatsapp/api/receiveMessage.ts @@ -36,6 +36,7 @@ export const receiveMessage = publicProcedure return resumeWhatsAppFlow({ receivedMessage, sessionId: `wa-${phoneNumberId}-${receivedMessage.from}`, + phoneNumberId, credentialsId, workspaceId, contact: { diff --git a/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts b/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts index 9b62484c7..27dbbed83 100644 --- a/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts +++ b/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts @@ -18,6 +18,7 @@ type Props = { receivedMessage: WhatsAppIncomingMessage sessionId: string credentialsId?: string + phoneNumberId?: string workspaceId?: string contact: NonNullable['contact'] } @@ -27,6 +28,7 @@ export const resumeWhatsAppFlow = async ({ sessionId, workspaceId, credentialsId, + phoneNumberId, contact, }: Props): Promise<{ message: string }> => { const messageSendDate = new Date(Number(receivedMessage.timestamp) * 1000) @@ -54,6 +56,13 @@ export const resumeWhatsAppFlow = async ({ } } + if (credentials.phoneNumberId !== phoneNumberId) { + console.error('Credentials point to another phone ID, skipping...') + return { + message: 'Message received', + } + } + const reply = await getIncomingMessageContent({ message: receivedMessage, typebotId: typebot?.id,