Skip to content

Commit

Permalink
🐛 (whatsapp) Fix webhook when having 2 phone numbers in same WA account
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 26, 2024
1 parent fe98f2a commit ce17ce5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/viewer/src/features/whatsapp/api/receiveMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const receiveMessage = publicProcedure
return resumeWhatsAppFlow({
receivedMessage,
sessionId: `wa-${phoneNumberId}-${receivedMessage.from}`,
phoneNumberId,
credentialsId,
workspaceId,
contact: {
Expand Down
9 changes: 9 additions & 0 deletions packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
receivedMessage: WhatsAppIncomingMessage
sessionId: string
credentialsId?: string
phoneNumberId?: string
workspaceId?: string
contact: NonNullable<SessionState['whatsApp']>['contact']
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ce17ce5

Please sign in to comment.