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!
Welcome to my another blog, here i am going to discuss on one of my cool project 'Whatsapp integration with S/4HANA'. We all know most probably whatsapp is one of most used messaging app now a day people use for business as well as personal use.
** I have added Part II is here, which will discuss the how we can handle the security aspect.
But How this integration make sense?
Answer is very simple think about a situation where you want to know your order status, either you would login to system or you ask someone. Now instead of doing this if you could ask whatsapp bot which could tell you insight of your order. Much simpler isn't' it.
Now most of the SAP CAI developer started thinking oh! this guy is just talking about building a bot in SAP CAI and expose this bot thorough another channel. But here is trick there is no whatsapp channel available in SAP CAI just like messenger, alexa, slack etc.
Then how this integration is possible?
This answer is also very simple its Twilio which will help us to achieve this.
Twilio is a cloud communications platform as a service. 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
Discussing about twilio more won't make sense here because people are smart enough to googling and do r&d on it. But what most important thing i am going to discuss is how twilio enabling this integration.
Lets look at the technical architecture
Business Story
Bestrun is a US based company who use S/4HANA to run their business. Brooke is newly on-boarded employee in Bestrun and she is eagerly waiting to get her new laptop to start work. As many employee joined in last seven days, Bestrun had to place an order for Brooke which take approximate two day to deliver the order. Other side Brooke is quite excited like others new employee to start working, so she is always wondering when she will get the laptop. In the meantime she remembered her on boarding training where she was introduced to Sarah a Whatsapp bot who can help employee to know different Business insight and information as Sarah is integrated with their core system S/4HANA. So Brooke add her in whatsapp account and ask about her order status and Sarah checked the order status in S/4HANA and reply that order is delivered and you can see the smile on her face :-).
Enough of story let's get into main business which is how we are going to connect the dots. Lets break this integration into smaller pieces so that it would make more easier to understand.
1. CDS and Odata service creation for querying order status. (In this example Purchase Requisition and Purchase order Status will be queried). Check this blog.
2. Exposing the odata service through cloud connector and creating proxy api using SAP Api management. Check this blog.
3. Designing the skill of chatbot in SAP Cai. Check this amazing tutorial
4. Creating node.js app which will be interacting with S/4HANA and provide json response the way SAP CAI understand. Check out my github repository.
5. Deploying the node.js app we created in last step into SAP Cloud Platform CF account.
6. Use the deployed application URL with proper path as webhook of skill in SAP CAI.
10. Create a twilio function to interact with SAP CAI using SAP CAI SDK.
11.Deploy the function and use function Url as Webhook of WhatsApp channel.
Among 11 step till 7 there are numerous blog people have written so i am not going to write the same stuff again rather provide you reference link which you can use. Lets discuss on last four points one by one.
8. Create free account in twilio using this link, you can get free trial account where all the beta services are enabled. Registration process is quite straight forward.
9. Enable the WhatsApp channel
Twilio provide WhatsApp Sandbox account, you have to setup the sandbox account in your mobile. The process is pretty straight forward. You have to add your sand box number in your WhatsApp and send the code (E.G join say-rays) as first message from your WhatsApp like below.
(log-in to your twilio account and click on programmable sms, you will find this option)
On successful connection you will get Message received like below.
Now leave it like this, we will come to this later. Now we have to create twilio function which will interact with SAP CAI using SAP CAI SDK.
10. Create a twilio function to interact with SAP CAI using SAP CAI SDK.
Now click on runtime in your twilio dashboard, you will find function (beta) option like below.
Now explore the function, you will find manage and configure option, first click on configure option we have to add npm module for SAP CAI SDK.
Now in dependency list we need to add SAP CAI npm module with correct version.
After saving this now go to manage function option and add function with blank template.
Now give a function name, path and add the below code and save it like below.
After pasting the below code and before saving replace the request token with your request token which is used in 4th line. You can get easily the request token from your bot like below.
Twilio Function code.
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';
dta = res.messages[0].content;
twiml.message(dta);
callback(null, twiml);
})
};
Now Save it, after successful save copy the function path which has to be Webhooked in WhatsApp channel.
11.Deploy the function and use function Url as Webhook of WhatsApp channel.
Now go to programmable sms and then go to WhatsApp Sandbox to add the function path as Webhook like below.
Save it and thats it. You can test it now.
Here i have attached a vedio of this Integration testing, hope everyone would like it.
I hope everyone enjoyed this blog, Please dont forget to put comment and share 🙂
Wow...that was well-narrated use case about the integration b/w trendy messenger app and trendy ERP S/4 HANA...with this lots of open ideas on other areas of SAP Processes will flow I guess....
if you have understood it correctly then you would see i have never used standard twilio channel in SAP CAI which is going to be deprecated, rather i used SAP CAI Sdk to forward all the message to SAP CAI. So this integration is not at all depending on the standard twilio channel. I hope this would help your answer.
Can you explain how did you use API Management in your scenario?
In the blog https://blogs.sap.com/2017/11/13/manage-your-apis-developed-in-cloud-foundry-using-api-management/, it says that for a CF application in the CF account, we need to create a service instance of API Management and bind the CF application with the service instance. This creates an API Proxy in the API Portal of the linked Neo account. All subsequent calls to this CF application will now be routed through API Management. Is that what you have also done?
The S/4HANA system i have used here is on-premise, so i just created proxy api using api management so the odata service can be accessible from all over the internet, the node js application is not limited to only cf account even you can use same node js application is aws and call the proxy api from there, Here api management is just playing role to create proxy api of odata in S/4 so that it can be called from anywhere any kind of platform. may be you can have a look at this blog. I hope it would help.
Great blog, interesting as well. My question is, is it possible to place an order, like a Purchase Order, via whatsapp and get the PO created in SAP automatically?
Well, Brother, I have tried to deploy the app in cf trial yesterday, it was completely working fine, maybe I will try to make video and post here this weekend.
Unfortunately this will only work in jurisdictions with low data privacy and employee rights. Twilio will sell your data for marketing purposes. That means your customers data. So you will have to lower your own privacy statement as a company using this integration to the standards of Twilio. And your works council will not allow unnamed third party partners of Twilio to monitor your employees.
Did you try to eliminate the path attribute. I am seeing that you have it and there is a point after the equal (=) sign.
While Sudip try to make a video deploying an app I think is the best option that you have in your hands. Even, you can see this video where you can learn to do it. It’s for begginers like me :).
Can you please tell specifically what exactly you are looking for, in above scenario i have used CAI sdk which you can get in node.js and python as well. and for webhook call either you can build express application or flask application it is basically for generating response the way CAI accept.
First of all thank you so much for raising a genuine concern. Well i am not a twilio fan, but twilio is GDPR compliance https://www.twilio.com/gdpr . And regarding
Employee security or authentication, you may have a look in this blog.
I found this information to share, so thought to share here.
Yes, but that Twilio statement is for users using Twilio directly. They can read that and then decide themselves if the way Twilio handles the data is ok for them. GDPR allows you to do a lot with your users data as long as you declare it.
However, the use case in this blog is different: by integrating with Twilio, you expose the data of the employees, customers, and partners of your company to Twilio. Yes, GDPR does not forbid that, but again: you have to ask first. And asking your customers and partners to confirm an update in the data privacy statement is not an easy task. Asking employee representatives to give their ok is a lenghty process at least, even if they allow it.
It seems it has a limitation it only works if the bot reply only one message. If there is more than one message set in the actions tab. The bot in whatsapp only replies the first one.