webiny-websocket-notifications

Send real-time websocket notifications from Webiny API to the Admin app.

8.0k|673|Updated Jan 9, 2018
One-click install
npx skills add https://github.com/webiny/webiny-js --skill webiny-websocket-notifications
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: webiny-websocket-notifications
Source: https://github.com/webiny/webiny-js/tree/main/skills/user-skills/api/websocket-notifications
Command: npx skills add https://github.com/webiny/webiny-js --skill webiny-websocket-notifications

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When server-side work runs in Webiny (background tasks, bulk actions, hooks), the user who triggered it has no way to know when it finishes or what happened. This Skill shows how to push real-time messages from the API to the Admin app over websockets so the UI can react immediately.

Core Features & Use Cases

  • API-side emitting: Inject WebsocketsSendToIdentityUseCase and IdentityContext to send a namespaced { action, data } message to the identity that triggered the work, with best-effort error handling so websocket failures never break the real task.
  • Admin-side handling: Implement a WebsocketEventHandler that filters incoming messages by action and reacts, for example showing a toast via Notifications.
  • Feature registration: Register the handler with createFeature and RegisterFeature inside an Admin.Extension.
  • Use Case: A bulk action processes hundreds of CMS entries; each processed entry sends a websocket message so the Admin displays live progress toasts to the user who started the action.

Quick Start

Ask the AI to add a websocket notification to your Webiny API task that sends a message to the triggering identity and an Admin handler that shows a toast when the message arrives.

Frequently Asked Questions about webiny-websocket-notifications

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I send a websocket message from the Webiny API to a specific user?

Inject WebsocketsSendToIdentityUseCase from webiny/api and IdentityContext from webiny/api/security, then call sendToIdentity.execute with the identity id and a payload containing an action string and data object. Wrap the call in try/catch so a websocket failure never fails the real work.

How do I handle websocket messages in the Webiny Admin app?

Implement the WebsocketEventHandler interface from webiny/admin/websockets, filter incoming events by event.payload.action, and react accordingly, for example showing a toast via the Notifications service. Register the handler with createFeature and render it with RegisterFeature in your Admin extension.

Which Webiny version supports websocket notifications?

Websocket notifications require Webiny 6.5.0 or newer. Earlier versions do not provide the WebsocketsSendToIdentityUseCase abstraction or the Admin WebsocketEventHandler contract.

Why does every websocket handler receive every message?

The websockets runner resolves all registered WebsocketEventHandler implementations and calls handle for each incoming message. Each handler must filter by the action field and return early for messages it does not care about.

Can I get the triggering user's identity inside a background task?

Yes. In a background task or bulk action, the triggering identity is available through IdentityContext. Use identityContext.getIdentity() to obtain the identity and pass its id to sendToIdentity.execute.