Bot Message API
  • 21 Mar 2024
  • 5 Minutes to read
  • Dark
    Light

Bot Message API

  • Dark
    Light

Article summary

Summary

  • Chatbot Message API. Use this API to send messages to Comm100 Live Chat channel while bot chatting

Only work in Comm100 Live Chat Channel

- session

Authentication

API_key Authentication

For each method call, you must use your email and API_KEY.Authentication to the API is done via HTTP Basic Auth. Provide your email as the basic auth username and API_KEY as the password. You must authenticate for API requests.

Session

  • POST /api/v3/bot/sessions/{sessionId}:sendMessage - Send Message

ChatbotMessage

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

NameTypeMandatoryDescription
typeenumyesit is a enum value with options: text,image,video, quickreply, button, intent.
contentobjectyesresponse's content.
when type is text, it represents TextResponse;
when type is image,it represents ImageResponse;
when type is video, it represents VideoResponse;
when type is quickreply, it represents QuickReplyResponse;
when type is button, it represents ButtonResponse;
when type is intent, it represents IntentId or intent name;
disableChatInputAreaboolnodefault value is false
delayTimedecimal1how many seconds delay to show

TextResponse

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

NameTypeMandatoryDescription
messagestringyesmessage of the response
linksarray of linkyeslinks in the text

Link

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

NameTypeMandatoryDescription
typeenumyesit is an enum value with options: hyperlink
startPositionintyesstart index of text which contains link info
endPositionintyesend index of text which contains link info
urlstringnourl of the web resource,including web forms,articles,images,video,etc. When the type is hyperlink, it is mandatory, otherwise not
ifPushPageboolnoauto open url in the side window
openInenumnoit is an enum value with options: currentWindow,sideWindow and newWindow. This field defined the way that webpage will be opened.

ImageResponse

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

NameTypeMandatoryDescription
descriptionstringyesdescription of the image, it will be displayed as the alternative text of the image
urlstringyesurl of the image

VideoResponse

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

NameTypeMandatoryDescription
urlstringyesurl of the video

QuickReplyResponse

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

NameTypeMandatoryDescription
messagestringyesmessage of the response
itemsarray of QuickReplyItemyes

QuickReplyItem

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

NameTypeMandatoryDescription
typeenumyesit is an enum value with options: goToIntent, contactAgent and text
textstringyestext on quick reply
intentIdGUIDnoid of the intent which current quickreply point to. When the type is goToIntent, it is mandatory, otherwise not
intentNamestringnoname of the intent which current quickreply point to. It will only take effect if intentId is empty or not set.

ButtonResponse

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

NameTypeMandatoryDescription
messagestringyesmessage of the response
itemsarray of ButtonItemyes

ButtonItem

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

NameTypeMandatoryDescription
typeenumyesit is an enum value with options: hyperlink,webview and goToIntent
textstringyestext on button
urlstringnourl of the web resource,including web forms,articles,images,video,etc. When the type is hyperlink or webview, it is mandatory, otherwise not
intentIdGUIDnoid of the intent which current button point to. When the type is goToIntent, it is mandatory, otherwise not
intentNamestringnoname of the intent which current button point to. It will only take effect if intentId is empty or not set.
openInenumnoit is an enum value with options: currentWindow,sideWindow and newWindow. This field defined the way that webpage will be opened. When the type is hyperlink, it is mandatory, otherwise not
webviewOpenStyleenumnoit is an enum value with options: compact, tall and full. This field defined the way that webview will be opened. When the type is webview, it is mandatory, otherwise not

Endpoints

Send Message

POST /api/v3/bot/sessions/{sessionId}:sendMessage

Parameters

Path parameters

NameTypeRequiredDescription
sessionIdGuidyesid of the chat

Query String

NameTypeRequiredDescription
siteIdintyesid of the site

Request body

The request body contains data with the follow structure:

NameTypeRequiredDefaultDescription
botIdGuidyesid of the chatbot
visitorIdGuidyesid of the visitor
intentIdGuidnoid of the intent
messagesChatbotMessage[]yesmax 10 messages in the list and only 1 quickreply type message in the list

example:

  {
    "botId": "44f88d68-92e6-4487-a2e8-8234fc9d1f48",
    "visitorId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "messages": [
        {
            "type": "text",
            "content": {
                "message": "this is a plain message"
            },
            "disableChatInputArea": true
        },
    ]
  }

Response

HTTP/1.1 204 No Content

Example

Using curl

curl -H "Authorization: Basic test@comm100.com:e07cce30b1b145e99049bf201f302239"
-H "Content-Type: application/json" -d '{
    "botId": "44f88d68-92e6-4487-a2e8-8234fc9d1f48",
    "visitorId": "a9928d68-92e6-4487-a2e8-8234fc9d1f48",
    "messages": [
        {
            "type": "text",
            "content": {
                "message": "this is a plain message"
            },
            "disableChatInputArea": true
        },
    ]
  }' -X POST https://api2.comm100.io/botapi/api/v3/bot/sessions/f9928d68-92e6-4487-a2e8-8234fc9d1f48:sendMessage?siteId=10000

Response

  HTTP/1.1 204 No Content
  Content-Type:  application/json
  

ChatbotMessage List Sample Json

 [
      {
          "type": "text",
          "content": {
              "message": "this is a plain message"
          },
          "disableChatInputArea": true
      },
      {
          "type": "text",
          "content": {
              "message": "this is a web link message",
              "link": [{
                  "type": "hypelink",// hypelink
                  "startPosition": 10,
                  "endPosition": 17,
                  "ifPushPage": true,
                  "url": "www.test.com",
                  "openIn": "sideWindow"// currentWindow, sideWindow or newWindow.
              }]
          },
          "disableChatInputArea": true
      },        
      {
          "type": "image",
          "content": {
              "description": "description of the image",
              "url": "www.test.com/test-image.jpg"
          },
          "disableChatInputArea": true
      },
      {
          "type": "video",
          "content": {
              "url": "www.test.com/test-video.jpg"
          },
          "disableChatInputArea": true
      },        
      {
          "type": "button",
          "content": {
              "message": "this is a button response",
              "items": [
                  {
                      "type": "goToIntent",// goToIntent, hyperlink or webview.
                      "text": "click to trigger test-intent-name",
                      "intentId": "00000000-0000-0000-0000-000000001111"
                  },
                  {
                      "type": "hyperlink",
                      "text": "click to open this url in web page",
                      "url": "www.test.com",
                      "openIn": "currentWindow"
                  },
                  {
                      "type": "webview",
                      "text": "click to open this url in web view",
                      "url": "www.test.com",
                      "webviewOpenStyle": "full"
                  }
              ]
          },
          "disableChatInputArea": true
      }, {
          "type": "quickreply",
          "content": {
              "message": "this is a quick reply response",
              "items": [
                  {
                      "type": "goToIntent",// goToIntent, contactAgent or text.
                      "text": "click to trigger test-intent-name",
                      "intentId": "00000000-0000-0000-0000-000000001111"
                  },
                  {
                      "type": "goToIntent",// goToIntent, contactAgent or text.
                      "text": "Go to main menu",
                      "intentName": "main menu"
                  },
                  {
                      "type": "contactAgent",
                      "text": "click to contact agent"
                  }
              ]
          },
          "disableChatInputArea": true
      },
  ]

Was this article helpful?