|
|
@ -38,6 +38,14 @@ export class WebhookServer {
|
|
|
|
return new Response('OK', { status: 200 });
|
|
|
|
return new Response('OK', { status: 200 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Debug logging for all incoming requests
|
|
|
|
|
|
|
|
console.log('ℹ️ Incoming request:', {
|
|
|
|
|
|
|
|
method: request.method,
|
|
|
|
|
|
|
|
path: url.pathname,
|
|
|
|
|
|
|
|
headers: Object.fromEntries(request.headers),
|
|
|
|
|
|
|
|
query: Object.fromEntries(url.searchParams)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Method validation
|
|
|
|
// 1. Method validation
|
|
|
|
if (request.method !== 'POST') {
|
|
|
|
if (request.method !== 'POST') {
|
|
|
|
return new Response('Method not allowed', { status: 405 });
|
|
|
|
return new Response('Method not allowed', { status: 405 });
|
|
|
@ -64,8 +72,18 @@ export class WebhookServer {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 5. Route events
|
|
|
|
// 5. Route events
|
|
|
|
|
|
|
|
console.log('ℹ️ Webhook event received:', {
|
|
|
|
|
|
|
|
event: payload.event,
|
|
|
|
|
|
|
|
instance: payload.instance,
|
|
|
|
|
|
|
|
data: payload.data ? '[...]' : null
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
switch (payload.event) {
|
|
|
|
switch (payload.event) {
|
|
|
|
case 'messages.upsert':
|
|
|
|
case 'messages.upsert':
|
|
|
|
|
|
|
|
console.log('ℹ️ Handling message upsert:', {
|
|
|
|
|
|
|
|
groupId: payload.data?.key?.remoteJid,
|
|
|
|
|
|
|
|
message: payload.data?.message?.conversation
|
|
|
|
|
|
|
|
});
|
|
|
|
await this.handleMessageUpsert(payload.data);
|
|
|
|
await this.handleMessageUpsert(payload.data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
// Other events will be added later
|
|
|
|
// Other events will be added later
|
|
|
|