Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member207000
Participant
COVID-19 pandemic has accelerated the shift towards a more digital world, every kind of business is moving to the online world, be it a small size, medium, or large enterprise. Every industry making its presence online, Finance/Banking, Healthcare, Travel, Education, Legal, HR, Real Estate, Media, E-commerce, Government because you want to know the status of your request, product/food delivery status, a complaint about faulty product or service, help in course enrollment, airport virtual assistant, getting health/car insurance quotes, etc. All these results in a huge spike in calls to service centers and they are unable to cope with this situation due to staff shortage, pandemic situation, which results in a bad customer experience. And intelligent technology seems the only cost-effective answer to many of the problems.

The world is now conversational, and AI-based chatbots have proven effective at delivering high-quality customer and employee experiences. SAP Conversational AI is an end-to-end chatbot platform to build enterprise-ready chatbots with AI technology from SAP. By deploying conversational interfaces embedded into SAP and non-SAP solutions, you can manage business tasks more smoothly and create a better user experience. Smart chatbots allow customers to get immediate responses to their questions, and employees to access the internal resources they need.

In this article, we'll create a news chatbot with SAP Conversational AI, which will provide news headlines based on the user's interest, recognize the user's reaction, and react accordingly, calls an API to get the latest news headlines.

 

Create SAP Conversational AI account


Go to https://cai.tools.sap/, and click Sign Up in the upper-right corner.

Follow the instructions for creating an account.


 

Create a new bot project


Fill in the following details


 

There are 4 stages in a bot's life :



 

  • Train: Here you teach your boat to understand what is expected. Here you will create intents – ideas your bot will recognize – using expressions that the bot should recognize coming from the user.

  • Build: At this stage, you give your boat the ability to meet these expectations, by giving the skills it can perform. Here you will create skills – things your bot can do – and define when they will be triggered. Your skills are defined by triggersrequirements (information your bot must collect), and actions.

  • Connect: Making your boat live to available platforms.

  • Monitor: Train your bot to make it sharper, and get insights on its usage.


 

Train


In the training phase, we build intents. Intents are things which means telling bot what is intended. Within an intent, we indicate all the possible expressions that a person might use to communicate that intent.

Go to Train tab --> Search for @news-selector intent


Click Fork for the @news-selector intent.

There are many existing intents and you can select or you can create your own based on your requirement


Explore the intent by clicking on it.

In the intent we forked, there are around 150 expressions to discern if someone wants to be told the news interest.

From the Add an expression field you can add expressions if you are creating new intent or update the existing intent with new ones.


 

Create an entity for news type


Our bot must be able to extract the type of news from within the conversation. Such data extracted from a conversation is defined as entities. Here you'll create entity news-type.


Click on the #news-type entity and open it to explore. Here you will see the values of our custom entity tagged in your intent.  ( To tag the values you need to goto intent and then under the expression list edit the expression, then select the keyword you want to tag. )


 

 

Create a second intent @news-interest, we are creating this intent to make our bot understand the user reactions.

You can simply search for @news-interest intent and Fork it to use in your project.



Build


Now that your bot knows how to understand people who talk to it, it’s time to give your robot some skills. Each skill represents a task/action that your bot will do to achieve what is intended from it.

Like human behavior, when a command is given to us, first we understand what is expected, and then based on certain conditions we evaluate and then perform some action.

Just like intents, you can create a skill from scratch or inherit skills from other bots you’ve created or from other people’s bots.

In our project, choose the predefined skill Greetings.

The Greetings skill – like all skills – has 4 tabs:

  • README.md: A description of the purpose of your skill

  • Triggers: The conditions that must occur – generally the intents that the user must express – for the skill to be executed

  • Requirements: Information that must be collected in order for the skill to be executed

  • Actions: The action to take (basically, this is the skill)


 

In the Build tab, we'll create a new skill show-news.


 

Click on the newly created skill show-news name and open it.

Under the triggers tab, we added one condition that must occur to trigger the action.


As our bot will call an external API service to get the latest news headlines, we need to pass some data to that service to get the type of news we want like sports, entertainment, health, etc.

So we will set the requirement in the Requirements tab. I hope you remember that entity we created earlier, we'll set the requirement that this information is required before executing actions.

 


Now we'll set what action to take when #news-type is complete.


Set the Memory Field, we'll use this field later, when we'll call the external API service.
{
"raw": "{{memory.news-type.raw}}",
"value": "{{memory.news-type.raw}}"
}


And when #news-type is missing, Then simply send the Message back to the user.

Ohhh !! I'm not taught to bring this news to you.


 

Finally, we'll call the API service to fetch the news in the Actions tab.

First, check a condition if news-type is present or not. If it is present only then the API service will be called.

Here you can add the URL of the API service which will send the latest news headlines based on the news-type information we share. You can create your own service and deploy it on the SAP Cloud Platform or use any existing service which sends the results in JSON format.

I used the NewsAPI service and the following is the URL
https://newsapi.org/v2/top-headlines?q={{memory.news-type.raw}}&apiKey=2399fd7ecfc841ebaae8f5841f589...

We are passing {{memory.news-type.raw}} tag, which will be replaced with the actual value, that our boat stored in memory.


Then add the Namespace to the Response tab - The API service response will be stored under this name. We have added news as our namespace.

To show the news results to the user, click on the + button sign below API Service Configuration and the output type of your choice.


 

You can select Text or any other control ( i have added a list ), In the text box, we can write the following to get the title and description from the results.
{{api_service_response.news.body.articles[0].title}}
{{api_service_response.news.body.articles[0].description}}

 

At the end click on Update Conversation and then select Reset Conversation. We reset the memory so that the user can enter another news type.


 


 

Connect


Now it's time to deploy our bot to various platforms. There are various kinds of options available you can deploy chatbots to a website, Slack, Facebook, Microsoft Teams, and various other platforms.

Here we'll deploy our news bot to a website.

Go to the Connect tab and perform the following steps.


Copy the Webchat script code, the javascript code for your HTML page.


Add the code to your website. Simply copy/paste the code on your website page where you want to make this bot live.

For testing, I created an index.html file and pasted this code inside <body></body> tag. Now open this index.html in your favorite browser.
<html>
<head>
<title>Developing News bot with SAP Conversational AI</title>
</head>
<body>
<center>Welcome to my website Newsbot</center>

<script
src="https://cdn.cai.tools.sap/webchat/webchat.js"
channelId="xxx959a556c-bceb-48bc-a12xxxxxxxxxx"
token="xxxf754bc21dd5dc4f0f018fxxxxxxxxxx"
id="cai-webchat">
</script>

</body>
</html>

Congratulations !! Your news bot is now live.


Hope you find that helpful! Let me know your thoughts on this in the comments section.

Thanks for reading!
6 Comments