CognxSafeTrack commited on
Commit Β·
b0907ad
1
Parent(s): 5fae74c
fix: restore whatsapp routes and add diagnostic logs
Browse files
apps/api/src/routes/whatsapp.ts
CHANGED
|
@@ -175,27 +175,15 @@ export async function whatsappRoutes(fastify: FastifyInstance) {
|
|
| 175 |
// ββ 4. Background Processing (enqueue to Worker) ββ
|
| 176 |
setImmediate(async () => {
|
| 177 |
try {
|
| 178 |
-
const parsed = WebhookPayloadSchema.safeParse(
|
| 179 |
-
if (!parsed.success)
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
const { scheduleInboundMessage } = await import('../services/queue');
|
| 182 |
const payload = parsed.data;
|
| 183 |
|
| 184 |
-
for (const entry of payload.entry) {
|
| 185 |
-
for (const change of entry.changes) {
|
| 186 |
-
const messages = change.value.messages ?? [];
|
| 187 |
-
|
| 188 |
-
for (const message of messages) {
|
| 189 |
-
const phone = message.from;
|
| 190 |
-
const messageId = message.id;
|
| 191 |
-
|
| 192 |
-
if (message.type === 'text' && message.text) {
|
| 193 |
-
await scheduleInboundMessage({ phone, text: message.text.body, messageId });
|
| 194 |
-
|
| 195 |
-
} else if (message.type === 'interactive' && message.interactive) {
|
| 196 |
-
let text = '';
|
| 197 |
-
if (message.interactive.type === 'button_reply' && message.interactive.button_reply) {
|
| 198 |
-
text = message.interactive.button_reply.id;
|
| 199 |
} else if (message.interactive.type === 'list_reply' && message.interactive.list_reply) {
|
| 200 |
text = message.interactive.list_reply.id;
|
| 201 |
}
|
|
|
|
| 175 |
// ββ 4. Background Processing (enqueue to Worker) ββ
|
| 176 |
setImmediate(async () => {
|
| 177 |
try {
|
| 178 |
+
const parsed = WebhookPayloadSchema.safeParse(body); // Use 'body' here
|
| 179 |
+
if (!parsed.success) {
|
| 180 |
+
fastify.log.warn(`[WEBHOOK] Failed to parse webhook payload: ${parsed.error.message}`);
|
| 181 |
+
return;
|
| 182 |
+
}
|
| 183 |
|
| 184 |
const { scheduleInboundMessage } = await import('../services/queue');
|
| 185 |
const payload = parsed.data;
|
| 186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
} else if (message.interactive.type === 'list_reply' && message.interactive.list_reply) {
|
| 188 |
text = message.interactive.list_reply.id;
|
| 189 |
}
|