Hi Guys,
Welcome to Part 3 of the series SAP Conversational AI Overview & Build your first BOT.
In this blog post, I am going to discuss one of the coolest integration in the SAP world ‘SAP S4HANA Cloud and Whatsapp’.
As many of you know, WhatsApp is one of the most popular messaging platforms, and nowadays, it can also be used for business purposes, so why not have your S4HANA system integrated with it.
Before stepping into the integration with Whatsapp, I’ll urge the readers to go through my previous blog SAP Conversational AI + S4HANA Cloud → ‘A Fantabulous Combination’ which explains the integration of SAP CAI with S4HANA Cloud.
Now let’s focus on the topic of the day.
Why such integration with Whatsapp is needed?
Let’s talk about a situation where the end-user wants to know the status of his/her order, or the user needs some details from the SAP system. It requires the user to login to the SAP system and performs the requested operation.
Now how about if we could get all such details in our smartphone right away from SAP System and that too with just having a chat conversation with the bot.
That sounds super cool and convenient…right
This blog here talks about the security aspect of the integration of Whatsapp.
How this integration is going to work?
Now, if you have worked with CAI integrations before, you would already be aware that there are some direct channels for integration with Telegram, Messenger, WebChat, etc.
But for Whatsapp, there is no direct integration channel available. The trick here is to make use of a trendy Cloud Communication Platforms called Twilio.
Twilio is a cloud communications platform as a service (CPaaS). Twilio allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs.
Technical Architecture
Now let’s get into the main steps involved in achieving this integration.
Step 1. Create a custom business object or CDS view or use the SAP whitelisted API.
Step 2. Create the communication scenario and arrangement for the CBO or CDS view. In case you are using whitelisted API, those are already exposed.
Step 3. Develop a Node Js Application that will act as a middleware between the SAP S4HANA Cloud System.
Step 4. Deploy the Node Js application on the SAP Cloud Platform.
Step 5. Develop and design the bot skills in SAP CAI.
Step 6. Use the deployed application URL as a webhook in the CAI Bot.
Step 7. Test the bot.
for Step 1-7 check out my previous blog.
Step 8. Create a free Twilio account on Twilio
Step 9. Enable the Whatsapp Channel.
Login into your Twilio account, expand the left side panel and click on Programmable SMS.
Then click on Whatsapp.
Twilio provides the Sandbox environment for Whatsapp. You have to set up the sandbox account on your mobile. You just need to add the number and send a message from your WhatsApp as shown below.
After the connection is successfully established, you’ll get the below message.
From the Twilio, dashboard click on Functions under Runtime category.
First click on the Configure option, here you need to add the correct version of the npm module for SAP CAI SDK.
Add the npm dependencies and save.
Now provide function name, path, and the below code. Now Save the function.
exports.handler = function(context, event, callback) {
console.log('invoked with', event)
global.twiml = new Twilio.twiml.MessagingResponse();
var sapcai = require('sapcai')
let build = new sapcai.build('<CAI API KEY>', 'en')
build.dialog({ type: 'text', content: event.Body}, { conversationId: event.From })
.then(function(res) {
'debugger';
data = res.messages[0].content+"\n"+res.messages[1].content;
twiml.message(data);
callback(null, twiml);
})
};
Add your BOT’s API token to the code. You can get the token from your bot like below.
Once the function is saved and deployed copy the function path which will be used as a webhook in the WhatsApp channel.
Step 11. Now use the deployed function’s URL as webhook in Whatsapp channel.
Navigate to the Whatsapp channel then sandbox, here give the function path which you copied in the previous step.
Save it and now you can test it.
Stay tuned for more upcoming fantastic stuff.
I hope you all have enjoyed this blog post, and I’ve been able to make myself clear. Please let me know your thoughts, doubts in the comment section below, and if you enjoyed, please like and share.
Wishing excellent health and safety to all of you and your friends & families.
Nenhum comentário:
Postar um comentário