Facebook Messenger Webhook get "outbound" message text

710 views Asked by At

I am getting the following back as a webhook (Message-Delivered Callback) but I need to get the actual content of the message that was delivered. The Message-Received Callback has a "text" field that contains this information, but this one does not.

 {
  "object": "page",
  "entry": [{
      "id": 2880130XXXX7538,
      "time": 1462299418787,
      "messaging": [{
          "sender": {
              "id": 1261XXXX3865793
          },
          "recipient": {
              "id": 2880XXXX7977538
          },
          "delivery": {
              "mids": ["mid.146XXXX412750:6bd62757XXXXd68848"],
              "watermark": 1462XXXX12769,
              "seq": 50
          }
      }]
  }]
 }

I have tried unsuccessfully to use graph api with the message id but the docs are a little unclear if this is possible (https://developers.facebook.com/docs/graph-api/reference/v2.6/message/)

The token I am using has the following permissions: read_page_mailboxes, manage_pages, pages_messaging.

Any help would be greatly appreciated!!

2

There are 2 answers

0
henry255164 On

You can try this code:

$M = $input['entry'][0]['messaging'][0]['message']['text'];

AND "$M" is what you want. it's work! But i can't explain why

0
devonj On

Add "m_" to your delivery mids, so in this case:

m_mid.146XXXX412750:6bd62757XXXXd68848

And then make a facebook-graph-api request using that as the "message-id" in the URL. Use fields=message to get the message text.

Reference: https://developers.facebook.com/docs/graph-api/reference/v2.6/message/