這份文件已更新。
中文(香港) 的翻譯尚未完成。
英文更新時間:1月29日

messages Webhook 事件參考資料

當有訊息傳送到專頁時,此回呼便會出現。系統一律會順序傳送訊息。您可能會收到文字訊息或包含附件的訊息。

imageaudiovideofile 是主要的支援附件類型。此外,您還可能收到 fallback 附件。一個常見的「遞補」範例為:用戶向專頁分享網址時,系統會根據連結分享建立附件。如果系統不支援用戶向專頁分享的內容,則會傳送無裝載的 fallback

設定 Webhook 時,您可以選擇 message 以訂閱此回呼。

範例

文字訊息

{
  "sender":{
    "id":"<PSID>"
  },
  "recipient":{
    "id":"<PAGE_ID>"
  },
  "timestamp":1458692752478,
  "message":{
    "mid":"mid.1457764197618:41d102a3e1ae206a38",
    "text":"hello, world!",
    "quick_reply": {
      "payload": "<DEVELOPER_DEFINED_PAYLOAD>"
    }
  }
}    

回覆訊息

{
  "sender":{
    "id":"<PSID>"
  },
  "recipient":{
    "id":"<PAGE_ID>"
  },
  "timestamp":1458692752478,
  "message":{
    "mid":"m_1457764197618:41d102a3e1ae206a38",
    "text":"hello, world!",
    "reply_to": {
      "mid":"m_1fTq8oLumEyIp3Q2MR-aY7IfLZDamVrALniheU"
    }
  }
}    

包含附件的訊息

{
  "id": "682498302938465",
  "time": 1518479195594,
  "messaging": [
    {
      "sender": {
        "id": "

包含商品範本的訊息

包含商品範本的訊息 Webhook 只適用於 Graph API v8.0 版或以上版本

此 Webhook 適用於用戶分享來自其他對話串的商品,或者分享流程至專頁的情況。此 Webhook 僅適用於專頁擁有的商品。應用程式將需要獲批 catalog_management 權限才能以 Webhooks 接收商品詳情。

{
  "id": "682498302938465",
  "time": 1518479195594,
  "messaging": [
    {
      "sender": {
        "id": "

包含遞補附件的訊息

以下範例適用於 v6.0 版及以上版本的 messages

{
    "object": "page",
    "entry": [
        {
            "id": "<PAGE_ID>",
            "time": 1583173667623,
            "messaging": [
                {
                    "sender": {
                        "id": "<PSID>"
                    },
                    "recipient": {
                        "id": "<PAGE_ID>"
                    },
                    "timestamp": 1583173666767,
                    "message": {
                        "mid": "m_toDnmD...",
                        "text": "This is where I want to go: https:\/\/youtu.be\/bbo_fZAjIhg",
                        "attachments": [
                            {
                                "type": "fallback",
                                "payload": {
                                    "url": "<ATTACHMENT_URL >",
                                    "title": "TAHITI - Heaven on Earth"
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ]
}

來自「商店」商品詳情頁面的訊息

來自「商店」商品詳情頁面的訊息 Webhook 只適用於 Graph API v8.0 版或以上版本

{
  "sender":{
    "id":"<PSID>"
  },
  "recipient":{
    "id":"<PAGE_ID>"
  },
  "timestamp":1458692752478,
  "message":{
    "mid":"mid.1457764197618:41d102a3e1ae206a38",
    "text":"hello, world!",
    "referral": {
      "product": {
        "id":"<PRODUCT_ID>"
      }
    }
  }
}    

包含指令的訊息

{
  "object": "page",
  "entry": [
    {
      "id": "<PAGE_ID>",
      "time": 1697643211842,
      "messaging": [
        {
          "sender": {
            "id": "<PSID>"
          },
          "recipient": {
            "id": "<PAGE_ID>"
          },
          "timestamp": 1697643027400,
          "message": {
            "mid": "m_3vs...",
            "text": "find flights from SFO to LAX next Thursday",
            "commands": [
              {
                "name": "flights"
              }
            ]
          }
        }
      ]
    }
  ]
}

屬性

sender

sender FieldDescription

id

string

The Page-scoped ID for the person who sent a message to your business

user_ref

string

The reference for a person who used the Chat Plugin to messsage your business

recipient

recipient FieldDescription

id

string

The ID for your Facebook Page

message

2020 年 3 月 4 日公告

我們將 v6.0 版及以上版本的 sticker_idmessage 移至 message.attachments.payload

屬性 類型 說明

mid

字串

訊息編號

text

字串

訊息文字

quick_reply

物件

(選用項目)傳送內容的應用程式所提供的自訂資料

reply_to

物件

此訊息要回覆的訊息編號(mid)之引用資料

attachments

陣列 <attachment>

包含附件資料的陣列

referral

物件

「商店」商品詳情頁面的訊息之引用來源。

message.quick_reply

當用戶點按快速回覆按鈕時,系統只會提供包含文字訊息的 quick_reply 裝載。

屬性 類型 說明

payload

字串

應用程式提供的自訂資料

message.reply_to

屬性 類型 說明

mid

字串

此訊息要回覆的訊息編號之引用資料

message.attachments

屬性 類型 說明

type

字串

audiofileimagevideofallback

payload

字串

message.attachments.payload

message.attachments.payload

屬性 類型 說明

url

字串

附件類型的網址。適用的附件類型:audiofileimagevideofallback

title

字串

附件標題。適用的附件類型:fallback

sticker_id

數字

此貼圖的永久編號,例如,369239263222822 代表「讚好」貼圖。適用的附件類型:image(僅在傳送貼圖時)。

message.attachments.payload.product.elements

屬性 類型 說明

id

字串

來自 Facebook 商品目錄的商品編號

retailer_id

字串

與商品關聯的外部編號。(例如 SKU 或內容編號)

image_url

字串

商品網址

title

字串

商品標題

subtitle

字串

商品副標題

message.referral

僅在用戶從「商店」商品詳情頁面傳送訊息時,系統才會提供 referral 裝載。

屬性 類型 說明

product

物件

商品資訊

message.referral.product

屬性 類型 說明

id

字串

商品編號

message.commands

屬性 類型 說明

name

字串

指令的名稱