Consume API Services and Call Webhooks from Your Chatbot
- How to call an API from your chatbot
- How to call a webhook from your chatbot
Prerequisites
- You understand the basics of creating a chatbot, as described in the tutorial Build Your First Chatbot with SAP Conversational AI.
In this tutorial, you will create a simple chatbot to check if the user entered an animal or a location or both: if an animal, the chatbot will display a “fun fact” about the animal by calling an API; if a location, the chatbot will display a Google map by calling a webhook.
-
The Consume API Service option is used when you need to call an API service and capture the results to be used in other actions like messages or other API calls. You can send any body content you want, and the returned JSON is returned in the
api_service_response
variable, which you can then use in other actions. -
The Call Webhook option is used when you need to create more complex middleware. By default, the entire conversation context JSON is sent (for POST requests), and the webhook must return JSON in the format that can be displayed in the chatbot UI (see Getting Response Using Webhook). The next tutorial in this group will show you how to create your own webhook designed to be called from a chatbot.
From a feature point of view, the 2 ways of calling an API are the same except:
A webhook is automatically sent the conversation context JSON (for POST requests) by default.
A webhook must return JSON that conforms to the SAP Conversational AI UI protocol.
For more information on making calls from your chatbot, see Connect to External Service.