快速回覆

「快速回覆」提供了一種向用戶顯示按鈕的新方式。「快速回覆」會顯示在 Composer 上方的明顯位置,讓鍵盤較不顯眼。當用戶點按「快速回覆」,訊息會在對話中發送,並在回呼中傳送開發人員定義的中繼資料。此外,按鈕會消失,以避免用戶點按對話中附加在舊訊息上的按鈕。

「快速回覆」會包含文字。您可選擇加入圖像。

您也可使用「快速回覆」來提示用戶輸入所在地點。

範例

純文字

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "text":"Pick a color:",
    "quick_replies":[
      {
        "content_type":"text",
        "title":"Red",
        "payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED"
      },
      {
        "content_type":"text",
        "title":"Green",
        "payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN"
      }
    ]
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"    

文字和圖像

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "text":"Pick a color:",
    "quick_replies":[
      {
        "content_type":"text",
        "title":"Red",
        "payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED",
        "image_url":"http://petersfantastichats.com/img/red.png"
      },
      {
        "content_type":"text",
        "title":"Green",
        "payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN",
        "image_url":"http://petersfantastichats.com/img/green.png"
      }
    ]
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"    

地點

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "text":"Please share your location:",
    "quick_replies":[
      {
        "content_type":"location",
      }
    ]
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"

欄位

message 物件

屬性名稱 說明 必要

text

訊息文字

必須設定 text 或 attachment

attachment

attachment 物件

必須設定 text 或 attachment

quick_replies

會隨同訊息傳送的 quick_reply 陣列

否

  • quick_replies 的數量上限為 11

attachment 物件

屬性名稱 說明 必要

type

附件類型,可為 image 或 template

是

payload

附件承載

是

「快速回覆」適用於所有訊息類型,包括文字訊息、圖像和範本附件。如需有關如何使用 attachment 物件的詳細資訊,請參閱傳送 API 文件。

quick_reply 物件

屬性名稱 說明 型別 必要

content_type

text 或 location

字串

是

title

按鈕說明

字串

只有在 content_type 為 text 時

payload

會透過 Webhook 傳回給您的自訂資料

字串

只有在 content_type 為 text 時

image_url

text 快速回覆的圖像網址

字串

否

  • title 的字元數不可超過 20,超出部分會被截斷
  • payload 的字元數不可超過 1000
  • 當 content_type 為 location,不使用 title 和 payload
  • image_url 所指的圖像應至少為 24x24,並會遭到裁切與調整大小

回呼

當用戶點按「快速回覆」,文字訊息會發送到您的 Webhook 已收到訊息回呼。訊息文字會對應「快速回覆」的標題。訊息物件還會包含名為 quick_reply 的欄位,內含「快速回覆」的 payload 資料。

{
  "sender": {
    "id": "USER_ID"
  },
  "recipient": {
    "id": "PAGE_ID"
  },
  "timestamp": 1464990849275,
  "message": {
    "mid": "mid.1464990849238:b9a22a2bcb1de31773",
    "seq": 69,
    "text": "Red",
    "quick_reply": {
      "payload": "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED"
    }
  }
}    

當用戶分享所在地點,回呼會類似如下:

{
  "object": "page",
  "entry": [
    {
      "id": "PAGE_ID",
      "time": 1472672934319,
      "messaging": [
        {
          "sender": {
            "id": "USER_ID"
          },
          "recipient": {
            "id": "PAGE_ID"
          },
          "timestamp": 1472672934259,
          "message": {
            "mid": "mid.1472672934017:db566db5104b5b5c08",
            "seq": 297,
            "attachments": [
              {
                "title": "Facebook HQ",
                "url": "https://www.facebook.com/l.php?u=https%....5-7Ocxrmg",
                "type": "location",
                "payload": {
                  "coordinates": {
                    "lat": 37.483872693672,
                    "long": -122.14900441942
                  }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}