官方套件 · 框架

從 Node.js 使用 Chat API、Live Chat 與審核

沒有任何相依套件的伺服器端 SDK,涵蓋 pusher 套件沒有的 Hibira 產品:Chat API、搭配 Express、Fastify 與 Koa middleware 的 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 middleware 會在頁面放上 Live Chat 聊天視窗,並驗證登入中的使用者。
  • hibira.approvals 請人做決定並等待回覆;verifyApprovalCallback() 驗證帶簽名的 callback。

登入後,範例程式碼會自動帶入您的叢集主機。 登入

  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 完全相同。 免費建立帳號 →