🐛 (whatsapp) Fix webhook when having 2 phone numbers in same WA account
This commit is contained in:
@ -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: {
|
||||||
|
@ -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,
|
||||||
|
Reference in New Issue
Block a user