Application API
The Application API empowers you to interact with a bot constructed within the Kindly Platform, bypassing the need for Kindly's native widget. This functionality facilitates enhanced integration with third-party services. By managing communication through your backend, you can for example seamlessly display chat content within your custom-designed user interface.
Getting started
New application
To start using the Application API with your bot, you first need to let us know about your application.
- From the dashboard of your Kindly bot, go to Connect -> Application -> New Application.
- Enter a descriptive name for your application.
- Add a webhook URL where the answers from Kindly will be POSTed at.
- Click Create application.
- You will now see a new API Key, which will act as your bearer token when interacting with the Kindly system.
Authorization
With the API key in hand, you're ready to start integrating Kindly into your application.
Every request should include the header Authorization: Bearer {{API_KEY}}.
Webhook
Every answer from Kindly to your Application API requests will be POSTed at the webhook URL you provided. This URL can be edited also afterwards.
Important params: user_id and market
As you'll see below, you want to use user_id and market properly:
- Consider user_id as the identifier for your conversation. New conversation -> new user_id.
- If your Workspace supports multiple Markets, you want to specify which market slug you want your conversations to start on. If not, we'll default to a random market in your Workspace. You can ignore the parameter if you don't have multiple markets, altough we suggest to use it if you plan in the future to make use of them.
Sending and receiving
Sending message
To chat with the bot POST a message to https://bot.kindly.ai/api/v1/send.
The POST payload should be in the following format:
{
"user_id": "{{unique-user-id}}",
"message": "{{message}}",
"language_code": "{{language-code}}",
"market": "{{market}}"
}language_code: is the two language code of the languages supported by your bot (both Live Translation and Managed languages). You can find the supported language codes here. For examples:
- English: en
- Spanish: es
- French: fr
- etc...
The response to the request will contain a unique id of the message. When the bot sends the reply to the message via webhook, this id will be found in the reply_to_id field of the reply payload.
{
"reply_to_id": "{{hexadecimal-id}}"
}Example:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}", "message": "Hello world!", "language_code": "en", "market": "{{market}}"}' \
https://bot.kindly.ai/api/v1/sendForcing a followup
Followup dialogues can in general only be triggered right after their parent dialogues. But there are cases when one wants to sidestep this limitation, mainly when using a quick reply button to trigger a followup. Normally the button would no longer work later in the chat, but this can be forced by including the id of the parent dialogue (i.e. the dialogue containing the button) in the payload under the name exchange_id. The id of a dialogue can be obtained from its URL in the platform.
For example, let's say the dialogue with id 9c0dd930-ca7c-4830-a901-7da5ebd3b6a6 has a quick reply button whose value is trigger_followup and it has a followup dialogue with sample or keyword trigger_followup. When the button is clicked the application could send the following payload:
{
"user_id": "{{unique-user-id}}",
"message": "trigger_followup",
"language_code": "en",
"exchange_id": "9c0dd930-ca7c-4830-a901-7da5ebd3b6a6",
"market": "{{market}}"
}Greet the user
You can also trigger the bot's greeting message with a POST to https://bot.kindly.ai/api/v1/greet
The POST payload is the same as when sending a regular message, but without a message:
{
"user_id": "{{unique-user-id}}",
"language_code": "{{language-code}}",
"market": "{{market}}"
}Example:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"user_id": "{{unique-user-id}}", "language_code": "{{language-code}}", "market":"{{market}}"}' \
https://bot.kindly.ai/api/v1/greetHandover request
If your user takes an action that should trigger a handover request, you can do this with a POST to https://bot.kindly.ai/api/v1/request_takeover
The POST payload should contain either a user_id or chat_id:
{
"user_id": "{{unique-user-id}}"
}or
{
"chat_id": "{{chat-id}}"
}Example:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}"}' \
https://bot.kindly.ai/api/v1/request_takeoverTrigger a defined dialogue
Instead of sending a reply defined by the webhook server, you can also trigger a dialogue that you have defined in the Kindly platform.
Examples:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}", "exchange_id": "{{dialogue-id}}", "market":"{{market}}"}' \
https://bot.kindly.ai/api/v1/triggeror
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}", "exchange_slug": "{{dialogue-slug}}", "market":"{{market}}"}' \
https://bot.kindly.ai/api/v1/triggerThe dialogue ID is a 128 bit hexadecimal UUID. You can find it on the page where you edit the dialogue.
The dialogue slug is an optional value picked by you that can be used in place of the dialogue UUID. You can set the dialogue slug on dialogues with the trigger type.
Receiving messages from the bot
Once the bot has a reply to the message, Kindly will POST the reply back to your application at the Webhook URL specified in getting started.
The POST payload from Kindly has the following format:
{
"exchange_id":"The unique id of the response",
"exchange_type":"Greeting, dialogue or fallback",
"user_id":"Unique user id",
"reply_to_id":"The chatmessage_id of the message being replied to",
"message":"Hello world!",
"buttons":[
{
"id":"The button id",
"type":"Type of button (possible values are 'quick_reply', 'link', 'email', 'phone')",
"label":"Label of button",
"value":"Message value when button is activated",
"exchange_id":"Exchange identifier",
"new_context":{
"key":"value",
"key2":2,
"key3":null
}
}
],
"image_carousel":[
{
"altText":"This is the image alt text",
"linkUrl":"https://example.com",
"imageUrl":"https://example.com/image.jpg",
"description":""
}
],
"form":{
"submit_dialogue_id":"The submit dialogue id",
"cancel_dialogue_id":"The cancel dialogue id",
"language_code": "Language code of the form",
"texts":{
"submit_button_text":"Send",
"cancel_button_text":"Cancel",
"cancel_text":"Form was exited",
"error_text":"An error occurred",
"unanswered_text":"Form was not answered"
},
"fields":[
{
"input_type": "Type of input (e.g., 'TEXT', 'EMAIL', 'NUMBER', 'RANGE', 'SELECT', 'CHECKBOX', 'RADIO', 'FILE')",
"required":false,
"order":0,
"slug":"Slug for the field",
"texts":{
"label":"Label for the field",
"placeholder_text":"Placeholder text for the field"
}
}
],
"submission_id":"Unique identifier for the form submission"
}
}Context
You can also read and write to the chat session's context memory with your API requests. See the context documentation for more information.
Write to context
You can write to context without sending a message to the user. Use a POST request to https://bot.kindly.ai/api/v1/set_context
The POST payload should be in the following format:
{
"user_id": "{{unique-user-id}}",
"context": { "purchase_flow_complete": true }
}The response to the request will contain a reference to the chat that was updated.
{
"chat_id": "{{chat-id}}"
}Example:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}", "context": { "purchase_flow_complete": true }' \
https://bot.kindly.ai/api/v1/set_context
To clear the context completely, you can supply an empty object context: {}. You can also write to context when sending a message or triggering a greeting. Examples:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}", "message": "Hello world!", "language_code": "en", "new_context": { "purchase_flow_complete": true }}' \
https://bot.kindly.ai/api/v1/sendcurl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}", "new_context": { "purchase_flow_complete": true }}' \
https://bot.kindly.ai/api/v1/greetSubmitting a Form
You can send the results of a form by making a POST to https://bot.kindly.ai/api/v1/form/submit
The POST payload should be in the following format:
{
"user_id": "{{unique-user-id}}",
"submission_id": "{{form-submission-id}}",
"context": {
"{{slug-field}}": "{{selected-slug}}"
},
"state": "{{form-state}}"
}- submission_id: The ID associated with the form submission.
- context: Represents the selected form field, including the user's input or selection.
- state: Indicates the current state of the form results. Possible states include:
- ACTIVE
- UNANSWERED
- SUBMITTED
- CANCELED
- ERRORED
Upon successful submission, the response will be structured as follows:
{
"form_submission_id": "{{form-submissi-id}}",
"form_id": "{{form-id}}",
"state": "{{form-state}}",
"updated_context": {
"_name": "{{api-name}}",
"_organization_name": "{{org-name}}",
"{{slug-field}}": "{{selected-slug}}"
}
}Privacy
Deleting all chats for user
You can delete all chats for a specific user by making a DELETE request to https://bot.kindly.ai/api/v1/privacy/delete
The POST payload should be in the following format:
{
"user_id": "{{unique-user-id}}"
}Upon successful submission, the response will be structured as follows:
[
{
"deletedMessages": {{quantity-of-deleted-messages}},
"deletedFormSubmissions": {{quantity-of-deleted-form-submissions}},
"deletedChat": "{{id of the chat}}"
},
{
...
}
]Example:
curl -H 'Content-Type: application/json' \
-H "Authorization: Bearer {{your-api-key}}" \
-d '{"user_id": "{{unique-user-id}}"}' \
-X DELETE \
https://bot.kindly.ai/api/v1/privacy/deleteApplication API vs. Webhooks
At first glance, the Application API and webhooks might look more or less the same. There is, however, a significant difference.
While webhooks let Kindly POST to a predefined URL, the response possibilities are limited. A webhook is not able to send multiple replies to Kindly. Furthermore, it's not possible for a webhook to send a message to Kindly without being triggered to do so. Using the application API you can do just that.