$(document).ready(function(){ $('#collapse1').collapse("hide"); $('#collapse2').collapse("hide"); });

Messages

Request

In order to send incoming/out-going messages to Botanalytics, make a POSTcall tohttps://botanalytics.co/api/v1/messages/facebook-messenger

Example

         
curl  "https://botanalytics.co/api/v1/messages/facebook-messenger" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d
'{
    "recipient":"1005636636158788" (should be null for the incoming messages),
    "timestamp":1458692752478
    "message": see below incoming/out-going message structures.
}'             

Fields

4
Field Name Description Type Required
message Message JSON Yes
recipient Recipient String Yes
timestamp Timestamp Number Yes
notification_type Notification Type Push notification type: REGULAR, SILENT_PUSH, NO_PUSH No

Simple Node.js code example

Below you can see a function track is defined and called for incoming and out-going messages.

     
     ...
     var request = require('request')
     ...
     function track(recipient,message,timestamp){
       request({
             url: 'https://botanalytics.co/api/v1/messages/facebook-messenger',
             body: JSON.stringify({message: message,
             recipient: recipient,
             timestamp:timestamp}),
             method: 'POST',
             headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Token 324d5564a67f15e56f8f6ef4cd3e9342'
             }
     }, function(error, response, body){

         if(error) {
           console.log(error)
         } else {
           console.log(response.statusCode, body)
         }
    })
   }
   ...

   app.post('/webhook/', function (req, res) {
       messaging_events = req.body.entry[0].messaging
       track(null,req.body,new Date().getTime()) // incoming message, this call should be at the top of the webhook, and recipient should be null for the incoming messages.
       ...
       res.sendStatus(200)
   })
   function sendTextMessage(sender, text) {
       messageData = {
           text:text
       }
       ...

       track(sender,messageData,new Date().getTime()) // out-going text message, this call should be at the bottom of the mesage send method.
   }
   function sendGenericMessage(sender) {
       messageData = {
           "attachment": {
               "type": "template",
               "payload": {
                   "template_type": "generic",
                   "elements": [
                   {
                       "title": "Model S",
                       "subtitle": "Performance and safety refined",
                       "image_url": "http://blog.caranddriver.com/wp-content/uploads/2016/04/2017-Tesla-Model-S-P90D-101-876x535.jpg",
                       "buttons":
                       [
                         {
                             "type": "web_url",
                             "url": "https://www.teslamotors.com/models",
                             "title": "Explore"
                         },
                         {
                             "type": "postback",
                             "title": "Buy Now!",
                             "payload": "See, it's coming",
                         }
                     ],
                   },
                   {
                       "title": "Model X",
                       "subtitle": "Meet Model X",
                       "image_url": "http://o.aolcdn.com/hss/storage/midas/f03635ab3daec6021760a187b6153b75/202724181/modelx.jpg",
                       "buttons":
                       [
                         {
                             "type": "web_url",
                             "url": "https://www.teslamotors.com/modelx",
                             "title": "Explore"
                         },
                         {
                             "type": "postback",
                             "title": "Buy Now!",
                             "payload": "See, it's coming",
                         }
                       ],
                   }]
               }
           }
       }
       track(sender,messageData,new Date().getTime()) // out-going generic template message, this call should be at the bottom of the message send method.
   }


     

incoming message structure

Text message

                       
                         {
                             "object":"page",
                             "entry":[
                               {
                                 "id":"PAGE_ID",
                                 "time":1458692752478,
                                 "messaging":[
                                   {
                                     "sender":{
                                       "id":"USER_ID"
                                     },
                                     "recipient":{
                                       "id":"PAGE_ID"
                                     },
                                     "timestamp":1458692752478,
                                     "message":{
                                         "mid":"mid.1457764197618:41d102a3e1ae206a38",
                                         "seq":73,
                                         "text":"hello, world!",
                                     }
                                   }
                                 ]
                               }
                             ]
                           }
                       

Attachment message

                         
                         {
                           "object":"page",
                           "entry":[
                             {
                               "id":"PAGE_ID",
                               "time":1458692752478,
                               "messaging":[
                                 {
                                   "sender":{
                                     "id":"USER_ID"
                                   },
                                   "recipient":{
                                     "id":"PAGE_ID"
                                   },
                                   "timestamp":1458692752478,
                                   "message":{
                                          "mid":"mid.1458696618141:b4ef9d19ec21086067",
                                          "seq":51,
                                          "attachments":[
                                            {
                                              "type":"image",
                                              "payload":{
                                                "url":"IMAGE_URL"
                                              }
                                            }
                                          ]
                                        }
                                 }
                               ]
                             }
                           ]
                         }
                       

out-going message structure

Text message

       
         {"text" : hello, world!"}
     

Image message

     
     {
       "attachment":{
         "type":"image",
         "payload":{
           "url":"IMAGE_URL"
         }
       }
     }
     

Template message

     
     {
      "attachment":{
      "type":"template",
      "payload":{
        "template_type":"generic",
        "elements":[
              {
                "title":"Welcome to Peter\'s Hats",
                "image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png",
                "subtitle":"We\'ve got the right hat for everyone.",
                "buttons":[
                  {
                    "type":"web_url",
                    "url":"https://petersapparel.parseapp.com/view_item?item_id=100",
                    "title":"View Website"
                  },
                  {
                    "type":"postback",
                    "title":"Start Chatting",
                    "payload":"USER_DEFINED_PAYLOAD"
                  }
                ]
            }
       ]
      }
     }
   }
   

User Profile

Request

In order to send the User Profile to Botanalytics, make a POSTcall tohttps://botanalytics.co/api/v1/facebook-messenger/users/

Example

       
curl  "https://botanalytics.co/api/v1/facebook-messenger/users/" \
-X POST -H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d
'{
      "first_name": "Peter",
      "last_name": "Chang",
      "profile_pic": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/13055603_10105219398495383_8237637584159975445_n.jpg?oh=1d241d4b6d4dac50eaf9bb73288ea192&oe=57AF5C03&__gda__=1470213755_ab17c8c8e3a0a447fed3f272fa2179ce",
      "locale": "en_US",
      "timezone": -7,
      "gender": "male"
      "user_id":"USER_ID"
}'            

      

Fields

Field Name Description Type Required
first_name First name String No
last_name Last name String No
profile_pic Profile picture String No
locale Locale String No
timezone Timezone Timezone, number relative to GMT No
gender Gender String No
user_id User ID String Yes

Simple Node.js code example

Below you can see an example of engage function

     
     ...
     var request = require('request')
     ...
     function engage(first_name,last_name,profile_pic,locale,timezone,gender,user_id){
       request({
             url: 'https://botanalytics.co/api/v1/facebook-messenger/users/',
             body: JSON.stringify({first_name: first_name,
             last_name: last_name,
             profile_pic:profile_pic
             locale:locale,
             timezone:timezone,
             gender:gender,
             user_id:user_id
             }),
             method: 'POST',
             headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Token 324d5564a67f15e56f8f6ef4cd3e9342'
             }
     }, function(error, response, body){

         if(error) {
           console.log(error)
         } else {
           console.log(response.statusCode, body)
         }
    })
   }
   ...
     

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Initialize

Request

When you first connect slack via rtm.start, please make a POSTcall tohttps://botanalytics.co/api/v1/bots/slack/initialize/the data that slack returns

Example

       curl  "https://botanalytics.co/api/v1/bots/slack/initialize/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
        "self": {
            "...": "...",
            "...": "..."
         },
         "team": {
            "...": "...",
            "...": "..."
         },
         "users": [ … ],
         "channels": [ … ],
         "groups": [ … ],
         "ims": [ … ]
    }'

    

Fields

Field Name Description Required
self Self Yes
team Team Yes
users Users Yes
channels Channels Yes
groups Groups Yes
ims Ims Yes

Messages

Request

We use Slack's message structure, when you receive/send message simply make a POSTcall tohttps://botanalytics.co/api/v1/messages/slack/

Example

     curl  "https://botanalytics.co/api/v1/messages/slack/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
      "message":{
            "channel": "D2PL0NX52",
            "user": "U2PL4GMNC",
            "type":"message",
            "text": "then bot",
            "attachments": [...],
            "team": "T27N7RKSA",
            "ts": 123456789
      }
}'            

    

Fields

Field Name Description Type Required
message Message message object Yes

message object

Field Name Description Type Required
channel Message String Yes
user User String Yes
type Type String Yes
text Text String text or/and attachments must be set
attachments Attachments Slack Attachment object text or/and attachments must be set
team Team String Yes
ts Ts Timestamp Yes

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Messages

Request

In order to send incoming/out-going messages to Botanalytics, make a POSTcall tohttps://botanalytics.co/api/v1/messages/generic/

Example

     curl  "https://botanalytics.co/api/v1/messages/generic/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
      "is_sender_bot": true,
      "user":{
        "id": "...",
        "name": "..."
      },
      "message":{
        "timestamp": 1458692752478,
        "text": "..."
      }
}'            

    

Fields

Field Name Description Type Required
is_sender_bot Simply set to true If message is send by your bot, and false If not Boolean Yes
user user object Yes
message message object Yes

user object

Field Name Description Type Required
id Unique user identifier String Yes
name Full name of the user String No

message object

Field Name Description Type Required
timestamp Timestamp of the message Timestamp Yes
text Message text String Yes

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Live Person Takeover - Hybrid Mode

On Hybrid mode, human representative can join the conversation with pausing the bot. To improve the engagement of conversations, you can pause the bot and join the conversation. You can send messages as If they are coming from your bot. After you talk with your user, you can enable bot again before leaving the conversation.

Facebook Messenger Pause Webhook

Your webhook will recieve two fields in the body:
userId: the facebook user id of the session to pause
paused: true = pause the bot; false = unpause the bot

While the details of the implementation may vary, at a high level, your webhook should keep track of which user sessions are paused. Whenever a new message is received, check if the session is paused for that user, and if so, stop the bot responding.

Facebook Webhook Example:

This is basic example that maintains state in memory. For a more robust solution, save the state in a database or other persistent memory store.

          

var pausedUsers = {}
  app.post('/pause', jsonParser, function (req, res) {
    const userId = req.body.userId
    const paused = req.body.paused
    pausedUsers[userId] = paused
    res.send("ok")
})


       

And then, check the status after receiving a message:

         

app.post('/webhook/', jsonParser, function (req, res) {
  ...
  if(req.body.entry){
    req.body.entry.forEach(function(entry){
      if(entry.messaging){
        entry.messaging.forEach(function(event){
          var recipientId = event.sender.id;
          if(!pausedUsers[recipientId]){
            //handle message if session is not paused for this userId
            [...]
          }
        }
      }
    }
  }
  ...
}
          


        

Slack Pause Webhook

Your webhook will recieve two fields in the body:
channelId: the slack channel id to pause
teamIdthe slack team id of the session to pause
paused: true = pause the bot; false = unpause the bot

While the details of the implementation may vary, at a high level, your webhook should keep track of which user sessions are paused. Whenever a new message is received, check if the session is paused for that user, and if so, stop the bot responding.

Add the Webhook Url and Platform Token to your Account

Please go to your settings and set hybrid mode settings

or you can make a PATCHcall tohttps://botanalytics.co/api/v1/bots/me

Example

            curl  "https://botanalytics.co/api/v1/bots/me" \
-X PATCH \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d
'{
    "platform_token": "..",
    "webhook_url" : ".."
    "partner_webhook_url" : ".."
}'            

           

Fields

Field Name Description Type Required
platform_token Your bot's platform token String No
webhook_url Your pause webhook url, ex: https://yourwebhookurl/pause String No
partner_webhook_url If you are using one of our partners platform, set platform webhook url for live takeover String No

Please keep in mind either partner_webhook_url or platform_token and webhook_url together should be set for live takeover.

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Try it out

Please go to your conversation page and toggle Live then option you'll see live conversations.

Click one of the live conversations listed to see the conversation flow, you'll then have option of pausing the bot and sending messages right there.

Messages

Request

We use WeChat's message structure, when you receive/send message simply make a POSTcall tohttps://botanalytics.co/api/v1/messages/wechat/

Example

            curl  "https://botanalytics.co/api/v1/messages/wechat/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
      "is_sender_bot": true,
      "message": {
          "ToUserName" : "tousername",
          "FromUserName":"fromusername",
          "CreateTime" : 1348831860 ,
          "MsgType" : "text",
          "Content" : "this is a test"
      }
}'            

           

Fields

Field Name Description Type Required
is_sender_bot Simply set to true If message is send by your bot, and false If not Boolean Yes
message message object Yes

message object

Field Name Description Type Required
ToUserName ToUserName String Yes
FromUserName FromUserName String Yes
CreateTime create time of the message Timestamp Yes
MsgType message type String Yes
Content Content String Depends on message types

User Profile

Request

We use WeChat's user profile structure, when you receive user profile simply make a POSTcall tohttps://botanalytics.co/api/v1/wechat/users/

Example

            curl  "https://botanalytics.co/api/v1/wechat/users/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
    "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
    "nickname": "Band",
    "sex": 1,
    "language": "zh_CN",
    "city": "Guangzhou",
    "province": "Guangdong",
    "country": "China",
    "headimgurl":    "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
    "subscribe_time": 1382694957
}'            

           

Fields

Field Name Description Type Required
openid openid String Yes
nickname nickname String Yes
sex sex String No
language language String No
city city String No
province province String No
country country String No
headimgurl headimgurl String No
subscribe_time subscribe_time Timestamp No

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Messages

Request

In order to send incoming/out-going sms/mms to Botanalytics, make a POSTcall tohttps://botanalytics.co/api/v1/twilio/sms/messages/

Example

            curl  "https://botanalytics.co/api/v1/twilio/sms/messages/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
      "is_sender_bot": true,
      "message": {
          "timestamp":1477860920000,
          "body": "Hey Jenny why aren't you returning my calls?",
          "to": "+14159978453",
          "from": "+14158141829",
          "media_urls": [],


          "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
          "api_version": "2008-08-01",
          "date_created": "Mon, 16 Aug 2010 03:45:01 +0000",
          "date_sent": "Mon, 16 Aug 2010 03:45:03 +0000",
          "date_updated": "Mon, 16 Aug 2010 03:45:03 +0000",
          "direction": "outbound-api",
          "price": "-0.02000",
          "sid": "SM800f449d0399ed014aae2bcc0cc2f2ec",
          "status": "sent",
          "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM800f449d0399ed014aae2bcc0cc2f2ec.json"
      }
}'            

           

Fields

Field Name Description Type Required
is_sender_bot Simply set to true If message is send by your bot, and false If not Boolean Yes
message message object Yes

message object

Field Name Description Type Required
timestamp Timestamp of the message Timestamp Yes
body Message body String body or/and media_urls must be set
to From number String Yes
from To number String Yes
media_urls Media urls String body or/and media_urls must be set
account_sid account_sid String No
api_version api_version String No
date_created date_created String No
date_sent date_sent String No
date_updated date_updated String No
direction direction String No
price price String No
sid sid String No
status status String No
uri uri String No

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Messages

Request

We use Viber's message structure, when you receive/send message simply make a POSTcall tohttps://botanalytics.co/api/v1/messages/viber/

Outgoing Message Example

            curl  "https://botanalytics.co/api/v1/messages/viber/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
        "message":
        {
           "auth_token": "4453b6ac1s345678-e02c5f12174805f9-daec9cbb5448c51r",
           "receiver": "01234567890A=",
           "sender":
           {
               "name": "yarden from the pa",
               "avatar": "http://avatar_url"
           },
           "tracking_data": "tracking data",
           "type": "text",
           "text": "a message from pa"
           "timestamp":1477860920000
        }
}'            

           

Fields

Field Name Description Type Required
message message parameter Yes

message parameter

Field Name Description Type Required
auth_token auth_token String No
receiver receiver String Yes
sender object sender String Yes
tracking_data tracking_data String No
type type String Yes
timestamp timestamp Timestamp Yes
text text String Depends on message type

sender object

Field Name Description Type Required
name name String Yes
avatar avatar String Yes

Incoming Message Example

            curl  "https://botanalytics.co/api/v1/messages/viber/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
        "message":
        {
           "event": "message",
           "timestamp": 1457764197627,
           "message_token": 4912661846655238145,
           "sender": {
               "id": "01234567890A=",
               "name": "yarden",
               "avatar": "http://avatar_url"
           },
           "message": {
               "type": "text",
               "text": "a message to the service",
               "media": "http://download_url",
               "location":{"lat": 50.76891, "lon": 6.11499},
               "contact":{"name":"Jorge","phone_number":"+14159646622"},
               "tracking_data": "tracking data"
           }
        }
}'            

           

Fields

Field Name Description Type Required
message message parameter Yes

message parameter

Field Name Description Type Required
event event String Yes
timestamp timestamp Timestamp Yes
message_token message_token String No
sender sender object Yes
message message object Yes

sender object

Field Name Description Type Required
id id String Yes
name name String Yes
avatar avatar String Yes

message object

Field Name Description Type Required
type type String Yes
text text String
media media String
location location location object
contact contact contact object
tracking_data tracking_data String No

location object

Field Name Description Type Required
lat lat Decimal Yes
lon lon Decimal Yes

contact object

Field Name Description Type Required
name name String Yes
phone_number phone_number String Yes

User Profile

Request

We use Viber's user details structure, when you receive user detail simply make a POSTcall tohttps://botanalytics.co/api/v1/viber/users/

Example

            curl  "https://botanalytics.co/api/v1/viber/users/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
       "id": "01234567890A=",
       "name": "yarden",
       "avatar": "http://avatar_url",
       "country": "IL",
       "language": "en",
       "primary_device_os": "android 7.1",
       "api_version": 1,
       "viber_version": "6.5.0"
}'            

           

Fields

Field Name Description Type Required
id id String Yes
name name String Yes
avatar avatar String No
country country String No
language language String No
primary_device_os primary_device_os String No
api_version api_version String No
viber_version viber_version String No

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Messages

Request

In order to send incoming messages to Botanalytics, make a POSTcall tohttps://botanalytics.co/api/v1/messages/user/google-assistant/

You'll just need to add timestamp inside API.AI's or Actions SDK's requestBody for the incoming messages

Incoming API.AI Message Example

         
curl  "https://botanalytics.co/api/v1/messages/user/google-assistant/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d
'{
	"message": {
	  "id": "209eefa7-adb5-4d03-a8b9-9f7ae68a0c11",
          "timestamp": 1481576685000,
	  "result": {
	    "source": "agent",
	    "resolvedQuery": "Hi, my name is Sam!",
	    "action": "greetings",
	    "actionIncomplete": false,
	    "parameters": {
	      "user_name": "Sam"
	    },
	    "contexts": [
	      {
	        "name": "greetings",
	        "parameters": {
	          "user_name": "Sam",
	          "user_name.original": "Sam!"
	        },
	        "lifespan": 5
	      }
	    ],
	    "metadata": {
	      "intentId": "373a354b-c15a-4a60-ac9d-a9f2aee76cb4",
	      "webhookUsed": "true",
	      "intentName": "greetings"
	    },
	    "fulfillment": {
	      "speech": "Nice to meet you, Sam!"
	    },
	    "score": 1
	  },
	  "originalRequest": {
	    "data": {
	       "user": {
	           "user_id": "VENL5NurhEq+JMFkrLwKRvH8tqY/xR9CsASCzuol874="
	       },
	       "conversation": {
	           "conversation_id": "1481574797415",
	           "type": 1
	       },
	       "inputs": [
	           {
	               "intent": "assistant.intent.action.MAIN",
	               "raw_inputs": [
	                   {
	                       "input_type": 2,
	                       "query": "Hi, my name is Sam!"
	                   }
	               ],
	               "arguments": []
	           }
	       ]
	   }
	  },
	  "status": {
	    "code": 200,
	    "errorType": "success"
	  },
	  "sessionId": "37151f7c-a409-48b8-9890-cd980cd2548e"
	}
}'             

Incoming Google Actions SDK Message Example

         
curl  "https://botanalytics.co/api/v1/messages/user/google-assistant/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d
'{
    "message":  {
	   "timestamp": 1481576685000,
       "user": {
           "user_id": "VENL5NurhEq+JMFkrLwKRvH8tqY/xR9CsASCzuol874="
       },
       "conversation": {
           "conversation_id": "1481574797415",
           "type": 1
       },
       "inputs": [
           {
               "intent": "assistant.intent.action.MAIN",
               "raw_inputs": [
                   {
                       "input_type": 2,
                       "query": "Hi, my name is Sam!"
                   }
               ],
               "arguments": []
           }
       ]
   }
}'             

Request

In order to send out-going messages to Botanalytics, make a POSTcall tohttps://botanalytics.co/api/v1/messages/bot/google-assistant/

API.AI/Actions SDK Outgoing Message Example

         
curl  "https://botanalytics.co/api/v1/messages/bot/google-assistant/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d
'{
       "user": {
           "user_id": "VENL5NurhEq+JMFkrLwKRvH8tqY/xR9CsASCzuol874="
       },
       "conversation": {
           "conversation_id": "1481574797415"
        },
        "message":  {
           "timestamp": 1481576688000,
           "expect_user_response": false,
           "is_ssml": false,
           "speech": "Hi there cutty"
       }
}'             

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Messages

Request

We use Kik's message structure, when you receive/send message simply make a POSTcall tohttps://botanalytics.co/api/v1/messages/kik/

Outgoing Message Example

            curl  "https://botanalytics.co/api/v1/messages/kik/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
        "messages":[
            {
              "body": "bar",
              "to": "laura",
              "type": "text",
              "chatId": "b3be3bc15dbe59931666c06290abd944aaa769bb2ecaaf859bfb65678880afab",
              "timestamp": 1439576628405
          },
          {
               "chatId": "b3be3bc15dbe59931666c06290abd944aaa769bb2ecaaf859bfb65678880afab",
               "type": "picture",
               "to": "laura",
               "picUrl": "http://mybucket.s3.amazonaws.com/mypic.jpg",
               "timestamp": 1439576628405
          }
        ]
}'            

           

Fields

Field Name Description Type Required
messages parameter message object Yes

message object

Field Name Description Type Required
chatId chatId String No
type type String Yes
to to String Yes
from from String from or to must be set
to to String Yes
body body string Depends on message type
timestamp timestamp of the message timestamp No

Incoming Message Example

            curl  "https://botanalytics.co/api/v1/messages/kik/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
      "messages": [
            {
              "chatId": "0ee6d46753bfa6ac2f089149959363f3f59ae62b10cba89cc426490ce38ea92d",
              "id": "0115efde-e54b-43d5-873a-5fef7adc69fd",
              "type": "text",
              "from": "laura",
              "participants": ["laura"],
              "body": "omg r u real?",
              "timestamp": 1439576628405,
              "readReceiptRequested": true,
              "mention": null
          },
          {
              "chatId": "0ee6d46753bfa6ac2f089149959363f3f59ae62b10cba89cc426490ce38ea92d",
              "id": "74ded818-1eb7-4266-91bc-c301c2f41fe3",
              "type": "picture",
              "from": "aleem",
              "participants": ["aleem"],
              "picUrl": "http://example.kik.com/apicture.jpg",
              "timestamp": 1439576628405,
              "readReceiptRequested": true,
              "mention": null
          }
      ]
}'            

           

Fields

Field Name Description Type Required
messages parameter message object Yes

message object

Field Name Description Type Required
chatId chatId String No
id id String No
type type of the message String Yes
from from String Yes
participants participants String Array No
timestamp timestamp of the message timestamp Yes
readReceiptRequested readReceiptRequested Boolean No
mention mention String No
body body of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
picUrl picUrl of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
url url of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
videoUrl videoUrl of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
data data of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
stickerUrl stickerUrl of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
isTyping isTyping of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
messageIds messageIds of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type
picked picked of the message String body,picUrl,url,videoUrl,data,stickerUrl,isTyping,messageIds,picked one of these must be set depends on message type

User Profile

Request

We use Kik's user profile structure, when you receive user detail simply make a POSTcall tohttps://botanalytics.co/api/v1/kik/users/

Example

            curl  "https://botanalytics.co/api/v1/kik/users/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
    "username": "joe",
    "firstName": "Joe",
    "lastName": "User",
    "profilePicUrl": "http://profilepics.kik.com/foobar.jpg"
}'            

           

Fields

Field Name Description Type Required
username username String Yes
firstName firstName String Yes
lastName lastName String Yes
profilePicUrl profilePicUrl String No

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Smooch Integration

On Smooch

1-Log in to select (or create) the app you want to connect to Botanalytics
2-Click on the “Settings” tab
3-Create a “Secret Key” that you’ll use to authenticate your bot. (If not created before)
4-Note the Key ID and Secret

On Botanalytics

As soon as you sign up to Botanalytics, please select smooch as your platform on integration page.

then you’ll be asked your SMOOCH_KEY_ID and SMOOCH_SECRET

After you save the details of your Smooch bot, you’are all set. We’ll be receiving data from your bot.

Note: Please make sure that you've saved your smooch creadentials and being shown the information pop up below.

Botanalytics provides an npm package for microsoft bot framework support

We natively support all the platforms microsoft bot framework supports

Installation

Add botanalytics-microsoftbotframework-middleware to your package.json

$ npm install botanalytics-microsoftbotframework-middleware

Usage

Register your bot with Botanalytics. Once you registered, please find your token at the integration page or navigate to Settings to see your token.

Set the following environment variable with the Token respectively.

BOTANALYTICS_TOKEN=your-botanalytics-token

Require botanalytics-microsoftbotframework-middleware and use the middleware in your bot like so:

// Initialize the middleware
var BotanalyticsMiddleware = require('botanalytics-microsoftbotframework-middleware').BotanalyticsMiddleware({
  token: process.env.BOTANALYTICS_TOKEN
});

// Initialize the connector and the bot
var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);

// Use the middleware
bot.use(
  {
    receive: BotanalyticsMiddleware.receive,
    send: BotanalyticsMiddleware.send
  }
);

License

MIT License.

Source

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)

Messages

Request

We use Line's message structure, when you receive/send message simply make a POSTcall tohttps://botanalytics.co/api/v1/messages/line/

Outgoing Message Example

            curl  "https://botanalytics.co/api/v1/messages/line/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
         "to": "U206d25c2ea6bd87c17655609a1c37cb8",
         "timestamp": 1462629479859,
         "messages":[
                {
                    "type": "text",
                    "text": "Hello, world"
                },{
                    "type": "image",
                    "originalContentUrl": "https://example.com/original.jpg",
                    "previewImageUrl": "https://example.com/preview.jpg"
                }
         ]

}'            

           

Fields

Field Name Description Type Required
to ID of the receiver String Yes
timestamp timestamp Timestamp Yes
messages Array of send message objects message object Yes

message object

Field Name Description Type Required
type type String Yes
text String Depends on message type

Incoming Message Example

          curl  "https://botanalytics.co/api/v1/messages/line/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
         "events": [
            {
              "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
              "type": "message",
              "timestamp": 1462629479859,
              "source": {
                "type": "user",
                "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
              },
              "message": {
                "id": "325708",
                "type": "text",
                "text": "Hello, world"
              }
            },
            {
              "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
              "type": "follow",
              "timestamp": 1462629479859,
              "source": {
                "type": "user",
                "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
              }
            }
         ]
}'            

           

Fields

Field Name Description Type Required
events Array of webhook event objects event object Yes

message object

Field Name Description Type Required
replyToken replyToken String Yes
type type String Yes
timestamp timestamp Timestamp Yes
source source source object Yes

source object

Field Name Description Type Required
type type String Yes
userId userId String Yes

User Profile

Request

We use Line's profile structure, when you receive user profile simply make a POSTcall tohttps://botanalytics.co/api/v1/line/users/

Example

            curl  "https://botanalytics.co/api/v1/line/users/" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token botanalytics_token' \
-d '{
       "displayName":"LINE taro",
       "userId":"Uxxxxxxxxxxxxxx...",
       "pictureUrl":"http://obs.line-apps.com/...",
       "statusMessage":"Hello, LINE!"
}'            

           

Fields

Field Name Description Type Required
displayName displayName String Yes
userId userId String Yes
pictureUrl pictureUrl String No
statusMessage statusMessage String No

Response Meanings

Response Code Meaning
200 OK – Everything worked as expected.
400 Bad Request – The request was unacceptable, often due to missing a required parameter.
401 Unauthorized – Your api token is wrong
404 Not Found – The requested resource doesn't exist.
500, 502, 503, 504 Server Errors – Something went wrong on Botanalytics's end. Try again later. (These are rare.)