> For the complete documentation index, see [llms.txt](https://qiu-yan-ming.gitbook.io/python-chatbot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://qiu-yan-ming.gitbook.io/python-chatbot/line-bot-api.md).

# 測試LINE BOT Webhook

> ## Header
>
> <https://developers.line.me/en/reference/messaging-api/#request-headers>

| HeaderName       | 描述        |
| ---------------- | --------- |
| X-Line-Signature | 訊息驗證的加密簽章 |

當LINE的一個訊息傳遞過來時，Http請求內會包含一個header\
&#x20;X-Line-Signature 這個header是用作訊息驗證的\
LINE會將傳遞過來的Http Request Body使用你的Line Bot Secret做SHA256加密\
並且塞入 X-Line-Signature 這個header當中

> ## RequestBody
>
> <https://developers.line.me/en/reference/messaging-api/#wh-text>

這邊先以文字訊息為例

```
{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U4af4980629..."
  },
  "message": {
    "id": "325708",
    "type": "text",
    "text": "Hello, world!"
  }
}
```

若為文字訊息RequestBody則會長成這樣

| Key        | 描述                                                                     |
| ---------- | ---------------------------------------------------------------------- |
| replyToken | 用來做訊息回覆的令牌                                                             |
| type       | 描述這是什麼訊息message代表是訊息事件                                                 |
| timestamp  | 什麼時候發生的? 這是unixtime                                                    |
| source     | 訊息來源                                                                   |
| ->type     | 訊息的來源地( 有可能是群組(group, room)或是個人(user) )                                |
| ->userId   | <p>userId是該User對你這個LINE Bot的識別碼</p><p>因此我們是透過userId(UUID)來識別每個User</p> |
| message    | 訊息內容                                                                   |
| id         | 訊息的編號                                                                  |
| type       | 訊息的格式(文字訊息, 圖片訊息, ...etc)                                              |
| text       | 使用者輸入的文字內容(ex: Hi Chatbot你好嗎?)                                         |

> ## 使用Postman進行測試

![參照橘框的部分進行Postman設定](/files/-LQSuLa-cLKZOx5KHdgJ)

![設定你的request body](/files/-LQSueN34m-FD57N3PJf)

最後再按下右上角藍色的send按鈕

![返回結果](/files/-LQSupbs9HIsr8KTMA1m)

\
如果你的Result右上角status是400的話就代表你成功發出一個request請求並且被server進行處理了

而這邊導致400發生的原因就是因為我們的X-Line\_Signature不是正確的加密

不過這樣就足夠了, 來進行下一步吧
