facebook-messenger icon indicating copy to clipboard operation
facebook-messenger copied to clipboard

Best way to use bot analytics providers?

Open echan00 opened this issue 7 years ago • 2 comments

Since this gem creates a new message object different from the incoming payload, I was wondering whether anybody had thoughts on best way to integrate with bot analytics vendors?

Below is the json data that needs to be passed to typical vendors like dashbot.io via REST.

INCOMING

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

OUTGOING

{
  "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"
  }
}

echan00 avatar Oct 04 '17 02:10 echan00

Oh, cool, I never thought of this. You can get at the original object at message.messaging, though, so you can pass it to the analytics service in your code using that.

jgorset avatar Mar 30 '18 07:03 jgorset

I'll leave this open and tag accordingly if someone wants to add it to the README.

jgorset avatar Mar 30 '18 07:03 jgorset