webiny-websocket-notifications
Skill này làm gì
Skill này hướng dẫn AI của bạn khi máy chủ cần báo cho người dùng admin biết về công việc đang diễn ra. Skill dành cho lập trình viên muốn cập nhật trực tiếp trong admin Webiny.
Khi nào nên dùng
- ✓Khi một tác vụ nền cần hiển thị tiến độ cho người đã khởi chạy nó.
- ✓Khi màn hình admin cần tự làm mới sau một thay đổi trên máy chủ.
- ✓Khi một tin nhắn cần xuất hiện dưới dạng thông báo trong ứng dụng admin.
Liên kết skill
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/websocket-notifications/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hiển thị thông báo trong admin khi tác vụ giảm giá hàng loạt hoàn tất cho từng sản phẩm.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Ở phía máy chủ, code gửi tin nhắn cho người đã kích hoạt công việc, và lỗi gửi tin nhắn không được làm hỏng công việc thật. Trong ứng dụng admin, một handler lọc tin nhắn theo action và phản ứng, chẳng hạn bằng cách hiện thông báo.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
actionstring; put the payload indata. - 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'sprocessDatasends a message per processed entry so the Admin can toast progress live.
Câu hỏi thường gặp
Webiny phiên bản nào cần cho thông báo websocket?
Skill nói thông báo websocket cần Webiny 6.5.0 trở lên.
Nếu gửi tin nhắn thất bại thì sao?
Skill nói lỗi websocket không bao giờ được làm hỏng công việc thật, nên lỗi chỉ được ghi log và bỏ qua.
Ai nhận tin nhắn?
Người đã kích hoạt công việc, được tìm qua identity context.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 8.1k
- Vị trí xếp hạng
- #12592
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
prd-to-plan
8.1kGiúp agent của bạn biến tài liệu yêu cầu sản phẩm thành kế hoạch theo giai đoạn gồm các lát cắt đầu-cuối nhỏ, lưu thành file Markdown.
webiny-admin-architect
8.1kDạy agent của bạn cách xây dựng màn hình quản trị cho nền tảng Webiny, dùng các tầng logic nghiệp vụ và mẫu presenter.
webiny-admin-permissions
8.1kDạy agent của bạn thêm kiểm soát quyền vào màn hình quản trị Webiny, gồm form quyền tự sinh và kiểm tra ẩn hoặc hiện.
webiny-form-model
8.1kDạy agent của bạn xây dựng form trong Webiny bằng trình tạo trường khai báo, bố cục, kiểm tra hợp lệ và quy tắc có điều kiện.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.