Create an Action

Learn how to create human-like action-taking abilities for your Chatbot

  1. On the Bot's settings page, click on [Actions] from the left hand side menu.
  2. Click [Add Actions]

  1. Enter the Action Title. Enter a concise and descriptive name for your new ability. For example, "Cancel Order" or "Book a Ticket." This reference helps you identify the ability later.

  1. Select Type of Action. You have two types of abilities you can add:
    • a custom API or
    • a knowledge base

  1. Click [Next]

  1. Provide a Description. In the "Description" field, explain what the ability does. For example, "This API helps with cancelling the order" or "this API helps with booking a ticket" This description helps you and others understand the purpose of the ability at a glance.


Add a Custom APIs

Adding new actions can significantly improve the user experience by automating processes such as ticket booking, data retrieval, and more.

1. List Inputs

List out all the necessary inputs that your API needs to be triggered successfully.

  1. Click on "Add Input"

  2. Select an input type and define parameters:

    • String: This input type is used for text-based data. For example, you might have an input called "destination" for an airline ticket booking API.
    • Number: This input type is used for numerical data. For example, you might have an input called "number of tickets" to specify how many tickets are being booked.
    • Boolean: This input type is used for true/false values. For example, you might have an input called "is child" to indicate if the ticket is for a child.
    • Enum: This input type is used for predefined options. For example, you might have an input called "class" with options like "economy," "business," and "premium economy."


Example for Booking Tickets:

NameTypeDescription
destinationStringThe destination for the ticket booking.
number of ticketsNumberThe number of tickets to be booked.
is childBooleanIndicates if the ticket is for a child.
classEnumThe class of the ticket.
Options: economy, business, premium economy

  • The AI will gather these inputs either from the previous conversation context or by asking relevant questions to the user. This ensures that all necessary information is collected before triggering the API.
  • For example, if the user has already mentioned the destination in a previous conversation, the AI will use that information. If not, it will prompt the user to provide the destination.

2. Make Custom API

To ensure that the chatbot can correctly send requests and receive responses from the external system, define the API Endpoint by specifying the URL and method type for the API your chatbot will interact with.

  1. Paste the URL: Enter your API's URL in the "URL" field.
  2. Select the Method Type: POST, GET, PUT, PATCH, DELETE.

3. Authentication

Authentication ensures that only authorized users can access the API, providing an additional layer of security. Select the type of authentication required for your API:

  • None: Choose this if your API is public and does not require any authentication.
  • API Key: If your API requires an API key, select this option then enter the API key in the provided field, then select the authentication type:
    • Basic Auth: This type of authentication requires a username and password. The credentials are encoded and sent in the request header.
    • Bearer Token: This method uses a token that is sent in the authorization header. The token is usually prefixed with the word "Bearer".
    • Custom Auth: If your API requires a custom authentication method, you can specify the custom header and its value.



4. Header Key

The header key allows you to add custom headers to your API requests. These headers can be used for various purposes, such as identifying the source of the request or passing additional information required by the API.

  • You can add any constant type headers that your API requires.
  • For example, you might want to add a header to identify that the request is coming from Botsonic. You could add a header like "x-from" with a static value of "botsonic-chatbot". This helps you recognize on your end that the request is coming from Botsonic.



5. Pick Outputs

Pick specific outputs from the API response that you want to expose to the chatbot. Instead of using all the data returned by the API, you can choose only the relevant pieces of information. This helps in filtering out unnecessary information and focusing only on what is relevant.

For example, if your ticket booking API returns 20 different parameters, but you only need the ticket URL, you can specify that using a JMESPath.

  1. Enter parameter key: Choose the specific outputs you want to expose.
  2. Configure JMESPath: Use JMESPath to filter and extract the desired data from the API response. For example, if you only need the ticket URL, you can configure a JMESPath to extract just that. To learn more, go to https://jmespath.org/



6. Configure Response Caching

Response caching helps optimize the number of requests made to your API by storing the response for a specified duration. This is particularly useful for APIs where the response does not change frequently within a chat session.

Example Scenario: Imagine you have an API that provides flight details. The flight details for a specific flight number are unlikely to change within a short period. By caching the response, you can avoid making multiple API calls for the same flight details within a single chat session, thereby reducing the load on your API and improving performance.

Select a caching option:

  • No Cache: The API response is not cached. Every time the API is called, a new request is made, and a fresh response is fetched. This is suitable for APIs where the response data changes frequently and needs to be up-to-date with every request.
  • Till End of Session: The API response is cached for the duration of the chat session. Once the response is cached, subsequent requests within the same session will use the cached response instead of making a new API call. This is ideal for APIs where the response data remains consistent within a chat session. For example, flight details, weather information, or static content that does not change frequently.



Add a Knowledge Base

This type of Action allows the bot to find answers from a restricted set of documents. You can add sources like PDFs, Word documents, text files, or even a website URL.