Push notifications for AI Transport
Wake users when an AI agent finishes while they are away.
Long agent runs often outlive the user’s attention: they ask a question, lock their phone, and come back later. This page shows two ways to send a push notification when the answer is ready, both built on Sockudo’s existing push pipeline. You need it when runs take longer than a user will keep the app open.
AI Transport uses normal Sockudo channel events for lifecycle and output. Push rules let those same channel publishes wake devices through the existing push notification pipeline.
Choose a recipe
| Recipe | How it triggers | Choose it when |
|---|---|---|
| Channel push rule | The agent publishes an ordinary event (for example agent-complete) to a notification channel; a [[push_rules]] entry turns it into a push. | You want zero backend code and static notification text. |
| Webhook recipe | The ai_run_ended webhook reaches your backend, which calls the push publish API. | You need enrichment, quiet hours, or a database lookup before notifying. |
Both recipes deliver through the same durable push status, fanout, queue, retry, and feedback transitions as any other push publish.
sequenceDiagram participant A as Agent worker participant S as Sockudo participant P as Push provider participant D as User device A->>S: ai-run-end (run-reason=complete) A->>S: agent-complete on notifications channel S->>S: push rule matches channel and event S->>P: provider request (FCM, APNs, ...) P-->>D: notification D->>S: open session, read history
Channel rule recipe
-
Build Sockudo with the
pushfeature and configure at least one provider. See Push notifications for provider credentials. -
Add a rule that watches each user’s notification channel:
config.toml [[push_rules]]enabled = truechannel_pattern = "notifications:*"event_filter = ["agent-complete"]rate_limit_per_second = 100[push_rules.payload_mapping]title_field = "title"body_field = "body"template_data_field = "data"include_remaining_fields = true -
Register each device and subscribe it to the same channel the app is allowed to read:
POST /apps/{appId}/push/channelSubscriptions -
Have the long-running agent publish a normal event when the answer is ready:
{"name": "agent-complete","channel": "notifications:user-123","data": {"title": "Agent finished","body": "Your answer is ready","sessionId": "sess_123"}}
Sockudo maps title and body into the push notification and copies the remaining fields into
provider data under data. The push target is Channel { channel: "notifications:user-123" }, so
existing channel subscriptions determine which devices receive FCM, APNs, Web Push, HMS, or WNS
delivery.
Rule details:
channel_patternaccepts exact names,*, or a single trailing wildcard such asnotifications:*.event_filteris a non-empty allowlist of at most 32 event names, each at most 200 bytes.rate_limit_per_seconddefaults to100per rule.- Rules are validated at startup, and a publish that matches no rule does no push work.
When the user taps the notification, the client should load sessionId, attach to the realtime
session channel, and read history/recovery state for the authoritative transcript. The notification
is a pointer, not the answer.
Webhook recipe
For teams that keep push orchestration in their backend, enable the ai_run_ended webhook. Its
payload carries channel, run_id, reason, and an optional error_code. On
reason = "complete", the backend can call the existing push publish API
(POST /apps/{appId}/push/publish):
{ "recipients": [ { "type": "channel", "channel": "notifications:user-123" } ], "payload": { "title": "Agent finished", "body": "Your answer is ready", "templateData": { "data": { "sessionId": "sess_123" } } }, "sync": false}With the Node server SDK, the same handler looks like this:
import Sockudo from "sockudo";// App code: maps a session channel to the user who owns it.import { ownerOfChannel } from "@/lib/sessions";
const sockudo = new Sockudo({ appId: process.env.SOCKUDO_APP_ID!, key: process.env.SOCKUDO_APP_KEY!, secret: process.env.SOCKUDO_APP_SECRET!, host: "realtime.example.com", useTLS: true,});
export async function POST(req: Request) { const rawBody = await req.text(); const webhook = sockudo.webhook({ headers: Object.fromEntries(req.headers), rawBody, }); if (!webhook.isValid()) return new Response("invalid signature", { status: 401 });
for (const event of webhook.getEvents()) { if (event.name !== "ai_run_ended" || event.reason !== "complete") continue; const userId = await ownerOfChannel(event.channel); await sockudo.publishPush({ recipients: [{ type: "channel", channel: `notifications:${userId}` }], payload: { title: "Agent finished", body: "Your answer is ready", templateData: { data: { sessionId: event.channel } }, }, }); } return new Response(null, { status: 200 });}This path is useful when the backend enriches notifications, applies product-specific quiet hours,
or joins run metadata with an application database before sending push. Webhooks are delivered at
least once, so make the handler idempotent (for example by keying on run_id).
Authorization
Use capability patterns so clients can subscribe only to their own notification channels, for
example notifications:user-123, while trusted backends or agent workers publish agent-complete.
Do not accept client_id from the message body when choosing a notification channel; derive the
channel from verified auth state or server-side session ownership.
Verification surface
The recipe relies on existing push device registration, channel subscriptions, channel publish targets, scheduled/status handling, delivery feedback, retries, and dead-letter behavior. Push rules add only the channel-to-push trigger; accepted work still goes through the same durable status, fanout, queue, retry, and feedback transitions as explicit push publishes.