API Requests and Responses - Response Callback and Response Callback Message

Response Callback and Response Callback Message are also utilized for making an API call to a specific endpoint, but allow you to effectively manage the API response, making them the preferred choices in most cases compared to Callback and Callback Message. The actual API call is defined under Callback Profiles, so only the Callback ID should be added in the Response Callback field. The Prompt field should be left blank to avoid sending any message to the end user as part of this follow-up question. On the other hand, the Response Callback Message, which acts as a replacement for user input, allows you to define the text that you want the Chatbot to store in the variable specified under Key Name. This text can be static or derived from data received in the API response, accessible through angle brackets notation < >.

Routes can then be used to split the flow into multiple branches (including one for managing API error scenarios) based on the value of the API response saved under Key Name.

For example:

  1. Chatbot first asks the end user to provide a ZIP code, which is saved in a zip_code variable.
  2. Once the ZIP code is provided by the user, the next follow-up question is triggered. In this follow-up question, we include the Callback ID in the Response Callback field to execute an API call to an external endpoint. This call involves sending the user's ZIP code to obtain the corresponding country information. The returned country can be accessed by adding <data.country> in the Response Callback Message field, which is then stored in the country variable defined under Key Name.

📘

Note:

The screenshot displays the Callback ID as a static text. In a real situation, you'll need to supply the actual Callback ID, which can be obtained from the Callback Profile page.

  1. You can then route the flow to the appropriate intent based on the country returned by the API. In this case, the flow is structured as follows:
    1. If the country is Italy, the Italy intent is triggered.
    2. If the country is France, the France intent is triggered.
    3. If the country is any other country, the Catch All intent is triggered. This can be achieved by using the 'default' keyword as the Key. If this Route is not defined and the API call returns a value that does not match any of the Route Keys, the Final Retry message will be sent and the end user will exit the intent. The Retry message should not be provided if Response Callback is used.
    4. If the API returns an error, the Error intent is triggered. We always recommend defining a route to handle API failure scenarios, which can be accomplished by adding 'Failure sending message' as one of the keys in the Routes.

You can then retrieve data stored in variables set with Key Name or Saved States using curly braces ❴key name❵. In the provided example, utilizing ❴country❵ within the prompt of a subsequent follow-up question will grant access to the country variable set in this question.

How to access Chatbot variables when configuring a Callback Profile?
Callback Profiles are used to configure the actual API call that the bot needs to perform. When configuring a callback profile, you can access any Chatbot variable in the query parameters or in the request body by using the angle brackets notation <>. For instance, if you intend to perform a GET API call and pass the value of a Chatbot variable named “zip_code” in a query parameter also named “zip_code”, you can update as follows: https://endpoint.com?zip_code=<zip_code>.