官方包 · 框架

从 Node.js 使用 Chat API、Live Chat 和审批

没有任何依赖的服务端 SDK,覆盖 pusher 包没有的 Hibira 产品:Chat API、配合 Express、Fastify 和 Koa 中间件的 Live Chat 验证访客,以及 Approvals。

npm 版本许可证

最快的方式:装好 Hibira 插件,粘贴一段提示词

在你的 AI 编程助手装好插件,再粘贴提示词。助手会帮你登录、需要时创建免费应用、写好代码并发送测试事件。 GitHub ↗

  1. 安装插件

    claude plugin marketplace add hibira-io/agent-plugin
    claude plugin install hibira@hibira
  2. 粘贴这段提示词

    Add Hibira Node.js SDK (@hibira-io/node) to this project.
    Follow https://hibira.io/guides/node-sdk, adapted to how this project is already set up.
    If I have no Hibira app yet, create a Free one that allows http://localhost so I can test right away.
    Keep the app key and secret in environment variables, add placeholders to .env.example, and never commit real values or send the secret to a browser.
    When you are done, send a test event, show me it arriving, and list the files you changed.

想自己动手? 下方的步骤如下:

  1. 安装
  2. 配置
  3. 使用

其他 AI 工具与插件内容 →

  • hibira.chat 可以创建会话、以成员身份发消息、读取历史并标记已读。
  • Express、Koa 和 Fastify 中间件会在页面放上 Live Chat 聊天窗口,并验证已登录的用户。
  • hibira.approvals 请人做决定并等待答复;verifyApprovalCallback() 校验带签名的回调。

登录后,示例代码会自动填入您的集群主机。 登录

  1. 安装

    npm install @hibira-io/node
  2. 配置

    HIBIRA_APP_ID=YOUR_APP_ID
    HIBIRA_KEY=YOUR_APP_KEY
    HIBIRA_SECRET=YOUR_APP_SECRET
    HIBIRA_HOST=ws.hibira.io
    HIBIRA_LIVECHAT_WORKSPACE=YOUR_WORKSPACE_ID
    HIBIRA_LIVECHAT_IDENTITY_SECRET=YOUR_IDENTITY_SECRET
  3. 使用

    import { createHibira } from '@hibira-io/node';
    
    const hibira = createHibira();
    
    // Live Chat on every page, signed-in users verified: <%- hibiraLiveChat.scriptTag %>
    app.use(hibira.liveChat.express({ getUser: (req) => req.user && { id: req.user.id, name: req.user.name } }));
    
    await hibira.chat.putConversation('order-1042', { members: ['buyer-7', 'seller-3'] });
    await hibira.chat.sendMessage('order-1042', 'seller-3', 'Shipped today!');
    
    const ask = await hibira.approvals.request({ title: 'Refund order #1042 for $89?', options: ['Refund', 'Decline'] });
    const answer = await hibira.approvals.wait(ask.approval_id, { timeout: 600 });

开始之前

  • 应用密钥只会在创建应用或轮换密钥时显示一次。请只放在服务器上,不要放进浏览器或游戏的构建包。
  • 实时事件和频道授权请使用指向你 {brand} 主机的 pusher npm 包;等候室请使用 @hibira-io/waiting-room。

请使用控制台中应用的 Key;Secret 只放在你的服务器上。频道、事件与授权端点的用法与 Pusher 完全相同。 免费创建账号 →