How to consume API service in an SAP Conversational AI Chatbot

In my previous blog you’ve learned how to build a chat bot in 5 minutes. In this blog, you will learn how to use an API service to connect to an external system from a chatbot.

Why API service? When you are building a chatbot for a real-time use case the systems you need to connect to – access, modify, delete data. You need the chatbot to connect with 3rd party systems. These systems are connected via API service.

There are two ways to connect to an external system – Webhooks and API service. To make it easy, I am going to use SAP Conversational AI trial and this sample API Service. We are going to use this sample service in the chatbot to get 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 an Intent

An intent is a set of expressions that means 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. Click on the Intent “help” that you created.

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

Create an 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 as a query to API service.

1. On 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. Click on Build tab> Create skill> Give name as answer.

2. Click on “answer”.

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

4. Click on Requirements tab and provide information as given below. Then, press Enter.

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

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

6. Click on “ADD CONDITION to trigger messages” and define the condition “If #countrycodes is-present” as given below.

7. Define the method as GET and enter the URL:{{memory.countrycode.raw}}

Click on Save.

7. Click on “Choose Message Type“. Then, choose Text. And, enter {{api_service_response.default.body.countrydata.0.total_cases}}

Click on Save.

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

10. Click on Save.

Are You Ready to Chat with Your Bot?

Click on Chat Preview button and enter text to get the response from API service. API service is giving a 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.