Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(notification): support rich agent push payloads (#18391)

Tsuki7de904e28fd7
diff --git a/apps/server/src/services/push/PushChannel.ts b/apps/server/src/services/push/PushChannel.ts
index ee1fa085558..dcbe3e6aab4 100644
--- a/apps/server/src/services/push/PushChannel.ts
+++ b/apps/server/src/services/push/PushChannel.ts
@@ -58,10 +58,17 @@ export class PushChannel {
body: ctx.content,
channelId: DEFAULT_PUSH_CHANNEL_ID,
data: {
+ ...ctx.pushPresentation?.data,
+ // Routing and identity fields are owned by the delivery context. Keep
+ // them after caller-provided presentation data so custom metadata can
+ // never redirect a tap or impersonate another notification scenario.
notificationId: ctx.notificationId,
+ type: ctx.type,
url: ctx.actionUrl,
},
+ mutableContent: ctx.pushPresentation?.mutableContent,
priority: 'high',
+ richContent: ctx.pushPresentation?.image ? { image: ctx.pushPresentation.image } : undefined,
sound: 'default',
title: ctx.title,
to: t.expoToken,
diff --git a/apps/server/src/services/push/__tests__/PushChannel.test.ts b/apps/server/src/services/push/__tests__/PushChannel.test.ts
index d493b5b5dbd..d73247da350 100644
--- a/apps/server/src/services/push/__tests__/PushChannel.test.ts
+++ b/apps/server/src/services/push/__tests__/PushChannel.test.ts
@@ -97,6 +97,48 @@ describe('PushChannel', () => {
});
});
+ it('adds mutable content, image, and custom data for a rich agent notification', async () => {
+ mockListByUserId.mockResolvedValueOnce([
+ { deviceId: 'iphone', expoToken: 'ExponentPushToken[A]' },
+ ]);
+
+ const expo = makeExpoMock();
+ expo.sendPushNotificationsAsync.mockResolvedValueOnce([{ id: 'ticket-1', status: 'ok' }]);
+
+ const channel = new PushChannel(expo as any);
+ await channel.deliver({
+ ...ctx,
+ pushPresentation: {
+ data: {
+ agentAvatar: 'πŸ€–',
+ agentAvatarBackgroundColor: '#ff0000',
+ agentId: 'agt_1',
+ lobePushStyle: 'agent_message',
+ notificationId: 'spoofed-notification',
+ type: 'spoofed_type',
+ url: '/malicious-target',
+ },
+ image: 'https://example.com/avatar.png',
+ mutableContent: true,
+ },
+ type: 'agent_run_completed',
+ });
+
+ expect(expo.sendPushNotificationsAsync.mock.calls[0][0][0]).toMatchObject({
+ data: {
+ agentAvatar: 'πŸ€–',
+ agentAvatarBackgroundColor: '#ff0000',
+ agentId: 'agt_1',
+ lobePushStyle: 'agent_message',
+ notificationId: 'notif-1',
+ type: 'agent_run_completed',
+ url: '/image?topic=t1',
+ },
+ mutableContent: true,
+ richContent: { image: 'https://example.com/avatar.png' },
+ });
+ });
+
it('drops send-time errors but still returns sent if at least one ticket succeeded', async () => {
mockListByUserId.mockResolvedValueOnce([
{ deviceId: 'a', expoToken: 'ExponentPushToken[A]' },
diff --git a/apps/server/src/services/push/types.ts b/apps/server/src/services/push/types.ts
index d405b4b1d99..93c5805ef3e 100644
--- a/apps/server/src/services/push/types.ts
+++ b/apps/server/src/services/push/types.ts
@@ -16,8 +16,19 @@ export interface PushDeliveryContext {
content: string;
/** Underlying notifications.id β€” sent as `data.notificationId` for tracing */
notificationId: string;
+ /** Optional native presentation hints for notification service extensions. */
+ pushPresentation?: {
+ /** Extra JSON-safe string values merged into Expo's custom data payload. */
+ data?: Record<string, string>;
+ /** Public HTTPS image used by supported system notification surfaces. */
+ image?: string;
+ /** Sets APNs `mutable-content: 1` so an iOS service extension can enrich the alert. */
+ mutableContent?: boolean;
+ };
/** Notification title */
title: string;
+ /** Scenario identifier sent in custom data for client/native routing. */
+ type?: string;
/** Ignored by push (kept for cloud `NotificationChannel` compatibility) */
userEmail?: string;
/** Target user β€” push channel fans out to all of this user's `push_tokens` */