Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
EstherGonçalves
Newcomer
0 Kudos

Introduction

The aim of this article is to show how to create a chatbot in SAP Conversational AI and
integrate it with a Telegram chat  and Alexa.

 

Prerequisites

This exercise will require to have some previous steps:

  • Create a trial account in SAP Conversational  AI: https://cai.tools.sap/ 
  • You will need an Amazon Alexa Developer account. An Alexa device is a plus but not required to test.
  • Install Telegram app in your mobile phone.
  • Create a Bot in SAP Conversational AI.

 

F&Q Bot

The first step is to create a Bot in SAP CAI. As my objective is to test the integration with Telegram and Alexa I will create a simple FAQ Bot using a .csv file like in the example below. I am using common questions in a high school secretary.

EstherGonalves_1-1713992622179.png

Once the .csv file is loaded you can see it in the Bot Train label

EstherGonalves_0-1714210078963.png

Uploaded file can be edited manually to correct possible classification errors. We can start then the training, testing the bot with different prompts to check if the questions asked to the user are correctly related to the intents created.

EstherGonalves_1-1714210206078.png

In the Monitor label, the procedures followed by the Bot in previous conversations can be analyzed in order to observe and assign the correct intent based on the user questions. This will help the Bot to learn with new expressions. 

EstherGonalves_3-1713993218928.png

Having corrected the bot's classification of the questions and answers, the bot can then be tested in the SAP console. This continues the training of the bot, enabling its continuous learning.

EstherGonalves_4-1713993395356.png

Once the Bot is tested we can integrate it in different platforms, on a website, MS Teams, Twitter, Slack, Line, Telegram or Amazon Alexa, among others.  

 

Telegram Integration

In order to create a user-bot interaction external to the SAP CAI console, the bot can be connected to an external channel In this case, it will be connected to the messaging application Telegram. To do this, create an account in the Telegram app and then search for the channel "BothFather". In the chat, type the command "/newbot", answer every question directly in the chat to configure your bot. 

EstherGonalves_5-1713994855584.png

Ask BotFather to get your token by typing the command /token in the conversation panel. Copy your token and then go to the Connect label of your Bot in SAP CAI, under Telegram Third party channels and paste your channel Telegram name and token, Telegram.

EstherGonalves_2-1714210352826.png

The CAI Bot is already deployed in Telegram. Now it can be shared with other users to converse with the bot, which will continue to expand its learning in intent recognition.

EstherGonalves_6-1713995131865.png

EstherGonalves_7-1713995157674.png

EstherGonalves_8-1713995194259.png

See this video how the SAP CAI Bot works in Telegram: https://youtu.be/17ULH8Fz-JU

 

 

Alexa Integration

To test the Alexa integration, I have created a new SAP Coversational Bot based in intents and skills. Follow this tutorial to build your own bot: https://developers.sap.com/tutorials/cai-bot-getting-started.html

EstherGonalves_3-1714211015572.png

To connect this new bot created in SAP CAI with Alexa, access Connect label and select Amazon Alexa channel and follow the steps below:

  1. Create an account in the Amazon Developer Console
  2. Give SAP CAI permission to manage the Alexa skills by clicking Allow in the popup that opens.

    EstherGonalves_5-1714211089148.png

  3. Alexa sends a launch request whenever a user invokes a skill. The bot has to handle this request by supporting an additional intent, e.g. conversation-start with a single expression CONVERSATION_START. Be sure to create a new skill to welcome the user. This new skill should be triggered whenever the conversation-start intent is detected.
  4. Select the skill we want to share. Fill the name for the Amazon Alexa skill hosted in Amazon Developer and an invocation name to start the skill. In this case this will be "alkala soporte".EstherGonalves_6-1714211131874.png

 

Once these steps are completed, the skill  is linked to the bot in SAP CAI, we are able now to test it in the Alexa Developer Console:

EstherGonalves_11-1713997797319.png

To connect the bot with Alexa Echo Dot, we must export the skill's compliance by agreeing to some conditions. The Developer Console also has several modifiable code files in javascript. For this development, it needs the following dependencies:

 

 

 

"dependecies":{
"ask-sdk-core": "^2.7.0",
"ask-sdk-model": "^1.19.0",
"aws-sdk": "^2.326.0",
"i18next": "^2.326.0",
"i18next-sprintf-postprocessor":"^0.2.2"
const Alexa = require('ask-sdk-core');
const i18n = require('i18next');
const sprintf = require('i18next-sprintf-postprocessor');

 

 

 

To put it into operation, we will need a structure with String in several languages. This can be done by adding Interceptors:

 

 

 

const LogginRequestInterceptor = {
process(handlerInput){
console.log(`Incoming request: $(JSON.stringify(handlerInput.requestEnvelope.request)}`);
}
};
const LogginResponseInterceptor = {
process(handlerInput, response){
console.log(`Outgoing response: $(JSON.stringify(response)}`);
}
};
.addRequestInterceptors(LogginRequestInterceptor)
.addResponseInterceptors(LogginResponseInterceptor)

 

 

 

Each handler can process an event that occurs in operation and triggers a given action, responding according to a database. In this case, the request type is to open the Launch Request skill. 

 

Conclusion

SAP Conversational AI is a powerful platform to build Bots with almost no code and be deployed in several channels in an easy way. I hope this article was useful for those who are starting projects In this area of great application opportunities.

Labels in this area