log los eventos del webhook
All checks were successful
Deploy conversation layer / deploy (push) Successful in 19s
All checks were successful
Deploy conversation layer / deploy (push) Successful in 19s
This commit is contained in:
@@ -113,6 +113,13 @@ app.use(express.json());
|
|||||||
app.post('/webhook', async (req: express.Request, res: express.Response) => {
|
app.post('/webhook', async (req: express.Request, res: express.Response) => {
|
||||||
const { message, text, from } = req.body as { message?: WhatsAppMessage; text?: string; from?: string };
|
const { message, text, from } = req.body as { message?: WhatsAppMessage; text?: string; from?: string };
|
||||||
const incoming = message || text;
|
const incoming = message || text;
|
||||||
|
|
||||||
|
if (incoming) {
|
||||||
|
const tipo = typeof incoming === 'string' ? 'texto' : 'objeto';
|
||||||
|
const origen = from || (message?.chatId ?? 'desconocido');
|
||||||
|
log('info', `📩 Mensaje recibido (${tipo}) de ${origen}`);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!incoming) return res.sendStatus(200);
|
if (!incoming) return res.sendStatus(200);
|
||||||
if (!openWaUrl) throw new Error('Service URLs not configured');
|
if (!openWaUrl) throw new Error('Service URLs not configured');
|
||||||
@@ -125,9 +132,11 @@ app.post('/webhook', async (req: express.Request, res: express.Response) => {
|
|||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Error processing message', err.message);
|
console.error('Error processing message', err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.listen(port, async () => {
|
app.listen(port, async () => {
|
||||||
console.log(`WhatsApp router listening on ${port}`);
|
console.log(`WhatsApp router listening on ${port}`);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user