Add logging
This commit is contained in:
@@ -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');
|
||||||
|
|||||||
Reference in New Issue
Block a user