快速回覆

「快速回覆」提供了一個向用戶展示按鈕的新方式。「快速回覆」就位在輸入欄位的正上方,使用鍵盤時可能會不太明顯。點按「快速回覆」後,訊息就會傳送到對話中,回傳中包含開發人員定義的中繼資料。此外,按鈕點按後就會消失,這樣可以避免用戶於對話中再次點按到舊訊息上附加的按鈕。

「快速回覆」內含文字。您可以自行選擇加入圖像。

您也可以使用「快速回覆」提示用戶的位置。

範例

僅有文字

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 陣列

N

  • quick_replies 限制為 11

attachment 物件

屬性名稱 描述 必須項目

type

附件類型可能是 image 或 template

Y

payload

附件的承載

Y

「快速回覆」適用所有訊息類型,包含文字訊息、圖像與範本附件。請參閱傳送 API 文件以進一步瞭解如何使用 attachment 物件。

quick_reply 物件

屬性名稱 描述 類型 必須項目

content_type

text 或 location

字串

Y

title

按鈕的說明

字串

僅限 content_type 是 text 的狀況

payload

會透過 webhook 回傳給您的自訂數據

字串

僅限 content_type 是 text 的狀況

image_url

text 快速回覆的圖像網址

字串

N

  • title 限用 20 個字元,任何超過 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
                  }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}