|
|
@ -41,12 +41,6 @@ export class WebhookServer {
|
|
|
|
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
console.log('ℹ️ Incoming webhook request:')
|
|
|
|
console.log('ℹ️ Incoming webhook request:')
|
|
|
|
|
|
|
|
|
|
|
|
// console.log('ℹ️ Incoming webhook request:', {
|
|
|
|
|
|
|
|
// method: request.method,
|
|
|
|
|
|
|
|
// path: url.pathname,
|
|
|
|
|
|
|
|
// time: new Date().toISOString()
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Method validation
|
|
|
|
// 1. Method validation
|
|
|
@ -83,10 +77,12 @@ export class WebhookServer {
|
|
|
|
|
|
|
|
|
|
|
|
switch (payload.event) {
|
|
|
|
switch (payload.event) {
|
|
|
|
case 'messages.upsert':
|
|
|
|
case 'messages.upsert':
|
|
|
|
console.log('ℹ️ Handling message upsert:', {
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
groupId: payload.data?.key?.remoteJid,
|
|
|
|
console.log('ℹ️ Handling message upsert:', {
|
|
|
|
message: payload.data?.message?.conversation
|
|
|
|
groupId: payload.data?.key?.remoteJid,
|
|
|
|
});
|
|
|
|
message: payload.data?.message?.conversation
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
await WebhookServer.handleMessageUpsert(payload.data);
|
|
|
|
await WebhookServer.handleMessageUpsert(payload.data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
// Other events will be added later
|
|
|
|
// Other events will be added later
|
|
|
@ -105,8 +101,10 @@ export class WebhookServer {
|
|
|
|
|
|
|
|
|
|
|
|
static async handleMessageUpsert(data: any) {
|
|
|
|
static async handleMessageUpsert(data: any) {
|
|
|
|
if (!data?.key?.remoteJid || !data.message || !data.message.conversation) {
|
|
|
|
if (!data?.key?.remoteJid || !data.message || !data.message.conversation) {
|
|
|
|
console.log('⚠️ Invalid message format - missing required fields');
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
console.log(data);
|
|
|
|
console.log('⚠️ Invalid message format - missing required fields');
|
|
|
|
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|