APIs

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.

Getting started

New application

To start using the Application API with your bot, you first need to let us know about your application.

  1. From the dashboard of your Kindly bot, expand Connect in the navigation menu and click Application.
  2. Click New application.
  3. Enter a descriptive name for your application. You can also add your custom webhook, which is optional.
  4. Click Create application.
  5. You will now see a new API Key, which will act as your bearer token when interacting with the Text Predict API.

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

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.

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:

JSON


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.

JSON


Example:

Shell


Forcing 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:

JSON


Make the bot say hello

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:

JSON


Example:

Shell


Handover 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:

JSON


or

JSON


Example:

Shell


Trigger 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:

Shell


or

Shell


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.

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:

JSON


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:

JSON


The response to the request will contain a reference to the chat that was updated.

JSON


Example:

Shell


To clear the context completely, you can supply an empty object context: {}.

Submitting 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:

JSON

  • 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:

JSON


Try a working example

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.

Application 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.