fix webhook data parsing

This commit is contained in:
josedario87
2025-06-04 23:33:02 -06:00
parent 41f6ace10a
commit 37c4384dec

View File

@@ -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;