From 37c4384dec119f0c49711a8b0201ac1e7bd8c697 Mon Sep 17 00:00:00 2001 From: josedario87 <71241187+josedario87@users.noreply.github.com> Date: Wed, 4 Jun 2025 23:33:02 -0600 Subject: [PATCH] fix webhook data parsing --- whatsapp-router/src/index.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/whatsapp-router/src/index.ts b/whatsapp-router/src/index.ts index 36daaa6..35a937d 100644 --- a/whatsapp-router/src/index.ts +++ b/whatsapp-router/src/index.ts @@ -127,11 +127,23 @@ app.use(express.json()); app.post('/webhook', async (req: express.Request, res: express.Response) => { log('debug', 'Received webhook request:', req.body); - const { message, text, from } = req.body as { - message?: WhatsAppMessage; - text?: string; - from?: string; - }; + + let message: WhatsAppMessage | undefined; + let text: string | undefined; + let from: string | undefined; + + if (req.body && req.body.data) { + // New webhook format from nucleo-whatsapp + message = req.body.data as WhatsAppMessage; + text = (req.body.data.body as string) || req.body.data.text; + from = req.body.data.from; + } else { + ({ message, text, from } = req.body as { + message?: WhatsAppMessage; + text?: string; + from?: string; + }); + } const incoming = message || text;