官方套件 · 框架

Ktor 的即時、等候室與聊天

以 Kotlin 撰寫的 Ktor 3 plugin:提供 pusher-js 與 Laravel Echo 需要的頻道授權與 webhook 路由、等候室路由 plugin,並以協程使用事件、Chat API 與 Approvals。

Maven Central 版本授權條款

最快的方式:裝好 Hibira 外掛,貼上一段提示詞

在你的 AI 程式助手裝好外掛,再貼上提示詞。助手會幫你登入、需要時建立免費應用、寫好程式碼並送出測試事件。 GitHub ↗

  1. 安裝外掛

    claude plugin marketplace add hibira-io/agent-plugin
    claude plugin install hibira@hibira
  2. 貼上這段提示詞

    Add Hibira Ktor (io.hibira:hibira-ktor) to this project.
    Follow https://hibira.io/guides/ktor, 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 工具與外掛內容 →

  • hibiraChannelAuth、hibiraUserAuth 與 hibiraWebhooks 加上 pusher-js 與 Laravel Echo 需要的路由。
  • 在路由上 install(HibiraWaitingRoom),沒有 pass 的訪客會被導到託管的等候頁。
  • 事件、Chat API 與 Approvals 的 suspend 函式,以及 Live Chat 驗證訪客。

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

  1. 安裝

    implementation("io.hibira:hibira-ktor:0.1.0")
  2. 設定

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

    fun Application.module() {
        install(HibiraPlugin)
        routing {
            hibiraChannelAuth { channel ->
                val user = principal<UserIdPrincipal>() ?: return@hibiraChannelAuth deny()
                if (channel.startsWith("presence-")) presence(user.name) else allow()
            }
            route("/drop") {
                install(HibiraWaitingRoom) { room = "presale" }
                get { call.respondText("You are number ${call.waitingRoomPass!!.number()}") }
            }
        }
    }

開始之前

  • 應用程式的密鑰只會在建立應用程式或輪替密鑰時顯示一次。請只放在伺服器上,不要放進瀏覽器或遊戲的建置檔。
  • Free 方案需要把頁面載入的每個來源都加進應用程式的「允許的來源」(開發時是 http://localhost:3000,之後是您的網域)。"*" 需要付費方案。

請使用儀表板中的應用程式 Key;Secret 只放在你的伺服器上。頻道、事件與授權端點的用法和 Pusher 完全相同。 免費建立帳號 →