Understanding External Requests
External requests are your chatbot’s means of communicating with other software or services on the internet. It enables your chatbot to retrieve information from these services or share information with them seamlessly. Essentially, it’s your chatbot’s way of asking questions or exchanging information with the broader digital world. The External Request feature enables interaction with external services, APIs (Application Programming Interfaces), or websites to retrieve data or perform actions. It allows you to fetch data from any other system and present it to the user within your Chatbot.Types of External Requests
There are two main types of external requests: HTTP GET and HTTP POST, each serving distinct purposes. Let’s delve into these types and understand when to employ each:HTTP GET
Purpose: The HTTP GET request is used to retrieve data from a specified resource without altering or modifying it. It is primarily used for fetching information.
Use Cases:
Use Cases:
- Retrieving data from a public API, like weather information or news headlines.
- Fetching a user’s profile by passing their username in the URL.
- Accessing web pages or resources in a web browser by clicking links.
HTTP POST
Purpose: The HTTP POST request is used to submit data to be processed to a specified resource. It is primarily used for sending data and creating or updating resources on the server.
Use Cases:
Use Cases:
- Submitting a form on a website to create a new user account.
- Uploading a file to a server.
- Sending data to an API to update a user’s preferences.
Setting up the External Request
On the Flow Builder, add Actions > External API Request.
How to save data to a custom field?
You can use Response Mapping to save data from an API to a Custom Field If the API returns data in JSON format. Many times you may want to get data from an API and show the data to the user. For example, we will use a currency exchange API to show how you could save the data returned from an API to a custom field. Below is the response from the API.- Custom Field and Response Mapping: You can store the data from the API response in a custom field, acting as a storage space. Once stored, you can later use this custom field in your chatbot’s conversation flow to display the information to the user.
- Dynamic Contents: Alternatively, the API can be configured to provide messages or content directly suitable for display within your chatbot. This implies that the API response includes text or information ready for presentation to the user without additional processing.
How to get the HTTP status code or the whole response body?
In response mapping, you can use the following elements to work with the API response:http_status_code: This element allows you to capture the HTTP status code from the API response. It tells you whether the API request was successful or encountered an error. You can save this status code into a custom field for further processing.http_response_body: This element allows you to capture the entire response body from the API. It contains the data or content sent back by the API, which you can also save into a custom field if you want to use it later in your chatbot’s conversation.http_download_EXTENSION: If you need to download a specific type of file, you can use this element. For example, if you want to download an audio file in MP3 format, you would usehttp_download_mp3.
Dynamic Content
Dynamic content in your chatbot empowers you to generate and display content directly from your server, ensuring compatibility across all communication channels. The system automatically adapts the content to the appropriate format for the user’s channel in real-time. However, a crucial limitation exists: You can only employ the Dynamic Content feature if you own and manage the API providing the data. If you lack control over the API, you can still work with its data by saving it into a Custom Field using Response Mapping. Subsequently, you can display that data to the user in your chatbot’s flow using the Custom Field. The response format for Dynamic Content typically looks like this:Sending more than a single message
Sending a Gallery
Sending a gallery is like sending a collection of cards. You can include up to 10 cards in a gallery. For each card in the gallery, you can also add a button.Sending messages supported only by WhatsApp
WhatsApp supports various message types that aren’t compatible with Messenger bots, including List, Contacts, Locations, or Catalogs Messages. However, with Chatbot Builder, you can send any message type supported by WhatsApp. You just need to use the message structure outlined in WhatsApp’s documentation, and Chatbot Builder will handle the “To” parameter automatically for you.Actions
The “Actions” field is optional, meaning you don’t have to include it. Actions allow you to do things like adding or removing tags, setting or unsetting custom fields, and sending a flow. Add Tagsjson_encode function to transform your actions object into a string representation.
