Application API
The Application API empowers you to interact with a bot constructed within the Kindly Platform, bypassing the need for Kindly's native Chat UI. 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.
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, expand Connect in the navigation menu and click Application.
- Click New application.
- Enter a descriptive name for your application. You can also add your custom webhook, which is optional.
- Click Create application.
- You will now see a new API Key, which will act as your bearer token when interacting with the Text Predict API.
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>
As previously mentioned, you can add a webhook to your application integration. You can also add or change the webhook URL after you created the application integration.
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:
language_code: is the two letter language code of your bot. This is the ISO 639-1 format of your bots language. 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.
Example:
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:
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:
Example:
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:
or
Example:
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:
or
The 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.
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:
You can also read and write to the chat session's context memory with your API requests. See the context documentation for more information.
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:
The response to the request will contain a reference to the chat that was updated.
Example:
To clear the context completely, you can supply an empty object context: {}.
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:
- 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:
To show an example of how to use the API, we've set up a live chat application using Docker, Node JS, socket.io and React that integrates with Kindly.
Check out the running demo.
View source code on Github.
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.