fix webhook data parsing
This commit is contained in:
@@ -127,11 +127,23 @@ app.use(express.json());
|
|||||||
|
|
||||||
app.post('/webhook', async (req: express.Request, res: express.Response) => {
|
app.post('/webhook', async (req: express.Request, res: express.Response) => {
|
||||||
log('debug', 'Received webhook request:', req.body);
|
log('debug', 'Received webhook request:', req.body);
|
||||||
const { message, text, from } = req.body as {
|
|
||||||
message?: WhatsAppMessage;
|
let message: WhatsAppMessage | undefined;
|
||||||
text?: string;
|
let text: string | undefined;
|
||||||
from?: string;
|
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;
|
const incoming = message || text;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user