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=10.1.1-rest&type=incoming&apiKey=API_KEY_HERE

The data to POST should pass the following data:

{
  "object": "page",
  "entry": [
    {
      "id": "943703799078240",
      "time": ,
      "messaging": [
        {
          "sender": {
            "id": "1018952661536494"
          },
          "recipient": {
            "id": "943703799078240"
          },
          "timestamp": ,
          "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":,"messaging":[{"sender":{"id":"1018952661536494"},"recipient":{"id":"943703799078240"},"timestamp":,"message":{"mid":"mid.1468531733396:9242db91fea253e355","seq":978,"text":"Hi, bot"}}]}]}' \
     'https://tracker.dashbot.io/track?platform=facebook&v=10.1.1-rest&type=incoming&apiKey=API_KEY_HERE'

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=10.1.1-rest&type=outgoing&apiKey=API_KEY_HERE

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=10.1.1-rest&type=outgoing&apiKey=API_KEY_HERE'

Example

View a complete example.

Close Menu