> ## Documentation Index
> Fetch the complete documentation index at: https://docs.panguard.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 設定通知

> 設定警報頻道，讓 Panguard 透過 Telegram、Slack、Email、LINE 或 Webhook 通知你威脅事件。

Panguard 把安全警報送到你團隊已經在用的頻道。這篇指南帶你設定 5 種通知頻道，並用角色控制誰收到什麼。

<Steps>
  <Step title="初始化通知設定">
    跑互動式設定精靈：

    ```bash theme={null}
    panguard chat setup
    ```

    精靈會引導你選頻道、輸入憑證。你也可以用下面的 flag 個別設定。
  </Step>

  <Step title="設定通知頻道">
    設定一個或多個頻道：

    <Tabs>
      <Tab title="Telegram">
        1. 在 Telegram 找 [@BotFather](https://t.me/BotFather) 建立一個新 bot
        2. 複製 bot token
        3. 跟你的 bot 開對話，隨便傳一則訊息
        4. 透過 Telegram API 或 [@userinfobot](https://t.me/userinfobot) 取得 chat ID

        ```bash theme={null}
        panguard chat setup --channel telegram \
          --telegram-token "123456:ABC-DEF..." \
          --telegram-chat-id "-1001234567890"
        ```

        <Tip>
          群組通知的話，把 bot 加進 Telegram 群組，用群組的 chat ID（開頭是 `-100`）。
        </Tip>
      </Tab>

      <Tab title="Slack">
        1. 到 [api.slack.com/apps](https://api.slack.com/apps) 建立新 app
        2. 在 **Bot Token Scopes** 加上 `chat:write` OAuth scope
        3. 把 app 裝到你的 workspace
        4. 複製 Bot User OAuth Token

        ```bash theme={null}
        panguard chat setup --channel slack \
          --slack-token "xoxb-..." \
          --slack-channel "#security-alerts"
        ```
      </Tab>

      <Tab title="Email">
        設定 SMTP 憑證收 email 通知：

        ```bash theme={null}
        panguard chat setup --channel email \
          --smtp-host "smtp.gmail.com" \
          --smtp-port 587 \
          --smtp-user "alerts@yourcompany.com" \
          --smtp-pass "app-password" \
          --email-to "security-team@yourcompany.com"
        ```

        <Info>
          Gmail 請用[應用程式密碼](https://support.google.com/accounts/answer/185833)，不要用帳號密碼。要先開兩步驟驗證。
        </Info>
      </Tab>

      <Tab title="LINE">
        1. 到 [notify-bot.line.me](https://notify-bot.line.me/) 建立 LINE Notify token
        2. 選要收通知的群組或一對一對話

        ```bash theme={null}
        panguard chat setup --channel line \
          --line-token "your-line-notify-token"
        ```
      </Tab>

      <Tab title="Webhook">
        送 JSON payload 到任何 HTTP 端點：

        ```bash theme={null}
        panguard chat setup --channel webhook \
          --webhook-url "https://your-server.com/api/panguard-alerts" \
          --webhook-secret "your-hmac-secret"
        ```

        Panguard 發 `POST` 請求，payload 格式如下：

        ```json theme={null}
        {
          "event": "guard.alert",
          "severity": "critical",
          "title": "Reverse shell detected",
          "details": { ... },
          "timestamp": "2026-03-07T14:22:01Z",
          "signature": "sha256=..."
        }
        ```

        `signature` header 是用你的 webhook secret 對 body 做 HMAC-SHA256 的結果，用來驗證來源。
      </Tab>
    </Tabs>
  </Step>

  <Step title="設定使用者角色">
    Panguard 有 3 種角色控制通知的詳細程度：

    | 角色          | 收到什麼                    | 適合誰        |
    | ----------- | ----------------------- | ---------- |
    | `developer` | 所有嚴重程度，完整技術細節           | 工程師、DevOps |
    | `boss`      | 只有 CRITICAL 和 HIGH，白話摘要 | 主管、管理層     |
    | `it_admin`  | 所有嚴重程度，中等細節，附行動項目       | IT 維運      |

    幫每個頻道指定角色：

    ```bash theme={null}
    panguard chat setup --channel telegram --role developer
    panguard chat setup --channel email --role boss
    panguard chat setup --channel slack --role it_admin
    ```

    <Tip>
      同一個頻道類型可以設定多次、用不同角色。例如 developer 等級的警報送 `#security-engineering`，boss 等級的摘要送 `#security-executive`。
    </Tip>
  </Step>

  <Step title="測試設定">
    送測試通知到所有已設定的頻道：

    ```bash theme={null}
    panguard chat test
    ```

    ```
      PANGUARD AI - Chat Test

      Sending test notification...

      Telegram   ... sent
      Slack      ... sent
      Email      ... sent

      All channels verified.
    ```

    測試特定頻道：

    ```bash theme={null}
    panguard chat test --channel slack
    ```
  </Step>

  <Step title="確認啟用的頻道">
    列出所有通知頻道和狀態：

    ```bash theme={null}
    panguard chat status
    ```

    ```
      PANGUARD AI - Chat Status

      -- Channels -------------------------------

      Telegram   Active   role: developer   last sent: 2m ago
      Slack      Active   role: it_admin    last sent: 15m ago
      Email      Active   role: boss        last sent: 1h ago

      3 channels configured, 3 active.
    ```
  </Step>
</Steps>

## 下一步

<CardGroup cols={2}>
  <Card title="設定即時防護" icon="shield-halved" href="/guides/real-time-protection">
    通知需要 Guard 在跑。先啟動持續監控。
  </Card>

  <Card title="通知系統參考" icon="comments" href="/products/chat/overview">
    通知系統的完整文件。
  </Card>

  <Card title="使用者角色詳解" icon="users" href="/products/chat/user-roles">
    每種角色收到的內容和訊息格式說明。
  </Card>

  <Card title="通知疑難排解" icon="wrench" href="/troubleshooting/notification-issues">
    頻道設定和寄送的常見問題。
  </Card>
</CardGroup>
