Aller au contenu
Skillpedia
API et serveurs (backend)8.1k · #12592

webiny-websocket-notifications

Ce qu’il fait

Cette compétence guide votre IA lorsque le serveur doit informer l'utilisateur de l'administration d'un travail en cours. Elle s'adresse aux développeurs qui veulent des mises à jour en direct dans l'administration Webiny.

Quand l’utiliser

  • ✓Quand une tâche de fond doit montrer sa progression à l'utilisateur qui l'a lancée.
  • ✓Quand l'écran d'administration doit se rafraîchir automatiquement après une modification côté serveur.
  • ✓Quand un message doit apparaître comme notification dans l'application d'administration.

Lien du skill

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/websocket-notifications/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/websocket-notifications/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Affiche une notification dans l'administration lorsque la tâche de remise groupée est terminée pour chaque produit.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

Côté serveur, le code envoie un message à l'utilisateur qui a déclenché le travail, sans qu'un échec du message ne fasse échouer le vrai travail. Dans l'application d'administration, un gestionnaire filtre les messages selon leur action et réagit, par exemple en affichant une notification.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

Websocket notifications (API → Admin)

TL;DR

On the API, inject WebsocketsSendToIdentityUseCase (webiny/api) + IdentityContext (webiny/api/security) and call sendToIdentity.execute({ id }, { action, data }). On the Admin, implement a WebsocketEventHandler (webiny/admin/websockets) that filters on action and reacts (e.g. toast via Notifications from webiny/admin), registered with createFeature + RegisterFeature.

API — emit

import { WebsocketsSendToIdentityUseCase } from "webiny/api";
import { IdentityContext } from "webiny/api/security";

class MyTaskOrHook {
  constructor(
    private identityContext: IdentityContext.Interface,
    private sendToIdentity: WebsocketsSendToIdentityUseCase.Interface
  ) {}

  async notify(entry) {
    // Best-effort: a websocket failure must never fail the real work.
    try {
      const identity = this.identityContext.getIdentity();
      if (identity) {
        await this.sendToIdentity.execute(
          { id: identity.id },
          {
            action: "cms.product.discountApplied",
            data: { id: entry.entryId, price: entry.values.price }
          }
        );
      }
    } catch (ex) {
      // log & swallow
    }
  }
}
// dependencies: [IdentityContext, WebsocketsSendToIdentityUseCase]
  • Send to the user who triggered the work — get them from IdentityContext. In a background task/bulk action, the triggering identity is available.
  • Use a namespaced action string; put the payload in data.
  • Sender data type: { action?: string; data?: T; error?: {...} }.

Admin — listen

import { WebsocketEventHandler } from "webiny/admin/websockets";
import { Notifications } from "webiny/admin";

const ACTION = "cms.product.discountApplied";

class MyHandlerImpl implements WebsocketEventHandler.Interface {
  constructor(private notifications: Notifications.Interface) {}

  async handle(event: WebsocketEventHandler.Event): Promise<void> {
    const payload = event.payload as { action?: string; data?: { id: string; price: number } };
    if (payload.action !== ACTION || !payload.data) {
      return; // every handler sees every message — filter by action
    }
    this.notifications.success({
      title: "Discount applied",
      description: `New price ${payload.data.price}.`
    });
  }
}

export const MyHandler = WebsocketEventHandler.createImplementation({
  implementation: MyHandlerImpl,
  dependencies: [Notifications]
});

Read the message off event.payload — event.payload.action and event.payload.data (the exact { action, data } object the API sent).

Admin — register

Register the handler in a feature and render it from your Admin.Extension:

import { createFeature, RegisterFeature } from "webiny/admin";
import { MyHandler } from "./MyHandler.js";

const MyFeature = createFeature({
  name: "MyExtension/Notifications",
  register(container) {
    container.register(MyHandler);
  }
});

export default () => <RegisterFeature feature={MyFeature} />;

The websockets runner resolves every registered WebsocketEventHandler and calls handle for each incoming message — hence the action filter in each handler.

Related

  • webiny-cms-bulk-actions — the typical emitter: a bulk action's processData sends a message per processed entry so the Admin can toast progress live.
Questions fréquentes

Quelle version de Webiny est nécessaire ?

La compétence indique que les notifications websocket nécessitent Webiny 6.5.0 ou une version plus récente.

Que se passe-t-il si le message ne parvient pas ?

La compétence précise qu'un échec websocket ne doit jamais faire échouer le vrai travail, donc les erreurs sont consignées puis ignorées.

Qui reçoit le message ?

L'utilisateur qui a déclenché le travail, identifié grâce au contexte d'identité.

Détails

Description originale de l’auteur

Sending real-time notifications from the API to the Admin app over websockets, and reacting to them on the client. Use this skill when the developer wants to push a message to the user who triggered some server-side work (e.g. per-entry progress from a background task/bulk action) and show a toast, update a cache, or refresh UI in response. Requires Webiny 6.5.0 or newer.

repo: webiny/webiny-js

Popularité

Étoiles GitHub
8.1k
Position au classement
#12592
Licence
—
Mis à jour
02/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires