How to consume API service in an SAP Conversational AI Chatbot

Earlier I have shown you how easy it is to create a FAQ chatbot in 5 minutes. In this blog, I will show you how to use an API service to connect to an external system from a chatbot.

There are two ways to connect to an external system – Webhooks and API service. To make it super easy, I am going to use SAP Conversational AI trial and a sample API Service available on the internet. The sample service provides the total number of covid cases by country.

So, let’s start building!

Create a project

1. Click on New BOT.

2. Choose Perform Actions.

3. Give a name for your bot. Ex. consumeapi

4. Choose Data Policy as Non-personal and Non-vulnerable. Then, choose Bot Visibility as Private and click on Create A BOT.

Create Intent

An intent is a set of expressions that mean the same thing. Intents are central to your bot’s understanding. Each one of your intents represents an idea that your bot is able to understand.

1. Click on +Create button. Enter intent as “help”. Then, click on Create Intent.

2. Enter an expression, Ex. “I need some help” and press Enter.

Create Entity

An entity is a keyword that is extracted from an expression. For example if “US” is defined as an entity then, from the text “Covid Cases US”, US can be extracted from it and use it as a query to API service.

1. In the Entity tab click on Create an Entity button. Then, add an entity called countrycodes>Restricted entity>Create.

2. Click on the custom entity #COUNTRYCODES.

3. Add country codes US, IN, SA etc. It will be auto-saved.

Create a Skill

1. In the Build tab>click on Create skill>Give name as answer. Then, click on “answer”.

2. Under Triggers tab enter condition as given below. It means that the skill will be triggered only if the intent @help is present.

3. Click on Requirements tab and provide information as given below.

Note that the value of “countrycode” will be used by API service to filter the response.

4. Click on Actions tab>Add Message Group. Then, click on Connect External Service>Consume API Service.

5. Define the condition “If #countrycodes is-present” as given below.

Define the method as GET and enter the URL: https://api.thevirustracker.com/free-api?countryTotal={{memory.countrycode.raw}}

Click on Save.

6. In order to show the response from API service click on Send Message button.

7. Choose Text. Then, enter {{api_service_response.default.body.countrydata.0.total_cases}}

Click on Save.

8. Click on Update Converstation>Reset Conversation. It will reset the memory, otherwise, it will keep using the old entity/keyword.

9. Click on Save.

Chat with Your Bot

Click on Chat with Your Bot button and enter text to get the response from API service. API service is giving response after extracting keywords(US, IN) from the text.

Learn from this blog how to integrate this chatbot with other applications.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.