Skip to content

Commit 3dd545b

Browse files
feat(sms-webhook): add /send endpoint for outgoing notifications
Allows sending WhatsApp/SMS notifications via HTTP POST: curl -X POST localhost:3456/send \ -H "Content-Type: application/json" \ -d '{"title":"Test","message":"Hello","type":"custom"}' Supports types: task_complete, review_ready, error, custom Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7174f5b commit 3dd545b

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

src/hooks/sms-webhook.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
processIncomingResponse,
2222
loadSMSConfig,
2323
cleanupExpiredPrompts,
24+
sendNotification,
2425
} from './sms-notify.js';
2526
import {
2627
queueAction,
@@ -449,6 +450,59 @@ export function startWebhookServer(port: number = 3456): void {
449450
return;
450451
}
451452

453+
// Send outgoing notification endpoint
454+
if (url.pathname === '/send' && req.method === 'POST') {
455+
let body = '';
456+
req.on('data', (chunk) => {
457+
body += chunk;
458+
if (body.length > MAX_BODY_SIZE) {
459+
req.destroy();
460+
}
461+
});
462+
463+
req.on('end', async () => {
464+
try {
465+
const payload = JSON.parse(body);
466+
const message = payload.message || payload.body || '';
467+
const title = payload.title || 'Notification';
468+
const type = payload.type || 'custom';
469+
470+
if (!message) {
471+
res.writeHead(400, { 'Content-Type': 'application/json' });
472+
res.end(
473+
JSON.stringify({ success: false, error: 'Message required' })
474+
);
475+
return;
476+
}
477+
478+
const result = await sendNotification({
479+
type: type as
480+
| 'task_complete'
481+
| 'review_ready'
482+
| 'error'
483+
| 'custom',
484+
title,
485+
message,
486+
});
487+
488+
res.writeHead(result.success ? 200 : 500, {
489+
'Content-Type': 'application/json',
490+
});
491+
res.end(JSON.stringify(result));
492+
} catch (err) {
493+
console.error('[sms-webhook] Send error:', err);
494+
res.writeHead(500, { 'Content-Type': 'application/json' });
495+
res.end(
496+
JSON.stringify({
497+
success: false,
498+
error: err instanceof Error ? err.message : 'Send failed',
499+
})
500+
);
501+
}
502+
});
503+
return;
504+
}
505+
452506
res.writeHead(404);
453507
res.end('Not found');
454508
}

0 commit comments

Comments
 (0)