# 範例：發送 LINE 訊息

## 1. 新增 Webhook 腳本

因發送 LINE 通知需透過 LINE Message API，所以我們需透過「Webhook 腳本」來呼叫 API 網址，而相關資訊可由 <https://developers.line.biz/en/reference/messaging-api/> 官方文件查詢。

{% hint style="info" %}
**呼叫網址**：<https://api.line.me/v2/bot/message/push\\>
**請求方法**：POST\
**表頭**：選擇 Authorization 並填寫 Bearer {channel access token}
{% endhint %}

![](/files/-Mcxva5APKU9oAmezxb7)

## 2. 設定 LINE Message API 參數

接著，依據 LINE 要求格式，應該至少需有 2 個欄位如下&#x20;

1. to：ID of the target recipient. Use a userId, groupId, or roomId value returned in a webhook event object. Do not use the LINE ID found on LINE.
2. messages：Messages to send.

{% tabs %}
{% tab title="工單範例" %}

```javascript
{     
    "to": "U121dadadasdadddsdc",     
    "messages":[         
        {             
           "type": "text",             
           "text": "{{ subject }} 事件通知！"         
        }     
    ] 
}
```

{% endtab %}

{% tab title="整合 LIFF 範例" %}

```javascript
{
  "to": "{{ textCall.liff_user_id }}",
  "messages": [
    {
      "type": "text",
      "text": "{{ contact.full_name }} 先生/小姐，您好，專員傳送「{{ textCall.last_message.content }}」，\n 請點擊 👉 https://liff.line.me/xxxxxxx 查閱訊息。"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

![LIFF 配合即時聊天通知用戶的範例](/files/-McxytjbVHmBQZepfSOE)

## 3. 新增自動化

最後，新增完成「發送 LINE 通知」Webhook 腳本後，並不會主動執行，所以我們需要透過「自動化」功能設定好想要的條件，並於「動作」中選擇此「Webhook」，接著只要等待事件發生，即能享受自動化的妙用。

![](/files/-McxzS7nTqceJIs6utb-)

### 設計使用場景

你可以依照不同使用場景來決定發送 LINE 通知，新增加相對應的條件與觸發點，如以下狀況：

* 當有緊急工單時，發送 LINE 通知提醒相關部門。
* 當整合即時聊天於 LIFF 中，專員回覆訊息但客戶未開啟聊天視窗，發送 LINE 通知告知內容與 LIFF 網址。
* 當工單轉派給指定督導時，也同步發送通知提醒。

![發送 LINE 通知提醒相關部門](/files/-Mcy-pU4unBiwwfF_2o6)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.firstline.cc/feature/integrate/automation/send-line-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
