Connect your chatbot to an API

Consumes HTTP resources

It consumes HTTP resources from SHIMLI streams, using an API that returns responses in JSON format.

  1. Prerequisites: You need an account with an active SHIMLI instance and an API that returns responses in JSON format. The example uses a free API called SWAPI to access Star Wars data.
  2. User Interaction: Through WhatsApp, the user receives a list of options to query, such as Star Wars characters, planets and spaceships. This is done through a message type control with lists.
  3. Wait for User Response: A "Wait for a response" type control is used to wait for the user's response and store it in a variable during the flow.
  4. Response Processing: A "Branch" type control filters and compares the user's response to determine the flow of the conversation.
  5. Use of the Fetch Variables Control: This control allows you to make calls to an API and store the server's response in variables.
  6. Response to User: If the response from the server is successful, a message with buttons is sent to the user, showing the number of characters and allowing to select for more information.
  7. Character Information Query: When a character is selected, the API is queried with the selected character code, and the API responds with all the character's characteristics in JSON format.
  8. Information Storage: Information is stored in variables with the same name as in the JSON object, accessing only properties at the root of the object.
  9. End Flow: An "End Flow" control is added to indicate that the conversation has ended.
  10. Testing the Flow: Finally, the flow is tested by starting a conversation in WhatsApp with the instance connected to SHIMLI, selecting the characters option and receiving the corresponding information.