Gói chính thức · Framework

Thời gian thực, phòng chờ và chat cho Axum và Actix Web

Crate Hibira gửi sự kiện, ký đăng ký kênh và kiểm tra webhook, đặt phòng chờ trước các route Axum hoặc Actix Web, và gọi Chat API cùng Approvals.

Phiên bản trên crates.ioGiấy phép

Cách nhanh nhất: plugin Hibira và một prompt

Cài plugin vào agent lập trình AI của bạn rồi dán prompt. Agent sẽ đăng nhập, tạo ứng dụng miễn phí nếu cần, viết mã và gửi một sự kiện thử. GitHub ↗

  1. Cài plugin

    claude plugin marketplace add hibira-io/agent-plugin
    claude plugin install hibira@hibira
  2. Dán prompt này

    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.
  • Middleware phòng chờ cho Axum và Actix Web; handler nhận pass của khách truy cập.
  • Cấp quyền kênh riêng tư và presence, đăng nhập pusher-js và kiểm tra webhook, không có mã mạng khi tắt feature client.
  • Chat API, Approvals và khách truy cập đã xác minh trong Live Chat từ cùng một crate.

Đăng nhập để xem các đoạn mã này với host cụm của riêng bạn. Đăng nhập

  1. Cài đặt

    cargo add hibira --features axum   # or --features actix
  2. Thiết lập

    HIBIRA_APP_ID=YOUR_APP_ID
    HIBIRA_KEY=YOUR_APP_KEY
    HIBIRA_SECRET=YOUR_APP_SECRET
    HIBIRA_HOST=ws.hibira.io
  3. Sử dụng

    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));

Trước khi bắt đầu

  • Secret của ứng dụng chỉ hiện một lần, khi bạn tạo ứng dụng hoặc xoay vòng secret. Hãy giữ nó trên máy chủ, không bao giờ đưa vào trình duyệt hay bản build game.
  • Kênh private và presence cần một auth endpoint trên backend ký các lượt đăng ký bằng secret của ứng dụng, giống như với pusher-js.

Dùng app key từ bảng điều khiển; secret chỉ để trên máy chủ của bạn. Kênh, sự kiện và endpoint xác thực hoạt động y như với Pusher. Tạo tài khoản miễn phí →