Add logging

This commit is contained in:
khalid@traclabs.com
2026-05-05 12:50:55 -05:00
parent c3958060ac
commit 8af4397803

View File

@@ -54,6 +54,24 @@ export function createWebhookSmsRouter(deps: WebhookSmsRouterDeps): Router {
// Respond quickly — Vonage expects a 200 within a few seconds // Respond quickly — Vonage expects a 200 within a few seconds
res.status(200).json({ status: 'received' }); res.status(200).json({ status: 'received' });
const body = (req.body ?? {}) as Record<string, unknown>;
const rawText = typeof body.text === 'string' ? body.text : '';
logger.info(
{
event: 'sms.webhook_inbound_payload',
contentType: req.headers['content-type'],
bodyKeys: Object.keys(body),
bodyRedacted: {
...body,
from: typeof body.from === 'string' ? maskPhone(body.from) : body.from,
to: typeof body.to === 'string' ? maskPhone(body.to) : body.to,
msisdn: typeof body.msisdn === 'string' ? maskPhone(body.msisdn) : body.msisdn,
text: rawText ? `${rawText.slice(0, 80)}${rawText.length > 80 ? '…' : ''}` : body.text,
},
},
'Inbound webhook payload (redacted)'
);
// Process async // Process async
handleInbound(req.body, deps).catch(err => { handleInbound(req.body, deps).catch(err => {
logger.error({ event: 'sms.handler_error', error: (err as Error).message }, 'SMS handler error'); logger.error({ event: 'sms.handler_error', error: (err as Error).message }, 'SMS handler error');