Bot Session API
  • 11 Jul 2022
  • 11 Minutes to read
  • Dark
    Light

Bot Session API

  • Dark
    Light

Article summary

Summary

Session

ChatbotSession Object

ChatbotSession Object is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
idGuidsessionId
channelstringe.g., Live Chat, Facebook Messenger, Twitter Direct Message, WeChat, WhatsApp, SMS, IVR
messageChatbotMessage Object
contextChatbotSessionContext Object

ChatbotSessionContext Object

ChatbotSessionContext Object is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
chatbotIdGuidchatbotId
currentIntentIdGuid
chatbotResponseIdGuid
authenticationstringauthentication data
locationstringthe longitude and latitude of the location, e.g. "-39.900000,116.300000"
formValuesFieldValue[]an array of FieldValue objects
isFormSubmittedboolfalse
consecutiveTimesOfPossibleAnswersint0
invalidInputTimesint0
latestMessageChatbotMessage Object
customDataObjectCustom data

FieldValue Object

FieldValue is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
namestringthe name of a field in a form.
valuestringthe value of a field.

ChatbotMessage Object

ChatbotMessage Object is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
idGuidthe unique id of the response
messagesListMessageData
disableChatInputAreaboolfalseOnly available when channel is Live Chat.
smartTriggerActionsSmartTriggerAction[]an array of SmartTriggerAction objects.
intentIdGuidid of the matched intent
intentNamestringname of the matched intent
scorefloatthe score of the intent matched, the value is beteween 0.0 and 100.0

MessageData Object is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
typeenumtype of the response,including chatbotActionSendMessage,chatbotActionQuickReplychatbotActionSendImagechatbotSendVideochatbotActionSSOLoginButton,chatbotActionCollectLocation, chatbotCollectCompany, chatbotCollectEmail, chatbotCollectName, chatbotActionCollectPhoneNumber, chatbotActionCollectComment,chatbotActionCollectVariableData,chatbotActionBookMeeting,chatbotActionTransferChat,chatbotActionGotoTaskbot
contentobjectresponse's content. when type is chatbotActionSendMessage, it represents SendMessage; when type is chatbotActionQuickReply,it represents QuickReply;when type is chatbotActionSendImage,it represents SendImage;when type is chatbotActionSendVideo,it represents SendVideo; when type is chatbotActionSSOLoginButton, it represents SSOLoginButton;when type is chatbotActionCollectLocation, it represents CollectLocation;when type is chatbotActionCollectCompany, it represents CollectCompany;when type is chatbotActionCollectEmail, it represents CollectEmail;when type is chatbotActionCollectName, it represents CollectName;when type is chatbotActionCollectPhoneNumber, it represents CollectPhoneNumber;when type is chatbotActionCollectComment, it represents CollectComment;when type is chatbotActionCollectVariableData, it represents CollectVariableData;when type is chatbotActionBookMeeting, it represents BookMeeting;when type is chatbotActionTransferChat, it represents TransferChat;when type is chatbotActionGotoTaskbot, it represents GotoTaskbot;

Smart Trigger Action Object

Smart Trigger Action is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
typeenumthe type of the action. enum:[sendNotification,autoMonitor,transferChat,changeAssignee,addToSegment]
isEnabledboolfalseif an action is enabled.
agentOfflineMessagestringagent offlineMessage prompt message
targetTypeenumthe trigger action target type. enum: department, agent, segment.
selectedDepartmentsGuid[]Only available when targetType is department.
selectedAgentsGuid[]Only available when targetType is agent.
segmentIdGuidOnly available when targetType is segment.

GreetingMessage Object

GreetingMessage is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
responsesChatbotResponse[]an array of ChatbotResponse object.

HighConfidenceAnswer Object

HighConfidenceAnswer is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
responsesChatbotResponse[]an array of ChatbotResponse object.

PossibleAnswer Object

PossibleAnswer is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
messagestringText of the Possible Answer message
audiostringbase64 string, convert the message text to speech
intentsIntentScore[]an array of IntentScore

IntentScore Object

IntentScore is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
idGuidid of the intent
namestringname of the intent
scorefloatthe score of the intent matched, value is between 0.0 and 100.0

NoAnswer Object

NoAnswer is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
messagestringtext of the No Answer message
audiostringbase64 string, convert the message text to speech
ifIncludeContactAgentOptionbool

AuthenticationRequest Object

AuthenticationRequest is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
signInMessagestringmessage of the sign in
audiostringbase64 string, convert the signInMessage text to speech
signInButtonTextstringtext of the sign in link
signInURLstringurl of the sign in

LocationRequest Object

LocationRequest is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
messagestringmessage of the sign in
buttonTextstringtext of the sign in link

Prompt Object

Prompt is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
questionstring
audiostringbase64 string, convert the signInMessage text to speech
optionsstring[]an array of string

FormRequest Object

FormRequest is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
messagestringA separate message which is sent before the button is sent.
titlestringwhen a button is sent to visitor, clicking this button will open a form that contains information bot wants to collect from the visitor. the title refers to the title of that form, and it is also placed on the button as a name.
isConfirmationRequiredboolwhether visitor needs to click confirm after filling out the information in a form.
fieldsField[]an array of Field Object
submitButtonTextstring
cancelButtonTextstring
confirmButtonTextstring

Field Object

Field is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
typeenumenums: text ,textArea,radio ,checkBox ,dropDownList ,checkBoxList,email type refers to the different kinds of fields which can be used in a form.
namestringa field’s name in a form.
defaultValuestringa field’s value
isRequiredboolto mark whether a field in a form is required or not.
isMaskedboolif this is true, visitor information will be masked with symbols in chat logs.
optionsstring[]an array of of string when the fieldType is radio ,dropDownList ,checkBoxList
orderintegermust greater than or equal 0, ascending sort

NotHelpfulMessage Object

NotHelpfulMessage is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
messagestringtext of the message
ifIncludeContactAgentOptionboolinclude Contact An Agent or not .

Chatbot Response Object

Response is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
typeenumenums: text ,htmlText ,button,quickReply ,image ,video ,ivrMenu ,transferCall .
contentobjectresponse's content. when type is text or htmlText, it represents Text Response; when type is image ,it represents ImageResponse;when type is video, the content is the video url, it represents string; when type is button,it represents ButtonResponse;when type is quickReply, it represents QuickReplyResponse; when type is ivrMenu, it represents IVRMenu Response;when type is transferCall, it represents TransferCall Response;
disableChatInputAreaboolfalseOnly available when channel is Live Chat.
delayTimedecimal1how many seconds delay to show

Text Response Object

Text Response is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
textstringstring
audiostringbase64 string, convert the text to speech

ImageResponse Object

Image is represented as simple flat JSON objects with the following keys:

NameTypeDefaultDescription
namestringname of the image
urlstringurl of the image

ButtonResponse Object

ButtonResponse is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
messagestringtext above buttons,this text will be sent before buttons.
buttonsButton[]an array of Button.

Button Object

Button is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
buttonTextstringtext on button.
typeenumenums contain triggerAnIntent,link and webView,type of buttons
linkUrlstringurl of the web page you want to open.
intentIdGuidid of the intent you choosed.
openInstringenums contain sideWindow,newWindow,currentWindow, it represents the way that a page will be opened.
openStylestringenums contain compact,tall and full,it represents the size of the webview that will be opened.

QuickReplyResponse

QuickReplyResponse is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
messagestringtext sent before quickreplys.
quickReplyItemsQuickReplyItem[]an array of QuickReplyItem.

QuickReplyItem Object

NameTypeDefaultDescription
typeenumenum values, triggerAnIntent,contactAnAgent
textstringtext of quickreply item .
intentIdGuidOnly available when type is triggerAnIntent.

IVRMenu Response Object

IVRMenu Response is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
messagestringThe message sent to visitor before the options.This message will be transferred to IVR and read to visitor
audiostringbase64 string, convert the message text to speech
invalidInputActionRepeatTimeintegerHow many times will this IVR Menu repeat if there is invalid input
keysIVRMenuKey[]The valid keys for visitor to choose options. the key contains: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, *, #. Each key can only be used once in an IVR menu. Visitor can press the key to choose the option.

IVRMenuKey Object

NameTypeDefaultDescription
keystringThe valid keys for visitor to choose options. the key contains: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, *, #. Each key can only be used once in an IVR menu. Visitor can press the key to choose the option.
textstringtext of quickreply item .
intentIdGuid

TransferCall Response Object

TransferCall Response is represented as simple flat json objects with the following keys:

NameTypeDefaultDescription
targetNumberstringphone number.

Endpoints

Create session

POST /chatbots/{chatbotId}/sessions

Parameters

Path parameters

NameTypeRequiredDescription
chatbotIdGuidyesthe unique id of the bot

Request body

The request body contains data with the follow structure:

NameTypeRequiredDefaultDescription
channelstringyeseg: Live Chat, Facebook Messenger, Twitter Direct Message, WeChat, WhatsApp, SMS, IVR
idGuidyesid of the session, you must generate the unique sessionId
contextChatbotSessionContext Objectno

example:

  {
    "channel":"IVR",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {   
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }

Response

the response is: ChatbotSession Object

Example

Using curl

curl -H "Content-Type: application/json" -d '{
    "channel":"IVR",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {   
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }' -X POST https://domain.comm100.com/chatbots/a9928d68-92e6-4487-a2e8-8234fc9d1f48/sessions

Response

  HTTP/1.1 200 OK
  Content-Type:  application/json

  {    
    "channel":"IVR",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    },
    "message":{
      "id":"d3f5b968-ad51-42af-b759-64c0afc40b84",
      "visitorQuestion":"",
      "type":"greetingMessage",
      "content":{
        "responses":[
          {
            "type":"text",
            "content": {
              "text":"Hi, I'm Peely, I'm glad to help you.",
              "audio":"UklGRrj2AQBXQVZFZm10IBAAAAABAAEAwF0AAIC7AAACABAAZGF0YZT2AQA..."
            }
          },
          {
            "type":"text",
            "content": {
              "text":"You can ask any questions. If you want to know what I can help with, you can say Menu or Options",
              "audio":"UklGRrj2AQBXQVZFZm10IBAAAAABAAEAwF0AAIC7AAACABAAZGF0YZT2AQA..."
            }
          }
        ]
      }
    }    
  }

Recieved Message

POST /sessions/{sessionId}:recieveMessage

Parameters

Path parameters

NameTypeRequiredDescription
sessionIdGuidyesid of the chat or conversation

Request body

The request body contains data with the follow structure:

NameTypeRequiredDefaultDescription
channelstringyeseg: Live Chat, Facebook Messenger, Twitter Direct Message, WeChat, WhatsApp, SMS, Voice
textInputstringnotext
contextChatbotSessionContext Objectyes

example:

  {
    "channel":"Facebook Messenger",
    "textInput":"i want to buy NBN",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    },
  }

Response

the response is: ChatbotSession Object

Example

Using curl

curl -H "Content-Type: application/json" -d '{
    "channel":"Facebook Messenger",
    "textInput":"i want to buy NBN",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    },
  }' -X POST https://domain.comm100.com/sessions/f9928d68-92e6-4487-a2e8-8234fc9d1f48:detectIntent

Response

  HTTP/1.1 200 OK
  Content-Type:  application/json

  {    
    "channel":"Facebook Messenger",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "currentIntentId": "8d6892e6-92e6-4487-a2e8-92e68d6892e6",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    },
    "message":{
      "id":"d3f5b968-ad51-42af-b759-64c0afc40b84",
      "visitorQuestion":"i want to buy NBN",
      "type":"highConfidenceAnswer",
      "content":{
        "intentId": "7534fdsca-92e6-4487-a2e8-92e68d6892e6",
        "intentName": "buy nbn",
        "score": 89.25,
        "responses":[
          {
            "type":"htmlText",
            "content": {
              "text":"<div>Hi, what can i do for you?</div>",
            }
          },
          {
            "type":"image",
            "content": {
              "name":"greeting.png",
              "url": "https://bot.comm100.com/botapi/images/greeting.png"
            }
          }
        ]
      }
    }    
  }

Trigger an intent

POST /sessions/{sessionId}:triggerAnIntent

Parameters

Path parameters

NameTypeRequiredDescription
sessionIdGuidyesid of the chat or conversation

Request body

The request body contains data with the follow structure:

NameTypeRequiredDefaultDescription
channelstringyeseg: Live Chat, Facebook Messenger, Twitter Direct Message, WeChat, WhatsApp, SMS
intentIdGuidyesid of the intent triggered
contextChatbotSessionContext Objectyes

example:

  {
    "channel":"Live Chat",
    "intentId":"8d6892e6-92e6-4487-a2e8-92e68d6892e6",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }

Response

the response is: ChatbotSession Object

Example

Using curl

curl -H "Content-Type: application/json" -d '{
    "channel":"Live Chat",
    "intentId":"8d6892e6-92e6-4487-a2e8-92e68d6892e6",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }' -X POST https://domain.comm100.com/sessions/f9928d68-92e6-4487-a2e8-8234fc9d1f48:triggerAnIntent

Response

  HTTP/1.1 200 OK
  Content-Type:  application/json

  {    
    "channel":"Live Chat",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "currentIntentId": "8d6892e6-92e6-4487-a2e8-92e68d6892e6",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    },
    "message":{
      "id":"d3f5b968-ad51-42af-b759-64c0afc40b84",
      "visitorQuestion":"Lost Card",
      "type":"authenticationRequest",
      "content":{
        "signInMessage": "Please Login",
        "signInButtonText": "Login",
        "signInURL": "https://domain.comm100.com/ssoidp/ssoLogin.aspx"  
      }
    }    
  }

Rate the bot answer as helpful or not helpful

POST /sessions/{sessionId}:rate

Parameters

Path parameters

NameTypeRequiredDescription
sessionIdGuidyesid of the chat or conversation

Request body

The request body contains data with the follow structure:

NameTypeRequiredDefaultDescription
channelstringyeseg: Live Chat, Facebook Messenger, Twitter Direct Message, WeChat, WhatsApp, SMS
chatbotMessageIdGuidyesthe id of the ChatbotMessage
typeenumyeshelpful or notHelpful
contextChatbotSessionContext Objectyes

example:

  {
    "channel":"Live Chat",
    "chatbotMessageId":"4487fc9d-92e6-4487-a2e8-92e68d6892e6",
    "type": "notHelpful",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }

Response

the response is: ChatbotSession Object

Example

  • Rate the bot as not helpful

    Using curl

curl -H "Content-Type: application/json" -d '{
    "channel":"Live Chat",
    "chatbotMessageId":"4487fc9d-92e6-4487-a2e8-92e68d6892e6",
    "type": "notHelpful",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }' -X POST https://domain.comm100.com/sessions/f9928d68-92e6-4487-a2e8-8234fc9d1f48:rate

Response

  HTTP/1.1 200 OK
  Content-Type:  application/json
  {    
    "channel":"Live Chat",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    },
    "message":{
      "id":"d3f5b968-ad51-42af-b759-64c0afc40b84",
      "visitorQuestion":"",
      "type":"notHelpfulMessage",
      "content":{
        "messageWhenNotHelpful":"I am sorry that this doesn't answer your question. Please click on following button to connect to an agent.",
        "ifIncludeContactAgentOptionWhenNotHelpful": true,
      },
      "smartTriggerActions":[
        {
          "type":"transfer", 
          "isEnabled": true,
          "targetType": "department",
          "selectedDepartments": ["sadwe21d-92e6-4487-a2e8-92e68d6892e6"] 
        }
      ]
    }    
  }  
  • Rate the bot as helpful

    Using curl

curl -H "Content-Type: application/json" -d '{
    "channel":"Live Chat",
    "chatbotMessageId":"4487fc9d-92e6-4487-a2e8-92e68d6892e6",
    "type": "helpful",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }
  }' -X POST https://domain.comm100.com/sessions/1487fc9d-92e6-4487-a2e8-92e68d6892e6:rate

Response

HTTP/1.1 200 OK
  Content-Type:  application/json
  {    
    "channel":"Live Chat",
    "id": "f9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "context": {
      "chatbotId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
      "customData": {
        "name":"Kart",
        "email":"kart@yahoo.com",
        "phone":"123-4355-212",
      }
    }       
  }

Was this article helpful?

What's Next