Files
whatsappNucleo/server/api/debug/webhook-receiver.post.ts
josedario87 71593b25e9
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m3s
Feature: Receptor de webhooks interno para debug
- Endpoint POST /api/debug/webhook-receiver para recibir webhooks
- Almacenamiento en memoria de ultimos 100 eventos
- Endpoint GET/DELETE para consultar/limpiar eventos
- Nueva tab Webhooks en seccion Debug con polling cada 5s
2025-12-02 21:14:39 -06:00

33 lines
977 B
TypeScript

/**
* POST /api/debug/webhook-receiver
* Internal endpoint to receive webhooks for debugging
* Stores events in memory and emits via SSE
*/
import { debugWebhookStore } from '../../services/debug/webhook-store'
export default defineEventHandler(async (event) => {
const body = await readBody(event)
const headers = getHeaders(event)
const webhookEvent = {
id: crypto.randomUUID(),
receivedAt: new Date().toISOString(),
event: body.event || 'unknown',
timestamp: body.timestamp,
data: body.data || body,
headers: {
'x-webhook-event': headers['x-webhook-event'],
'x-webhook-timestamp': headers['x-webhook-timestamp'],
'x-webhook-signature': headers['x-webhook-signature'],
'content-type': headers['content-type'],
}
}
// Store the event
debugWebhookStore.addEvent(webhookEvent)
console.log(`[Debug Webhook] Received event: ${webhookEvent.event}`)
return { success: true, message: 'Event received' }
})