# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: OpenAB Gateway
spec:
    description: |
        Standalone webhook gateway for OpenAB — bridges Telegram and/or LINE to any running OAB instance via WebSocket. Deploy alongside an existing OpenAB service to enable Telegram and/or LINE support. At least one platform must be configured.
        Source: https://github.com/openabdev/openab
    coverImage: https://cdn-console.zeabur.com/f/Xp0H6/openab-cover.webp
    icon: https://cdn-console.zeabur.com/f/0Ewi6/openab-icon.webp
    variables:
        - key: TELEGRAM_BOT_TOKEN
          type: STRING
          name: Telegram Bot Token (optional)
          description: Optional. Bot token from @BotFather (https://t.me/BotFather). Leave empty to disable Telegram. At least one of Telegram or LINE must be configured.
        - key: LINE_CHANNEL_SECRET
          type: STRING
          name: LINE Channel Secret (optional)
          description: Optional. Channel secret from LINE Developers Console. Leave empty to disable LINE.
        - key: LINE_CHANNEL_ACCESS_TOKEN
          type: STRING
          name: LINE Channel Access Token (optional)
          description: Optional. Channel access token from LINE Developers Console. Required when LINE Channel Secret is set.
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Gateway Domain
          description: Public HTTPS domain for receiving webhooks from Telegram and LINE.
    tags:
        - AI
        - Developer Tools
        - Telegram
        - LINE
    readme: |
        # OpenAB Gateway

        [OpenAB Gateway](https://github.com/openabdev/openab) is a standalone webhook bridge that connects Telegram and LINE to any running [OpenAB](https://github.com/openabdev/openab) instance via WebSocket.

        ```
        Telegram ──POST──▶ ┌──────────────────┐
        LINE     ──POST──▶ │  OpenAB Gateway  │ ◀──WebSocket── OAB Pod
                           │     :8080        │   (OAB connects out)
                           └──────────────────┘
        ```

        Deploy this template alongside an existing OpenAB service (Claude, Cursor, Codex, etc.) to add Telegram and LINE support without redeploying OAB.

        ## Prerequisites

        - A running OpenAB service (any variant) in the same Zeabur project
        - **At least one** of the following:
          - A Telegram bot token from [@BotFather](https://t.me/BotFather)
          - A LINE Official Account with Messaging API enabled (LINE Channel Secret + Access Token)

        ## Setup

        ### 1. Create a Telegram Bot

        1. Open [@BotFather](https://t.me/BotFather) in Telegram
        2. Send `/newbot` and follow the prompts
        3. Copy the bot token (e.g. `123456:ABC-DEF...`) → paste into **Telegram Bot Token**
        4. Optional: send `/setprivacy` → `Disable` so the bot sees all group messages

        ### 2. Deploy

        Fill in the tokens for the platform(s) you want to enable and click deploy. A public HTTPS domain is auto-assigned. You can enable Telegram only, LINE only, or both.

        ### 3. Register the Telegram Webhook

        After deployment, register your gateway URL with Telegram (replace `YOUR_TOKEN`, `YOUR_DOMAIN`, and optionally `YOUR_SECRET`):

        ```bash
        # Without webhook secret (simpler, less secure)
        curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram"

        # With webhook secret (recommended — matches TELEGRAM_SECRET_TOKEN you set)
        curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram&secret_token=YOUR_SECRET"
        ```

        Expected response: `{"ok":true,"result":true,"description":"Webhook was set"}`

        ### 4. Configure OAB to Use the Gateway

        In your OpenAB service (same Zeabur project), edit `/home/agent/.config/openab/config.toml` and add:

        ```toml
        [gateway]
        url = "ws://openab-gateway:8080/ws"
        ```

        Then restart the OpenAB service. OAB connects outbound to the gateway — no inbound ports needed on OAB.

        > **Internal hostname:** `openab-gateway` resolves within the same Zeabur project via internal DNS. If your gateway service has a different name, use that name instead.

        ### 5. Test

        Send a message to your Telegram bot. The gateway receives it and forwards it to OAB via WebSocket. OAB processes it and replies through the gateway.

        ## LINE Setup (Optional)

        ### 1. Create a LINE Official Account

        1. Go to [LINE Official Account Manager](https://manager.line.biz) and create a new account
        2. **Settings** → **Messaging API** → **Enable Messaging API**
        3. Open [LINE Developers Console](https://developers.line.biz) → your channel:
           - **Basic settings** → **Channel secret** → copy → paste into **LINE Channel Secret**
           - **Messaging API** → **Channel access token** → Issue → copy → paste into **LINE Channel Access Token**

        ### 2. Set Webhook URL

        In LINE Developers Console → **Messaging API** tab:

        1. **Webhook URL** → Edit → enter: `https://YOUR_DOMAIN/webhook/line`
        2. **Use webhook** → ON
        3. **Auto-reply messages** → OFF
        4. Click **Verify**

        ### 3. Configure OAB for LINE

        In `config.toml`, add `platform = "line"` to the gateway section:

        ```toml
        [gateway]
        url = "ws://openab-gateway:8080/ws"
        platform = "line"
        ```

        Restart the OpenAB service after saving.

        ## Webhook Endpoints

        | Path | Platform |
        |------|----------|
        | `POST /webhook/telegram` | Telegram |
        | `POST /webhook/line` | LINE |
        | `GET /ws` | OAB WebSocket (internal) |
        | `GET /health` | Health check |

        ## Links

        - [OpenAB GitHub](https://github.com/openabdev/openab)
        - [Telegram Setup Guide](https://github.com/openabdev/openab/blob/main/docs/telegram.md)
        - [LINE Setup Guide](https://github.com/openabdev/openab/blob/main/docs/line.md)
        - [Gateway README](https://github.com/openabdev/openab/blob/main/gateway/README.md)
    services:
        - name: openab-gateway
          icon: https://cdn-console.zeabur.com/f/0Ewi6/openab-icon.webp
          template: PREBUILT_V2
          spec:
            id: openab-gateway
            source:
                image: ghcr.io/openabdev/openab-gateway:0.3.0
            ports:
                - id: web
                  port: 8080
                  type: HTTP
            instructions:
                - title: Register Telegram Webhook
                  content: curl "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook?url=${ZEABUR_WEB_URL}/webhook/telegram&secret_token=${TELEGRAM_SECRET_TOKEN}"
                - title: Unregister Telegram Webhook
                  content: curl "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/deleteWebhook"
            env:
                LINE_CHANNEL_ACCESS_TOKEN:
                    default: ${LINE_CHANNEL_ACCESS_TOKEN}
                LINE_CHANNEL_SECRET:
                    default: ${LINE_CHANNEL_SECRET}
                TELEGRAM_BOT_TOKEN:
                    default: ${TELEGRAM_BOT_TOKEN}
                TELEGRAM_SECRET_TOKEN:
                    default: ${PASSWORD}
            healthCheck:
                type: TCP
                port: web
          domainKey: PUBLIC_DOMAIN
localization:
    es-ES:
        description: |
            Gateway Webhook independiente para OpenAB — conecta Telegram y/o LINE a cualquier instancia de OAB en ejecución mediante WebSocket. Se debe configurar al menos una plataforma.
            Fuente: https://github.com/openabdev/openab
        variables:
            - key: TELEGRAM_BOT_TOKEN
              type: STRING
              name: Token de Bot de Telegram (opcional)
              description: Opcional. Token del bot obtenido de @BotFather (https://t.me/BotFather). Dejar vacío para deshabilitar Telegram. Al menos uno de Telegram o LINE debe configurarse.
            - key: LINE_CHANNEL_SECRET
              type: STRING
              name: LINE Channel Secret (opcional)
              description: Opcional. Channel Secret de LINE Developers Console. Dejar vacío para deshabilitar LINE.
            - key: LINE_CHANNEL_ACCESS_TOKEN
              type: STRING
              name: LINE Channel Access Token (opcional)
              description: Opcional. Channel Access Token de LINE Developers Console. Requerido si se configura LINE Channel Secret.
            - key: PUBLIC_DOMAIN
              type: STRING
              name: Dominio del Gateway
              description: Dominio HTTPS público para recibir webhooks de Telegram y LINE.
        readme: |
            # OpenAB Gateway

            Gateway Webhook independiente que conecta Telegram y LINE a cualquier instancia de [OpenAB](https://github.com/openabdev/openab) mediante WebSocket.

            ## Requisitos previos

            - Un servicio OpenAB en ejecución en el mismo proyecto de Zeabur
            - **Al menos uno** de los siguientes:
              - Un token de bot de Telegram de [@BotFather](https://t.me/BotFather)
              - Una cuenta oficial de LINE con Messaging API habilitada (LINE Channel Secret + Access Token)

            ## Configuración

            ### 1. Crear Bot de Telegram

            Abrir [@BotFather](https://t.me/BotFather), enviar `/newbot` y copiar el token en **Token de Bot de Telegram**.

            ### 2. Desplegar

            Introducir el token y desplegar. Se asignará un dominio HTTPS automáticamente.

            ### 3. Registrar Webhook de Telegram

            ```bash
            curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram"
            ```

            ### 4. Configurar OAB

            Editar `/home/agent/.config/openab/config.toml` en el servicio OpenAB:

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            ```

            Reiniciar el servicio OpenAB.

            ## Configuración de LINE (Opcional)

            ### 1. Crear una cuenta oficial de LINE

            1. Ir a [LINE Official Account Manager](https://manager.line.biz) y crear una cuenta
            2. **Configuración** → **Messaging API** → **Habilitar Messaging API**
            3. Abrir [LINE Developers Console](https://developers.line.biz) → tu canal:
               - **Basic settings** → **Channel secret** → copiar → pegar en **LINE Channel Secret**
               - **Messaging API** → **Channel access token** → Emitir → copiar → pegar en **LINE Channel Access Token**

            ### 2. Configurar URL de Webhook

            En LINE Developers Console → pestaña **Messaging API**:

            1. **Webhook URL** → Editar → introducir: `https://YOUR_DOMAIN/webhook/line`
            2. **Usar webhook** → Activar
            3. **Mensajes de respuesta automática** → Desactivar
            4. Clic en **Verificar**

            ### 3. Configurar OAB para LINE

            En `config.toml`, añadir `platform = "line"` en la sección gateway:

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            platform = "line"
            ```

            Reiniciar el servicio OpenAB tras guardar.

            ## Endpoints de Webhook

            | Ruta | Plataforma |
            |------|-----------|
            | `POST /webhook/telegram` | Telegram |
            | `POST /webhook/line` | LINE |
            | `GET /ws` | OAB WebSocket (interno) |
            | `GET /health` | Health check |

            ## Enlaces

            - [OpenAB GitHub](https://github.com/openabdev/openab)
            - [Guía de configuración de Telegram](https://github.com/openabdev/openab/blob/main/docs/telegram.md)
            - [Guía de configuración de LINE](https://github.com/openabdev/openab/blob/main/docs/line.md)
            - [Gateway README](https://github.com/openabdev/openab/blob/main/gateway/README.md)
    id-ID:
        description: |
            Gateway Webhook mandiri untuk OpenAB — menghubungkan Telegram dan/atau LINE ke instansi OAB mana pun melalui WebSocket. Setidaknya satu platform harus dikonfigurasi.
            Sumber: https://github.com/openabdev/openab
        variables:
            - key: TELEGRAM_BOT_TOKEN
              type: STRING
              name: Token Bot Telegram (opsional)
              description: Opsional. Token bot dari @BotFather (https://t.me/BotFather). Kosongkan untuk menonaktifkan Telegram. Setidaknya satu antara Telegram atau LINE harus dikonfigurasi.
            - key: LINE_CHANNEL_SECRET
              type: STRING
              name: LINE Channel Secret (opsional)
              description: Opsional. Channel Secret dari LINE Developers Console. Kosongkan untuk menonaktifkan LINE.
            - key: LINE_CHANNEL_ACCESS_TOKEN
              type: STRING
              name: LINE Channel Access Token (opsional)
              description: Opsional. Channel Access Token dari LINE Developers Console. Wajib jika LINE Channel Secret diisi.
            - key: PUBLIC_DOMAIN
              type: STRING
              name: Domain Gateway
              description: Domain HTTPS publik untuk menerima webhook Telegram dan LINE.
        readme: |
            # OpenAB Gateway

            Gateway Webhook mandiri yang menghubungkan Telegram dan LINE ke instansi [OpenAB](https://github.com/openabdev/openab) mana pun melalui WebSocket.

            ## Prasyarat

            - Layanan OpenAB yang sedang berjalan di proyek Zeabur yang sama
            - **Setidaknya salah satu** dari berikut:
              - Token bot Telegram dari [@BotFather](https://t.me/BotFather)
              - Akun resmi LINE dengan Messaging API aktif (LINE Channel Secret + Access Token)

            ## Pengaturan

            ### 1. Buat Bot Telegram

            Buka [@BotFather](https://t.me/BotFather), kirim `/newbot`, dan salin token ke **Token Bot Telegram**.

            ### 2. Deploy

            Masukkan token dan klik deploy. Domain HTTPS publik akan ditetapkan secara otomatis.

            ### 3. Daftarkan Webhook Telegram

            ```bash
            curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram"
            ```

            ### 4. Konfigurasikan OAB

            Edit `/home/agent/.config/openab/config.toml` di layanan OpenAB:

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            ```

            Restart layanan OpenAB.

            ## Pengaturan LINE (Opsional)

            ### 1. Buat Akun Resmi LINE

            1. Buka [LINE Official Account Manager](https://manager.line.biz) dan buat akun
            2. **Pengaturan** → **Messaging API** → **Aktifkan Messaging API**
            3. Buka [LINE Developers Console](https://developers.line.biz) → channel Anda:
               - **Basic settings** → **Channel secret** → salin → tempel ke **LINE Channel Secret**
               - **Messaging API** → **Channel access token** → Issue → salin → tempel ke **LINE Channel Access Token**

            ### 2. Atur Webhook URL

            Di LINE Developers Console → tab **Messaging API**:

            1. **Webhook URL** → Edit → masukkan: `https://YOUR_DOMAIN/webhook/line`
            2. **Gunakan webhook** → Aktifkan
            3. **Pesan balasan otomatis** → Nonaktifkan
            4. Klik **Verifikasi**

            ### 3. Konfigurasi OAB untuk LINE

            Di `config.toml`, tambahkan `platform = "line"` ke bagian gateway:

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            platform = "line"
            ```

            Restart layanan OpenAB setelah menyimpan.

            ## Endpoint Webhook

            | Path | Platform |
            |------|---------|
            | `POST /webhook/telegram` | Telegram |
            | `POST /webhook/line` | LINE |
            | `GET /ws` | OAB WebSocket (internal) |
            | `GET /health` | Health check |

            ## Tautan

            - [OpenAB GitHub](https://github.com/openabdev/openab)
            - [Panduan Telegram](https://github.com/openabdev/openab/blob/main/docs/telegram.md)
            - [Panduan LINE](https://github.com/openabdev/openab/blob/main/docs/line.md)
            - [Gateway README](https://github.com/openabdev/openab/blob/main/gateway/README.md)
    ja-JP:
        description: |
            OpenAB スタンドアロン Webhook Gateway — WebSocket を通じて Telegram または LINE（あるいは両方）を既存の OAB インスタンスに接続します。少なくとも一方のプラットフォームを設定する必要があります。
            ソース：https://github.com/openabdev/openab
        variables:
            - key: TELEGRAM_BOT_TOKEN
              type: STRING
              name: Telegram Bot トークン（オプション）
              description: オプション。@BotFather から取得した Bot トークン（https://t.me/BotFather）。空の場合、Telegram は無効。Telegram か LINE のどちらか一方は必ず設定してください。
            - key: LINE_CHANNEL_SECRET
              type: STRING
              name: LINE Channel Secret（オプション）
              description: オプション。LINE Developers Console の Channel Secret。空の場合、LINE は無効。
            - key: LINE_CHANNEL_ACCESS_TOKEN
              type: STRING
              name: LINE Channel Access Token（オプション）
              description: オプション。LINE Developers Console の Channel Access Token。LINE Channel Secret を設定する場合は必須。
            - key: PUBLIC_DOMAIN
              type: STRING
              name: Gateway ドメイン
              description: Telegram・LINE の Webhook を受信する公開 HTTPS ドメイン。
        readme: |
            # OpenAB Gateway

            [OpenAB Gateway](https://github.com/openabdev/openab) は、Telegram と LINE を WebSocket 経由で既存の OpenAB インスタンスに接続するスタンドアロン Webhook ブリッジです。

            ## 前提条件

            - 同じ Zeabur プロジェクト内に稼働中の OpenAB サービスが必要
            - **以下のいずれか一方（または両方）：**
              - [@BotFather](https://t.me/BotFather) から取得した Telegram Bot Token
              - Messaging API が有効な LINE 公式アカウント（LINE Channel Secret + Access Token）

            ## セットアップ

            ### 1. Telegram Bot を作成

            [@BotFather](https://t.me/BotFather) で `/newbot` を送信し、Bot Token を取得して **Telegram Bot Token** に入力してください。

            ### 2. デプロイ

            Telegram Bot Token を入力してデプロイします。公開 HTTPS ドメインが自動割り当てされます。

            ### 3. Telegram Webhook を登録

            ```bash
            curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram"
            ```

            ### 4. OAB に Gateway を設定

            OpenAB サービスの `/home/agent/.config/openab/config.toml` を編集して追加：

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            ```

            OpenAB サービスを再起動してください。

            ## LINE 設定（オプション）

            ### 1. LINE 公式アカウントを作成

            1. [LINE Official Account Manager](https://manager.line.biz) でアカウントを作成
            2. **設定** → **Messaging API** → **Messaging API を利用する**
            3. [LINE Developers Console](https://developers.line.biz) → チャンネルを開く：
               - **Basic settings** → **Channel secret** → コピー → **LINE Channel Secret** に貼り付け
               - **Messaging API** → **Channel access token** → 発行 → コピー → **LINE Channel Access Token** に貼り付け

            ### 2. Webhook URL を設定

            LINE Developers Console → **Messaging API** タブ：

            1. **Webhook URL** → 編集 → 入力：`https://YOUR_DOMAIN/webhook/line`
            2. **Webhookの利用** → ON
            3. **応答メッセージ** → OFF
            4. **検証** をクリック

            ### 3. OAB に LINE を設定

            `config.toml` の gateway セクションに `platform = "line"` を追加：

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            platform = "line"
            ```

            保存後、OpenAB サービスを再起動してください。

            ## Webhook エンドポイント

            | パス | プラットフォーム |
            |------|----------------|
            | `POST /webhook/telegram` | Telegram |
            | `POST /webhook/line` | LINE |
            | `GET /ws` | OAB WebSocket（内部） |
            | `GET /health` | ヘルスチェック |

            ## リンク

            - [OpenAB GitHub](https://github.com/openabdev/openab)
            - [Telegram 設定ガイド](https://github.com/openabdev/openab/blob/main/docs/telegram.md)
            - [LINE 設定ガイド](https://github.com/openabdev/openab/blob/main/docs/line.md)
            - [Gateway README](https://github.com/openabdev/openab/blob/main/gateway/README.md)
    zh-CN:
        description: |
            OpenAB 独立 Webhook Gateway — 通过 WebSocket 将 Telegram 和/或 LINE 桥接到任何正在运行的 OAB 实例。部署于现有 OpenAB 服务旁，即可启用 Telegram 和/或 LINE 支持。至少须配置一个平台。
            来源：https://github.com/openabdev/openab
        variables:
            - key: TELEGRAM_BOT_TOKEN
              type: STRING
              name: Telegram Bot Token（选填）
              description: 选填。来自 @BotFather 的 Bot Token（https://t.me/BotFather）。留空则禁用 Telegram。Telegram 和 LINE 至少须填写其中一个。
            - key: LINE_CHANNEL_SECRET
              type: STRING
              name: LINE Channel Secret（选填）
              description: 选填。来自 LINE Developers Console 的 Channel Secret。留空则禁用 LINE。
            - key: LINE_CHANNEL_ACCESS_TOKEN
              type: STRING
              name: LINE Channel Access Token（选填）
              description: 选填。来自 LINE Developers Console 的 Channel Access Token。填写 LINE Channel Secret 时必填。
            - key: PUBLIC_DOMAIN
              type: STRING
              name: Gateway 域名
              description: 用于接收 Telegram 和 LINE Webhook 的公开 HTTPS 域名。
        readme: |
            # OpenAB Gateway

            [OpenAB Gateway](https://github.com/openabdev/openab) 是一个独立的 Webhook 桥接服务，通过 WebSocket 将 Telegram 和 LINE 连接到任何正在运行的 [OpenAB](https://github.com/openabdev/openab) 实例。

            ```
            Telegram ──POST──▶ ┌──────────────────┐
            LINE     ──POST──▶ │  OpenAB Gateway  │ ◀──WebSocket── OAB Pod
                               │     :8080        │   （OAB 主动向外连线）
                               └──────────────────┘
            ```

            将此模板部署于现有 OpenAB 服务（Claude、Cursor、Codex 等）旁，无需重新部署 OAB 即可添加 Telegram 和 LINE 支持。

            ## 前置条件

            - 同一个 Zeabur 项目中已有正在运行的 OpenAB 服务
            - **至少需要以下其中一个：**
              - 来自 [@BotFather](https://t.me/BotFather) 的 Telegram Bot Token
              - 已启用 Messaging API 的 LINE 官方账号（LINE Channel Secret + Access Token）

            ## 设置步骤

            ### 1. 创建 Telegram Bot

            1. 在 Telegram 打开 [@BotFather](https://t.me/BotFather)，发送 `/newbot`
            2. 复制 Bot Token → 粘贴到 **Telegram Bot Token**

            ### 2. 部署

            填入 Telegram Bot Token 后点击部署。系统自动分配公开 HTTPS 域名。

            ### 3. 注册 Telegram Webhook

            ```bash
            curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram"
            ```

            ### 4. 配置 OAB 使用 Gateway

            在 OpenAB 服务中编辑 `/home/agent/.config/openab/config.toml`：

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            ```

            重启 OpenAB 服务。

            ## LINE 设置（选填）

            ### 1. 创建 LINE 官方账号

            1. 前往 [LINE 官方账号管理后台](https://manager.line.biz) 创建账号
            2. **设置** → **Messaging API** → **启用 Messaging API**
            3. 打开 [LINE Developers Console](https://developers.line.biz) → 你的 Channel：
               - **Basic settings** → **Channel secret** → 复制 → 粘贴到 **LINE Channel Secret**
               - **Messaging API** → **Channel access token** → Issue → 复制 → 粘贴到 **LINE Channel Access Token**

            ### 2. 设置 Webhook URL

            在 LINE Developers Console → **Messaging API** 标签：

            1. **Webhook URL** → 编辑 → 输入：`https://YOUR_DOMAIN/webhook/line`
            2. **Use webhook** → 开启
            3. **Auto-reply messages** → 关闭
            4. 点击 **Verify**

            ### 3. 配置 OAB 使用 LINE

            在 `config.toml` 的 gateway 区块加入 `platform = "line"`：

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            platform = "line"
            ```

            保存后重启 OpenAB 服务。

            ## Webhook 端点

            | 路径 | 平台 |
            |------|------|
            | `POST /webhook/telegram` | Telegram |
            | `POST /webhook/line` | LINE |
            | `GET /ws` | OAB WebSocket（内部使用） |
            | `GET /health` | 健康检查 |

            ## 链接

            - [OpenAB GitHub](https://github.com/openabdev/openab)
            - [Gateway README](https://github.com/openabdev/openab/blob/main/gateway/README.md)
    zh-TW:
        description: |
            OpenAB 獨立 Webhook Gateway — 透過 WebSocket 將 Telegram 和／或 LINE 橋接到任何正在運行的 OAB 實例。部署於現有 OpenAB 服務旁，即可啟用 Telegram 和／或 LINE 支援。至少須設定一個平台。
            來源：https://github.com/openabdev/openab
        variables:
            - key: TELEGRAM_BOT_TOKEN
              type: STRING
              name: Telegram Bot Token（選填）
              description: 選填。來自 @BotFather 的 Bot Token（https://t.me/BotFather）。留空則停用 Telegram。Telegram 和 LINE 至少須填寫其中一個。
            - key: LINE_CHANNEL_SECRET
              type: STRING
              name: LINE Channel Secret（選填）
              description: 選填。來自 LINE Developers Console 的 Channel Secret。留空則停用 LINE。
            - key: LINE_CHANNEL_ACCESS_TOKEN
              type: STRING
              name: LINE Channel Access Token（選填）
              description: 選填。來自 LINE Developers Console 的 Channel Access Token。填寫 LINE Channel Secret 時必填。
            - key: PUBLIC_DOMAIN
              type: STRING
              name: Gateway 網域
              description: 用於接收 Telegram 和 LINE Webhook 的公開 HTTPS 網域。
        readme: |
            # OpenAB Gateway

            [OpenAB Gateway](https://github.com/openabdev/openab) 是一個獨立的 Webhook 橋接服務，透過 WebSocket 將 Telegram 和 LINE 連接到任何正在運行的 [OpenAB](https://github.com/openabdev/openab) 實例。

            ```
            Telegram ──POST──▶ ┌──────────────────┐
            LINE     ──POST──▶ │  OpenAB Gateway  │ ◀──WebSocket── OAB Pod
                               │     :8080        │   （OAB 主動對外連線）
                               └──────────────────┘
            ```

            將此 template 部署於現有 OpenAB 服務（Claude、Cursor、Codex 等）旁，無需重新部署 OAB 即可新增 Telegram 和 LINE 支援。

            ## 前置條件

            - 同一個 Zeabur 專案中已有正在運行的 OpenAB 服務
            - **至少需要以下其中一個：**
              - 來自 [@BotFather](https://t.me/BotFather) 的 Telegram Bot Token
              - 已啟用 Messaging API 的 LINE 官方帳號（LINE Channel Secret + Access Token）

            ## 設定步驟

            ### 1. 建立 Telegram Bot

            1. 在 Telegram 開啟 [@BotFather](https://t.me/BotFather)
            2. 發送 `/newbot` 並依照提示操作
            3. 複製 Bot Token（例如 `123456:ABC-DEF...`）→ 貼到 **Telegram Bot Token**
            4. 選填：發送 `/setprivacy` → `Disable`，讓 Bot 可以看到群組中所有訊息

            ### 2. 部署

            填入想啟用平台的 Token 後點擊部署。系統會自動分配公開 HTTPS 網域。可以只啟用 Telegram、只啟用 LINE，或兩者同時啟用。

            ### 3. 註冊 Telegram Webhook

            部署完成後，向 Telegram 註冊你的 Gateway URL（替換 `YOUR_TOKEN`、`YOUR_DOMAIN`，選填 `YOUR_SECRET`）：

            ```bash
            # 不帶 webhook secret（較簡單）
            curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram"

            # 帶 webhook secret（建議 — 與 TELEGRAM_SECRET_TOKEN 一致）
            curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=https://YOUR_DOMAIN/webhook/telegram&secret_token=YOUR_SECRET"
            ```

            預期回應：`{"ok":true,"result":true,"description":"Webhook was set"}`

            ### 4. 設定 OAB 使用 Gateway

            在同一個 Zeabur 專案的 OpenAB 服務中，編輯 `/home/agent/.config/openab/config.toml` 並加入：

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            ```

            儲存後重啟 OpenAB 服務。OAB 會主動對外連線到 Gateway，OAB 本身不需要開放任何 inbound 連接埠。

            > **內部 Hostname：** `openab-gateway` 在同一個 Zeabur 專案內透過內部 DNS 解析。若你的 Gateway 服務名稱不同，請改用對應名稱。

            ### 5. 測試

            向你的 Telegram Bot 發送訊息。Gateway 收到後透過 WebSocket 轉發給 OAB，OAB 處理後透過 Gateway 回覆。

            ## LINE 設定（選填）

            ### 1. 建立 LINE 官方帳號

            1. 前往 [LINE 官方帳號管理後台](https://manager.line.biz) 建立帳號
            2. **設定** → **Messaging API** → **啟用 Messaging API**
            3. 開啟 [LINE Developers Console](https://developers.line.biz) → 你的 Channel：
               - **Basic settings** → **Channel secret** → 複製 → 貼到 **LINE Channel Secret**
               - **Messaging API** → **Channel access token** → Issue → 複製 → 貼到 **LINE Channel Access Token**

            ### 2. 設定 Webhook URL

            在 LINE Developers Console → **Messaging API** 頁籤：

            1. **Webhook URL** → 編輯 → 輸入：`https://YOUR_DOMAIN/webhook/line`
            2. **Use webhook** → 開啟
            3. **Auto-reply messages** → 關閉
            4. 點擊 **Verify**

            ### 3. 設定 OAB 使用 LINE

            在 `config.toml` 的 gateway 區塊加入 `platform = "line"`：

            ```toml
            [gateway]
            url = "ws://openab-gateway:8080/ws"
            platform = "line"
            ```

            儲存後重啟 OpenAB 服務。

            ## Webhook 端點

            | 路徑 | 平台 |
            |------|------|
            | `POST /webhook/telegram` | Telegram |
            | `POST /webhook/line` | LINE |
            | `GET /ws` | OAB WebSocket（內部使用） |
            | `GET /health` | 健康檢查 |

            ## 連結

            - [OpenAB GitHub](https://github.com/openabdev/openab)
            - [Telegram 設定指南](https://github.com/openabdev/openab/blob/main/docs/telegram.md)
            - [LINE 設定指南](https://github.com/openabdev/openab/blob/main/docs/line.md)
            - [Gateway README](https://github.com/openabdev/openab/blob/main/gateway/README.md)
