# 應用 API 元件 - LINE

### **功能簡介**

您可以發送多種不同 HTTP 請求方法，讓機器人解析您的伺服器回應並回覆訊息。

具體而言，您將可以執行：

1. 創建動態訊息
2. 執行 postbacks
3. 取得並設定使用者參數（即將到來）
4. 轉向其他節點（即將到來）

### **回傳參考**

我們將解析您回傳的 JSON，以此為根據發送訊息給您的顧客。更多訊息請參考 [LINE API 文件](https://developers.line.biz/en/reference/messaging-api/)。

#### **發送文字**

以下回應將發送文字訊息。

```
{
  "messages": [
    {
      "type": "text",
      "text": "歡迎使用最聰明的聊天機器人平台 —— YOCTOL.AI"
    },
    {
      "type": "text",
      "text": "您打算創建怎樣的機器人呢？"
    }
  ]
}
```

#### **發送圖片**

目前圖片格式支援 JPG，以下回應將發送圖片訊息。

```
{
  "messages": [
    {
      "type": "image",
      "originalContentUrl": "https://example.com/original.jpg",
      "previewImageUrl": "https://example.com/preview.jpg"
    }
  ]
}
```

#### **發送影片**

以下回應將發送影片檔案。目前 LINE 僅支援 10MB 以下、1 分鐘以內的 MP4 檔網址。

```
{
  "messages": [
    {
      "type": "video",
      "originalContentUrl": "https://example.com/original.mp4",
      "previewImageUrl": "https://example.com/preview.jpg"
    }
  ]
}
```

#### **發送語音**

以下回應將發送語音檔案；目前 LINE 僅支援 10MB 以下、1 分鐘以內的 M4A 語音檔網址。

```
{
  "messages": [
    {
      "attachment": {
        "type": "audio",
        "payload": {
          "url": "https://ccrma.stanford.edu/~jos/mp3/bachfugue.mp3"
        }
      }
    }
  ]
}
```

#### **發送貼圖**

以下回應將發送貼圖。目前 LINE 支援的[貼圖清單](https://developers.line.biz/media/messaging-api/sticker_list.pdf)。

```
{
  "messages": [
    {
      "type": "sticker",
      "packageId": "1",
      "stickerId": "1"
    }
  ]
}
```

#### **按鈕**

以下回應將發送按鈕。您可以設定各個按鈕的動作，例如打開網站。更多關於按鈕的用法，請參考 [LINE 按鈕](https://developers.line.biz/en/reference/messaging-api/#buttons)。

```
{
  "messages": [
    {
      "type": "template",
      "altText": "This is a buttons template",
      "template": {
        "type": "buttons",
        "thumbnailImageUrl": "https://example.com/bot/images/image.jpg",
        "imageAspectRatio": "rectangle",
        "imageSize": "cover",
        "imageBackgroundColor": "#FFFFFF",
        "title": "Menu",
        "text": "Please select",
        "defaultAction": {
          "type": "uri",
          "label": "View detail",
          "uri": "http://example.com/page/123"
        },
        "actions": [
          {
            "type": "postback",
            "label": "Buy",
            "data": "action=buy&itemid=123"
          },
          {
            "type": "postback",
            "label": "Add to cart",
            "data": "action=add&itemid=123"
          },
          {
            "type": "uri",
            "label": "View detail",
            "uri": "http://example.com/page/123"
          }
        ]
      }
    }
  ]
}
```

另外您也可以傳送特殊按鈕，例如打開相機。

```
{
  "messages": [
    {
      "type": "template",
      "altText": "This is a buttons template",
      "template": {
        "type": "buttons",
        "text": "Please select",
        "actions": [
          {
            "type": "camera",
            "label": "Camera"
          },
          {
            "type": "cameraRoll",
            "label": "Camera roll"
          }
        ]
      }
    }
  ]
}
```

#### **快速回覆**

以下回應將發送快速回覆。

```
{
  "messages": [
    {
      "type": "text",
      "text": "Did you enjoy the last game of the CF Rockets?",
      "quickReply": {
        "items": [
          {
            "type": "action",
            "action": {
              "type": "cameraRoll",
              "label": "Send photo"
            }
          },
          {
            "type": "action",
            "action": {
              "type": "camera",
              "label": "Open camera"
            }
          }
        ]
      }
    }
  ]
}
```


---

# 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://docs-tw.yoctol.ai/settings/json_api_line.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.
