Spaces:
Sleeping
Sleeping
fix: use gateway call agent for notification delivery (#381)
Browse filesSwitches 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
CHANGED
|
@@ -7,8 +7,8 @@ import { logger } from '@/lib/logger';
|
|
| 7 |
/**
|
| 8 |
* POST /api/notifications/deliver - Notification delivery daemon endpoint
|
| 9 |
*
|
| 10 |
-
* Polls undelivered notifications and sends them to
|
| 11 |
-
* via OpenClaw
|
| 12 |
*/
|
| 13 |
export async function POST(request: NextRequest) {
|
| 14 |
const auth = requireRole(request, 'operator');
|
|
@@ -64,12 +64,12 @@ export async function POST(request: NextRequest) {
|
|
| 64 |
|
| 65 |
for (const notification of undeliveredNotifications) {
|
| 66 |
try {
|
| 67 |
-
// Skip if agent
|
| 68 |
-
if (!notification.
|
| 69 |
errors.push({
|
| 70 |
notification_id: notification.id,
|
| 71 |
recipient: notification.recipient,
|
| 72 |
-
error: '
|
| 73 |
});
|
| 74 |
errorCount++;
|
| 75 |
continue;
|
|
@@ -79,20 +79,26 @@ export async function POST(request: NextRequest) {
|
|
| 79 |
const message = formatNotificationMessage(notification);
|
| 80 |
|
| 81 |
if (!dry_run) {
|
| 82 |
-
// Send notification via OpenClaw
|
| 83 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
const { stdout, stderr } = await runOpenClaw(
|
| 85 |
[
|
| 86 |
'gateway',
|
| 87 |
-
'
|
| 88 |
-
'
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
],
|
| 93 |
-
{ timeoutMs:
|
| 94 |
);
|
| 95 |
-
|
| 96 |
if (stderr && stderr.includes('error')) {
|
| 97 |
throw new Error(`OpenClaw error: ${stderr}`);
|
| 98 |
}
|
|
|
|
| 7 |
/**
|
| 8 |
* POST /api/notifications/deliver - Notification delivery daemon endpoint
|
| 9 |
*
|
| 10 |
+
* Polls undelivered notifications and sends them to agents
|
| 11 |
+
* via OpenClaw gateway call agent command
|
| 12 |
*/
|
| 13 |
export async function POST(request: NextRequest) {
|
| 14 |
const auth = requireRole(request, 'operator');
|
|
|
|
| 64 |
|
| 65 |
for (const notification of undeliveredNotifications) {
|
| 66 |
try {
|
| 67 |
+
// Skip if agent is not registered in the agents table
|
| 68 |
+
if (!notification.recipient) {
|
| 69 |
errors.push({
|
| 70 |
notification_id: notification.id,
|
| 71 |
recipient: notification.recipient,
|
| 72 |
+
error: 'Notification has no recipient'
|
| 73 |
});
|
| 74 |
errorCount++;
|
| 75 |
continue;
|
|
|
|
| 79 |
const message = formatNotificationMessage(notification);
|
| 80 |
|
| 81 |
if (!dry_run) {
|
| 82 |
+
// Send notification via OpenClaw gateway call agent
|
| 83 |
try {
|
| 84 |
+
const invokeParams = {
|
| 85 |
+
message,
|
| 86 |
+
agentId: notification.recipient,
|
| 87 |
+
idempotencyKey: `notification-${notification.id}-${Date.now()}`,
|
| 88 |
+
deliver: false,
|
| 89 |
+
};
|
| 90 |
const { stdout, stderr } = await runOpenClaw(
|
| 91 |
[
|
| 92 |
'gateway',
|
| 93 |
+
'call',
|
| 94 |
+
'agent',
|
| 95 |
+
'--params',
|
| 96 |
+
JSON.stringify(invokeParams),
|
| 97 |
+
'--json'
|
| 98 |
],
|
| 99 |
+
{ timeoutMs: 30000 }
|
| 100 |
);
|
| 101 |
+
|
| 102 |
if (stderr && stderr.includes('error')) {
|
| 103 |
throw new Error(`OpenClaw error: ${stderr}`);
|
| 104 |
}
|