Building a COVID-19 Chatbot powered by SAP BTP (Part 3/4): Creating a Chatbot with SAP Conversational AI
This article is the third of a four-part blog post series by Tim Huse and me. We met in the 2021 Career Starter Program and together we took the opportunity to discover and work with the latest technologies as part of the SAP Innovator Challenge 2021.
Together, we developed a COVID-19 chatbot (Vyri) as a solution to keep users updated regarding regulations, news, and statistics about the current pandemic. In this series, we will present our chatbot solution, which we implemented based on SAP Business Technology Platform (SAP BTP) components. The goal of the blogposts is to share our personal experience with the SAP BTP solution portfolio and its integration.
This third blog post, “Building a COVID-19 Chatbot powered by SAP BTP (Part 3/4): Creating a Chatbot with SAP Conversational AI”, is intended to give an overview on how to set up a chatbot with SAP Conversational AI and which integration options exist. If you are interested in our chatbot solution, we can recommend you to read our other blog articles, in which we look at use cases and specifically discuss the other key elements of the solution’s IT architecture.
The other articles in this series can be accessed here:
- Setting the stage (Part 1/4)
- Accelerating Data Transformation and Governance with SAP Data Intelligence (Part 2/4)
- Data Modeling and Advanced Analytics with SAP Data Warehouse Cloud and SAP Analytics Cloud (Part 4/4)
What is SAP Conversational AI?
SAP Conversational AI is an end-to-end, low code chatbot building platform and the conversational AI layer of SAP Business Technology Platform. The platform is a collection of natural language processing services and enables the creation of conversational interfaces for various enterprise use cases. The solution is hosted in the cloud, allowing one or more people to work on the chatbot at the same time. SAP Conversational AI makes it possible to build, train, connect and monitor powerful chatbots in one interface. Basically, the life of a chatbot can be divided according to the previously mentioned four capabilities. For this reason, the blog post is also based on this structure:
- Train: The bot must be taught what it needs to understand.
- Build: The skills of the bot and their triggers must be created so that a flow of conversation can subsequently be established.
- Connect: To make the chatbot available on one or several messaging platforms.
- Monitor: To check if the bot is understanding user inputs correctly. Monitoring also shows what users want so the chatbot can be enhanced accordingly.
More information about SAP Conversational AI can be found on the official product website.
Creating intents is one of the first things we did when creating our chatbot, as each intent represent an idea that our bot can understand. Most of the intents we used were created by us, since no similar use cases have been created in the past. However, some of the intents were also “forked”, meaning we used an intent that was already created by someone and cloned it into our chatbot. This is possible because SAP Conversational AI is collaborative.
In the next step, we created expressions for each intent. Expressions are sentences that the chatbot can understand. For this some manual effort was required, since all possible expressions that a user might use to communicate a specific intent must be included. There is also the possibility for uploading an csv. file, since we did not have one, we created all the expressions manually. A golden rule would be to add at least 30 expressions here. You can’t think of enough at the beginning? Don’t worry, just look at the monitor function described a few agenda points below. There you can review what users are writing and add those to your intents and expressions.
It is important to make sure that the expressions for the intents are distinct enough to avoid misunderstanding. First, we had some issues with the intents “get-covid-news” (providing the latest news about COVID-19) and “rki-data” (providing the latest COVID-19 numbers from the Robert Koch Institute), as the expressions have been too similar.
Entities, Values and Enrichment
When the chatbot can understand the user’s intent, it is also important to tag necessary information out of the user’s expression. It is not essential that you tag everything in the expression, but it is important to annotate what really needs to be extracted. This is working by entities, which are thus the keywords in an expression.
There are golden entities that are automatically determined by the SAP Conversational AI platform when a particular keyword is appropriate to describe that entity (such as date, time or location). In this blogpost we will focus on the custom entities depending on our bot’s context. To enable our chatbot to identify the respective county in questions about e.g., COVID-19 numbers, we needed to create the entity #Landkreis (German for county). In our example we used a restricted custom entity, as we have a strict list of words to detect. No word can be recognized as an entity if it doesn’t appear in a closed list of values. Which brings us to the next point, values. After creating the entity, we had to create values for this entity, that enabled our chatbot to recognize the entity. In other words, we added a list of German counties as values for the entity #Landkreis. Whenever a county is found to be part of a conversation the entity is recognized and could be used to trigger a specific skill of the chatbot, but if the user doesn’t ask about a county in the list, the bot asks to try other counties.
For the matching strictness we selected 80, that means a detected entity with a confidence score strictly greater than 0.8 is kept and returned. With a strictness of 100, a word must exactly match a value in the list to be recognized as such. At 80, we also allow misspellings.
Moreover, we enriched the entity #Landkreis, as we have assigned a key per county, which is also used in our tables in SAP Data Intelligence and for an API request described below. Since we can have multiple entities for a county all referencing to one county (e.g., Munich, München, Munchen), we mapped them to one unique ID.
At this stage, the chatbot knows how to understand the users who talk to it. The next step was to give the chatbot some skills to respond to the user’s intents. Each skill created represents one action that the bot knows how to do. In our use case we have used two types of skills. The green ones are business skills, they reflect the core purpose of the bot. The yellow ones are floating skills, they complete the bots core business skills by e.g., small talk.
First, the skill must be triggered. For this we had to store the appropriate intent. When the chatbot detects an expression that matches an intent, the corresponding skill is triggered. The example in the screenshot below show, that for the skill “get-rki-data” the intent “rki-data” must be identified first.
Now when the skill is triggered, there are some other necessary prerequisites. As mentioned in the entity section, some information must be provided by the user, so that the bot can respond to the user’s intent. The example below shows the “get-rki-data” skill. Here we selected the #Landkreis entity as a requirement and entered landkreis as the memory variable. In SAP Conversational AI, requirements are information that need to be present in the memory before actions for the skill can be executed. In other words, no information about COVID-19 numbers if the user does not specify a #Landkreis entity.
Finally, the API call remains, which is necessary for the chatbot to return up-to-date data from multiple data sources as well. We used the Consume API Service option that is used when there is a need to call an API service and capture the results out of this request to be used in other actions like messages. If a request is sent to the API, the returned JSON is returned in an API service response variable, which then can be used in other actions. With the API service, we connected to our SAP Data Intelligence pipelines, e.g., the pipeline to the Robert Koch Institute, describe in our previous blog.
We are still in the “get-rki-data” skill. In the screenshot below you can see, that we set the HTTP method to GET, because we want to get data from the API service. We used the script syntax to append the county to the URL. Also, here you can see the previous mentioned Object ID.
The county is in memory because the memory contains all the required entities that we added to the skills in the section before. Using the memory, any conversation with the user can be made more interactive by replying with personalized messages. The memory is persistent throughout the chat unless it is updated or reset. Using the passing Object ID, we are now accessing the corresponding data set for the county via the API of our SAP Data Intelligence pipeline.
For the ease of maintenance and usability, we stored the path of the specific table fields in a memory variable that we can then easily access instead of going through the entire response structure in the chatbot. To access the memory variables, it is necessary to enclose the reference with curly brackets.
These memory fields can then be used in a response structure to create the chatbot response. Many different formats are supported, enabling us to build a great user experience for our bot. You can choose between text, list, image, buttons, carousel, card, custom, client data and quick replies. For a more detailed explanation of the different answer types, we can recommend the SAP Help Portal. Most of the time we used Text as the message type of the response. The corresponding memory fields are then filled with the related data from the API, as you can see in the screenshot below. When creating text messages, we used markdown to format text in bold, italics or as a hyperlink. To do this, you must select the Enable rich text for this message check box. If you have integrated your bot with a third-party integration option, the message type will automatically be adapted to the channel, so the look and feel will probably be slightly different from what you see on SAP Conversational AI platform. We have to say that sometimes this works well and sometimes not so well. For example, in the skill “get-covid-news” we have an output of the three latest news as a list. In Microsoft Teams on the laptop, the display of the list turned out much better graphically than in Telegram on the cell phone, which is perhaps related to the screen size.
One of the issues we faced in our use case was that sometimes the chatbot did not receive a response from the API and the chatbot did not give an error message, but simply did not give a response. If this happens to you, check first if your pipelines are running in SAP Data Intelligence. If that is the case, but you still don’t get a response from your chatbot, you should check if SAP Conversational AI is currently available.
I would also like to use a few more sentences for our “routing-skill”. We always faced some issues when using Quick Replies as message type. Whenever we selected one of the buttons, the output or fallback did not work properly. For example, the correct skill was executed, but then the “show actions” skill was executed again.
That’s why we created the “routing-skill” within this, we build the response and fallback structure. where we build the answer or the fallback structure. If you have a similar problem with your fallbacks, you should try this as well.
SAP Conversational AI is offering several third-party integration options. Because we wanted to make our solution available on a variety of devices inside and outside of SAP, our solution is available through our SAP Analytics Cloud Dashboard, Microsoft Teams and in Telegram (just search for “Vyri” in our Telegram app and test our chatbot yourself).
In this tutorial it is well explained how to connect your SAP Conversational AI with Microsoft Teams. The main prerequisites are creating an (trial) account at Microsoft Azure and an Azure bot channel. SAP colleagues may need to create a new account with a new email address as we have had some issues using the SAP-User. When you are using the Azure tenant from SAP, the internal IT blocks some functions because otherwise resources (and thus costs) would be uncontrollable. That’s why we created a new trial account and created our Azure bot channel with an F0 Free pricing tier.
For the connection of SAP Conversational AI and Telegram we can recommend this blog to you. The connection to SAP Analytics Cloud will be described in our next blogpost.
In our pilot phase, we used the monitoring features for two main purposes. First, we used the log feed to identify potential weaknesses and new skills for our chatbot.
Furthermore, we used conversation logs to solve problems with solution experts to a later point of time. In this context, we used the debug information to see which intent was detected and which entities are extracted at each step of the conversation. This can help you better understand how the chatbot works and further improve its performance.
As shown in this blog post, the SAP Conversational AI platform provides a user-friendly interface and easy to use functions to build a chatbot solution. In combination with other solutions of the SAP Business technology platform, powerful use cases can be implemented via API services.
This blog post is not meant to be a complete overview of all the features and capabilities that SAP Conversational AI offers. Rather, the focus was to present the implementation of our chatbot solution and why we have chosen the respective implementation form among other possibilities. Furthermore, it should help you to avoid mistakes we made or to solve problems.
Thank you for reading! We hope you find this post helpful and will also read the other posts in our blogpost series. For any questions or feedback just leave a comment below this post.
Sebastian & Tim
Find more information and related blog posts on the topic page for SAP Conversational AI.
If you have questions about SAP Data Intelligence you can submit them in the Q&A area for SAP Conversational AI in the SAP Community.