Webhook Channel API
Last updated
Was this helpful?
Last updated
Was this helpful?
Chatlayer.ai provides a REST JSON API to retrieve, create data and manipulate data from third party applications and a webhook configuration to notify you when a variety of interactions or events happen, including when a bot sends a message. Webhook events are sent by Chatlayer.ai as POST requests to your webhook.
This document describes what can be done, under which conditions and the expected input and output formats and communication mechanism.
Note that the API can easily be tested from any web browser, command line terminal or API development environment.
The Chatlayer.ai Webhook API is often used to integrate Chatlayer.ai into a mobile app.
Request must be done with https scheme. Depending on the environment, the API hostname will be:
All API paths are prefixed by /api.
You must provide an access token on each of your API calls. This access token can be created . For posting a webhook message the access token is not required and replaced by a verify token that you can configure in the bots settings in Chatlayer.ai together with the webhook configuration url.
A user id or sender id should have at least 32 characters.
We suppose you have an Chatlayer.ai bot instance accessible from the Chatlayer staging environment with bot id 11 and an access token with value bot22
.
To get all chat messages on the source accessible by the token’s users, you’ll need to build your request with access_token request query with proper value. The HTTP request will look like this:
All responses are formatted in JSON using utf-8 encoding. The returned content-type is : application/json; charset=utf-8. Here is an example:
Chatlayer.ai will retry sending the message 3 times upon receiving a failing HTTP code from your API.
GET
/api/bots/:botId/history/:senderId
This method gets the messages by senderId.
senderId
string
The id of the sender
botId
string
The id of your bot
access_token
string
offset
string
The amount of messages to skip
limit
string
The size of the results
GET
/api/sessionData/:botId/:senderId/:namespace
This method can be used to retrieve user session data from a namespace. A namespace is used to save your session data into. You can use this data for interpolation of session variable values in messages, API requests, etc.
access_token
string
botId
string
The bot ID you want to send the message to
senderId
string
The user's sender ID
namespace
string
The namespace of the variables to get
Chatlayer.ai provides:
a Webhook message API endpoint to send a user message to the bot
POST
/api/webhookMessage/:botId
This method sends a user message to the bot. The user message can be a simple text message or a button payload object which represents the state data when a user clicks the button or quick reply. The bot messages that come as a response will be sent to your webhook URL. The button payload is available in the messages received from the bot.
botId
string
locale
string
ISO 2 letter language code (en, nl, fr, de, ...)
verifyToken
string
The webhook verify token you should configure in the webhook configuration of the bot settings in Chatlayer.ai.
sender
object
The Sender Object
text
string
The user text message
Sender object:
Property
Value
Description
id
string
The user identifier which can be used to identify the user when receiving a bot response on the webhook.
Request format for button click
Text stringified object:
Property
Value
Description
params
array with key/value objects
The key - value configuration settings of the button/quick reply. This data will be saved in to the user session state data when he clicks this button or quick reply.
nextDialogstateId
string
The dialog state to which the user will be navigated after the button/quick reply click
type
string
UI component type (button or quick reply)
caption
string
The button/quick reply caption
Add a new channel type webhook in your channel configuration in Chatayer.
Configure both settings
Webhook URL: this URL must either be publicly available, or at least available from Chatlayer.ai’s IP range. We strongly advise to use HTTPS for this endpoint
Verify token: This can be any arbitrary string, but it is recommended to be chosen randomly.
POST
customer webhook endpoint URL configured in Chatlayer.ai
string
POST
/api/webview
This endpoint can be used to trigger a dialog state, send messages or save session data asynchronously. A typical use case is an action based on the triggering of a custom component.Note that for the request to succeed you will have to include either:
botId
string
The bot ID
senderId
string
The user identifier
session
object
Use this to add data to the user session.
action
object
Use this parameter to include a nextDialogstate ID to define where the flow should go next.
messages
array
The bot message object. The object structure depends on the message type. See appendix for all message structures.
POST
/api/bots/:botId/extract/:version
This endpoint may be used to fetch an NLP result for a single expression. This NLP extract contains your matched intents, entities and their performance scores.Expect the in- and output of this endpoint to change in the future. Existing fields will remain the same but we reserve the right to add new fields at our discretion.
botId
string
Your bot's unique ID
version
string
The version to extract NLP data from. This value can contain DRAFT or LIVE.
access_token
string
The API access token
language
string
The language to use, in lowercase 2-letter notation.
expression
string
The expression to gather an NLP result for
This is an Chatlayer.ai Enterprise or Corporate feature. Please contact your Chatlayer.ai sales representative before using this API endpoint.
Chatlayer.ai bot message send to the customer webhook endpoint URL and returned as response of a user messages can have different object structures depending on the message type. This section describes the different message type object structures.
A text message includes a simple bot text message.
Request format:
Property
Value
Description
text
string
The user test message.
A button template includes a simple bot text message and an array of button objects.
Request format:
Message object for button template:
Property
Value
Description
attachment
object
The attachment object.
Attachment object:
Property
Value
Description
type
string
The attachment type (template)
payload
object
The attachment payload object. The object structure depends of the attachment type
Attachment payload object:
Property
Value
Description
template_type
string
The template type (button)
text
string (optional)
The text above the buttons ( only for a button template type)
buttons
array
An array of button objects
Button object:
Property
Value
Description
type
string
The button type (web_url - postback - phone_numberl - element_share)
title
string
The button caption
payload
object (type postback) or string (type phone_number) - optional
The button payload. Only for postback type buttons.
url
string - optional
The button url. Only for url type buttons
Button payload object:
Property
Value
Description
params
array with key/value objects
The key - value configuration settings of the button. This data will be saved in to the user session state data when he clicks this button.
nextDialogstateId
string
The dialog state to which the user will be navigated after the button click
type
string
UI component type (button)
caption
string
The button caption
A quick reply message includes a simple bot text message and an array of quick reply objects.
Request format:
Message object for quick replies:
Property
Value
Description
text
string
The text before the quick replies.
quick_replies
array
An array of quick reply objects
Quick reply object:
Property
Value
Description
content_type
string
The quick reply content type (text)
title
string
The button caption
payload
object
The quick reply payload
Quick reply payload object:
Property
Value
Description
params
array with key/value objects
The key - value configuration settings of the quick reply. This data will be saved in to the user session state data when the user clicks this quick reply.
nextDialogstateId
string
The dialog state to which the user will be navigated after the quick reply click
type
string
UI component type ( quickreply)
caption
string
The button/quick reply caption
A generic template (carousel) includes a list of generic template elements. The generic template element is a simple structured message that includes a title, subtitle, image, and up to three buttons
Request format:
Message object for generic template:
Property
Value
Description
attachment
object
The attachment object.
Attachment object:
Property
Value
Description
type
string
The attachment type (template)
payload
object
The attachment payload object. The object structure depends of the attachment type
Attachment payload object:
Property
Value
Description
template_type
string
The template type (generic)
elements
array
An array of generic template elements (carousel cards)
Generic template element object:
Property
Value
Description
title
string
The carousel card title
subtitle
string
The carousel card subtitle
image_url
string
The carousel card image
item_url
string
The carousel card url. When the user clicks the image the web page opens in a new browser tab.
buttons
array
An array of button objects
Button object:
Property
Value
Description
type
string
The button type (web_url - postback - phone_numberl - element share)
title
string
The button caption
payload
object (type postback) or string (type phone_number) - optional
The button payload. Only for postback type buttons.
url
string - optional
The button url. Only for url type buttons
Button payload object:
Property
Value
Description
params
array with key/value objects
The key - value configuration settings of the button. This data will be saved in to the user session state data when he clicks this button or quick reply.
nextDialogstateId
string
The dialog state to which the user will be navigated after the button/quick reply click
type
string
UI component type (button or quick reply)
caption
string
The button/quick reply caption
The list template is a list of 2-4 structured items with an optional global button rendered at the bottom. Each item may contain a thumbnail image, title, subtitle, and one button. You may also specify a default_action object that sets a URL that will be opened when the item is tapped.
Request format:
Message object for list template:
Property
Value
Description
attachment
object
The attachment object.
Attachment object:
Property
Value
Description
type
string
The attachment type (template)
payload
object
The attachment payload object. The object structure depends of the attachment type
Attachment payload object:
Property
Value
Description
template_type
string
The template type (list)
elements
array
An array of list element
buttons
array
An array of general list button objects
List template element object:
Property
Value
Description
title
string
The carousel card title
subtitle
string
The carousel card subtitle
image_url
string
The carousel card image
default_action
object
The default action when the user taps the list item.
buttons
array
An array of list item button objects
Default action object:
Property
Value
Description
type
string
The action type (web_url)
url
string
The action ur. When the user taps the list element this web page will open in a new browser tab.
Button object:
Property
Value
Description
type
string
The button type (web_url - postback - phone_numberl - element share)
title
string
The button caption
payload
object (type postback) or string (type phone_number) - optional
The button payload. Only for postback type buttons.
url
string - optional
The button url. Only for url type buttons
Button payload object:
Property
Value
Description
params
array with key/value objects
The key - value configuration settings of the button. This data will be saved in to the user session state data when he clicks this button or quick reply.
nextDialogstateId
string
The dialog state to which the user will be navigated after the button/quick reply click
type
string
UI component type (button or quick reply)
caption
string
The button/quick reply caption
An attachment represents a file such as images and video.
Request format:
Message object for attachment:
Property
Value
Description
attachment
object
The attachment object.
Attachment object:
Property
Value
Description
type
string
The attachment type (image-video)
payload
object
The attachment payload object. The object structure depends of the attachment type
Attachment payload object:
Property
Value
Description
url
string
The attachment url
Chatlayer.ai provides custom component development for your channels. Please contact your project manager to discuss further integration.
a Webhook configuration to be notified when bot messages are returned as response to a user messages sent to the webhook message API as described in . This API is almost realtime and the purpose is to be able to trigger event-based behavior as soon as a bot message response occurs . This way you will be able to integrate the bot flow logic in your own application or message channel.
The overall mechanism is loosely based on Pubsub protocol , and rely on HTTP request containing the bot message response being sent to a consumer Endpoint URL. The customer webhook Endpoint URL can be configured in Chatlayer.ai as described in .