From d980fc1a4eeaf1ad8dacf908d7df9da65d54b592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arriola?= Date: Sun, 15 Mar 2026 05:31:05 -0600 Subject: [PATCH] fix: use gateway call agent for notification delivery (#381) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switches notification delivery from sessions_send to gateway call agent command. No longer requires session_key — uses agent name (recipient) directly. Timeout increased 10s to 30s. --- src/app/api/notifications/deliver/route.ts | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/app/api/notifications/deliver/route.ts b/src/app/api/notifications/deliver/route.ts index 28b6b1a..8854757 100644 --- a/src/app/api/notifications/deliver/route.ts +++ b/src/app/api/notifications/deliver/route.ts @@ -7,8 +7,8 @@ import { logger } from '@/lib/logger'; /** * POST /api/notifications/deliver - Notification delivery daemon endpoint * - * Polls undelivered notifications and sends them to agent sessions - * via OpenClaw sessions_send command + * Polls undelivered notifications and sends them to agents + * via OpenClaw gateway call agent command */ export async function POST(request: NextRequest) { const auth = requireRole(request, 'operator'); @@ -64,12 +64,12 @@ export async function POST(request: NextRequest) { for (const notification of undeliveredNotifications) { try { - // Skip if agent doesn't have session key - if (!notification.session_key) { + // Skip if agent is not registered in the agents table + if (!notification.recipient) { errors.push({ notification_id: notification.id, recipient: notification.recipient, - error: 'Agent has no session key configured' + error: 'Notification has no recipient' }); errorCount++; continue; @@ -79,20 +79,26 @@ export async function POST(request: NextRequest) { const message = formatNotificationMessage(notification); if (!dry_run) { - // Send notification via OpenClaw sessions_send + // Send notification via OpenClaw gateway call agent try { + const invokeParams = { + message, + agentId: notification.recipient, + idempotencyKey: `notification-${notification.id}-${Date.now()}`, + deliver: false, + }; const { stdout, stderr } = await runOpenClaw( [ 'gateway', - 'sessions_send', - '--session', - notification.session_key, - '--message', - message + 'call', + 'agent', + '--params', + JSON.stringify(invokeParams), + '--json' ], - { timeoutMs: 10000 } + { timeoutMs: 30000 } ); - + if (stderr && stderr.includes('error')) { throw new Error(`OpenClaw error: ${stderr}`); }