官方包 · 框架

Axum 和 Actix Web 的实时、等候室与聊天

Hibira crate 可以发送事件、签署频道订阅和校验 webhook、在 Axum 或 Actix Web 路由前加上等候室,并调用 Chat API 和 Approvals。

crates.io 版本许可证

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

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

  1. 安装插件

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

    Add Hibira Rust (hibira) to this project.
    Follow https://hibira.io/guides/rust, 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 工具与插件内容 →

  • 提供 Axum 和 Actix Web 的等候室中间件;handler 会收到访客的 pass。
  • 私有和 presence 频道授权、pusher-js 登录和 webhook 校验;关闭 client feature 时不含任何网络代码。
  • 同一个 crate 还提供 Chat API、Approvals 和 Live Chat 验证访客。

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

  1. 安装

    cargo add hibira --features axum   # or --features actix
  2. 配置

    HIBIRA_APP_ID=YOUR_APP_ID
    HIBIRA_KEY=YOUR_APP_KEY
    HIBIRA_SECRET=YOUR_APP_SECRET
    HIBIRA_HOST=ws.hibira.io
  3. 使用

    use std::sync::Arc;
    use axum::{middleware, routing::get, Extension, Router};
    use hibira::{waiting_room::axum_guard, Client, Config, Pass};
    
    let config = Config::from_env()?;
    let hibira = Client::new(config.clone());
    hibira.trigger(&["orders"], "order.shipped", &serde_json::json!({ "id": 1042 })).await?;
    
    let app = Router::new()
        .route("/drop", get(|Extension(pass): Extension<Pass>| async move { format!("You are number {}", pass.number) }))
        .layer(middleware::from_fn_with_state(Arc::new(config.waiting_room("presale")), axum_guard));

开始之前

  • 应用密钥只会在创建应用或轮换密钥时显示一次。请只放在服务器上,不要放进浏览器或游戏的构建包。
  • 私有频道和 presence 频道需要后端提供授权端点,用应用密钥签名订阅,做法与 pusher-js 相同。

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