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,