2
0

🐛 (whatsapp) Fix webhook when having 2 phone numbers in same WA account

This commit is contained in:
Baptiste Arnaud
2024-02-26 13:54:41 +01:00
parent fe98f2a9b6
commit ce17ce5061
2 changed files with 10 additions and 0 deletions

View File

@ -36,6 +36,7 @@ export const receiveMessage = publicProcedure
return resumeWhatsAppFlow({ return resumeWhatsAppFlow({
receivedMessage, receivedMessage,
sessionId: `wa-${phoneNumberId}-${receivedMessage.from}`, sessionId: `wa-${phoneNumberId}-${receivedMessage.from}`,
phoneNumberId,
credentialsId, credentialsId,
workspaceId, workspaceId,
contact: { contact: {

View File

@ -18,6 +18,7 @@ type Props = {
receivedMessage: WhatsAppIncomingMessage receivedMessage: WhatsAppIncomingMessage
sessionId: string sessionId: string
credentialsId?: string credentialsId?: string
phoneNumberId?: string
workspaceId?: string workspaceId?: string
contact: NonNullable<SessionState['whatsApp']>['contact'] contact: NonNullable<SessionState['whatsApp']>['contact']
} }
@ -27,6 +28,7 @@ export const resumeWhatsAppFlow = async ({
sessionId, sessionId,
workspaceId, workspaceId,
credentialsId, credentialsId,
phoneNumberId,
contact, contact,
}: Props): Promise<{ message: string }> => { }: Props): Promise<{ message: string }> => {
const messageSendDate = new Date(Number(receivedMessage.timestamp) * 1000) 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({ const reply = await getIncomingMessageContent({
message: receivedMessage, message: receivedMessage,
typebotId: typebot?.id, typebotId: typebot?.id,