Facebook Integration with REST API

Create a bot API key

Each bot needs its own API key for tracking.

Create a bot to get an API key.

Integrate the REST API

There are two integration points as outlined below.

  1. When Facebook posts to your webhook endpoint

When Facebook posts to your webhook endpoint, post the same data Facebook sent to you to the following endpoint:

https://tracker.dashbot.io/track?platform=facebook&v=11.1.0-rest&type=incoming&apiKey=<strong>API_KEY_HERE</strong>

Make sure to set the ‘Content-Type’ header to ‘application/json’

The data to POST should pass the following data:

{
  "object": "page",
  "entry": [
    {
      "id": "943703799078240",
      "time": 1610470068673,
      "messaging": [
        {
          "sender": {
            "id": "1018952661536494"
          },
          "recipient": {
            "id": "943703799078240"
          },
          "timestamp": 1610470068673,
          "message": {
            "mid": "mid.1468531733396:9242db91fea253e355",
            "seq": 978,
            "text": "Hi, bot"
          }
        }
      ]
    }
  ]
}

Sample cURL

curl -X POST -H "Content-Type: application/json"
     -d '{"object":"page","entry":[{"id":"943703799078240","time": 1610470068673,"messaging":[{"sender":{"id":"1018952661536494"},"recipient":{"id":"943703799078240"},"timestamp": 1610470068673,"message":{"mid":"mid.1468531733396:9242db91fea253e355","seq":978,"text":"Hi, bot"}}]}]}'
     'https://tracker.dashbot.io/track?platform=facebook&v=11.1.0-rest&type=incoming&apiKey=<strong>API_KEY_HERE</strong>'

Note
This is just an example — we accept any rich media that Facebook accepts.

2. When your bot sends a message


When your bot sends a message, POST to the following endpoint:

https://tracker.dashbot.io/track?platform=facebook&v=11.1.0-rest&type=outgoing&apiKey=<strong>API_KEY_HERE</strong>

Make sure to set the ‘Content-Type’ header to ‘application/json’

The data to POST should pass the following data:

{
  "qs": {
    "access_token": "<YOUR ACCESS TOKEN>"
  },
  "uri": "https://graph.facebook.com/v2.6/me/messages",
  "json": {
    "message": {
      "text": "Hello, my human pet"
    },
    "recipient": {
      "id": "975099989272315"
    }
  },
  "method": "POST",
  "responseBody": {
    "recipient_id": "975099989272315",
    "message_id": "mid.1470371655004:4727480467538e9450"
  }
}

Sample cURL

curl -X POST -H "Content-Type: application/json"
     -d '{"qs":{"access_token":""},"uri":"https://graph.facebook.com/v2.6/me/messages","json":{"message":{"text":"Hello, my human pet"},"recipient":{"id":"975099989272315"}},"method":"POST","responseBody":{"recipient_id":"975099989272315","message_id":"mid.1470371655004:4727480467538e9450"}}'
     'https://tracker.dashbot.io/track?platform=facebook&v=11.1.0-rest&type=outgoing&apiKey=<strong>API_KEY_HERE</strong>'

Note
This is just an example — we accept any rich media that Facebook accepts.

Example

View a complete example.