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: 
sudipghosh
Active Contributor
100,739
Hello everyone,

 

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.

What is Twilio?

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.

7. Test the bot using SAP CAI.

for 5, 6, 7 check my previous blog.

8. Create a free account in twilio.

9. Enable the whatsapp channel.

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 🙂

 

Regards,

Sudip
113 Comments
Former Member
Wowww....that really seems interesting...I would like to try this... Thanks for this wonderful blog ?
former_member286578
Discoverer
0 Kudos

This is amazing and need of the hour. <email address removed by moderator>

I’m a functional but I’ll try.

0 Kudos
Very cool! I will perform here! I see a lot of important functionality with this integration! Thank you for sharing!
former_member292627
Discoverer
Awesome integration.. looking forward to trying it.
neeraj_bhardwaj4
Contributor
0 Kudos
Nice blog..!!
Former Member
Great Job! Thank you for sharing with us!
BKesav
Explorer
0 Kudos
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....

Thanks for your efforts in sharing this...
Thanks for sharing your great work !!
rajendra_kumar5
Explorer
Thanks for sharing, very nice blog..
sada_gandla2
Explorer
Great !! Thanks for sharing with us.
former_member190936
Participant
Really interesting Sudip.
Superb
former_member618678
Discoverer
Its Really Cool...

thanks for sharing such useful information.
rsonikar
Explorer
Nice and great efforts

 

Its useful blog
ravi91
Explorer
Hi,

I saw messages from SAP like Twilio is going to be deprecated.

Is any other way to connect Whatsapp through SAP CAI?

 

Regards,

Ravi
sudipghosh
Active Contributor
0 Kudos
Hello Ravi,

 

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.

 

Regards,

Sudip
Saksham_Minocha
Product and Topic Expert
Product and Topic Expert
Great Job! I can tell you this is already making news. Keep it up! Thanks.
former_member607993
Contributor
Superb sghosh2 . Great work 🙂

Keep it Up!
himanshu_mundra1
Explorer
0 Kudos
Hi Sudip,

While deploying app to Cloud foundry using CF CLI i am getting unexpected response

error code 422

what might be the issue?

 

Thanks,

Himanshu
Kishorep
Participant
Great work ... superb
former_member409575
Participant
0 Kudos
Hi Himanshu,

Did you configure the manifest file properly

applications:
- name: <app name>
random-route: true
path: <folder name where whole app is there>
command: node index.js
memory: 512M
himanshu_mundra1
Explorer
0 Kudos
Hi Sudip,

Please find attached screenshots of folder structure , manifest file and index fie

 

Thanks,

Himanshu Mundra
spurkayastha
Explorer
Hi Sudip,

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?
former_member409575
Participant
0 Kudos
Hello Sangita,

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.

 

Regards,

Sudip
0 Kudos
Hi Himanshu Mundra,

 

Could you resolve this issue? It would be nice to know it.

 

Thanks,

José
himanshu_mundra1
Explorer
0 Kudos
Hi Jose,

 

Issue is not resolved yet .

Thanks,

Himanshu
former_member121716
Discoverer
0 Kudos
Hello

 

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?

 

Regards,

Thandeka
former_member409575
Participant
Yes it's possible, everything is possible.
imransyed
Product and Topic Expert
Product and Topic Expert
Nice Sudip

Thanks for sharing the knowledge

 
former_member182510
Participant
Interesting blog, thanks for sharing such an important information.
Former Member
Cool, pretty interesting. Thank you for bringing up such cool integrations with social media.
former_member409575
Participant
0 Kudos
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.
jranganathan
Product and Topic Expert
Product and Topic Expert
Cool stuff !!! Very useful feature for SAP users
AndreasHuppert
Product and Topic Expert
Product and Topic Expert
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.
saikrishna_vallurupalli
Active Contributor
Very interesting
former_member347172
Discoverer
0 Kudos
Really interesting!

Thanks for sharing!
0 Kudos

Hi himanshu.mundra

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 :).

https://www.youtube.com/watch?v=fOraTnTZktI

 

Regards,

José

I agree and I appreciate your concern for customer privacy.
RameshGaikwad
Associate
Associate
0 Kudos
Nice post.

Last month I did it stage-1. twilio+whatsapp.
I will now try with SAP CAI.
0 Kudos
Very Interesting, I would like to know more about the programming details of SAP AI ChatBot?

Can you explain it?

Regards
former_member409575
Participant
0 Kudos
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.
former_member409575
Participant
0 Kudos
Now Part II is available which will show how you can enable One Time Password  in above scenario

https://blogs.sap.com/2019/08/29/implement-security-in-whatsapp-integration-with-sap-s4hana/
former_member409575
Participant
0 Kudos
Now Part II is available which will show how you can enable One Time Password  in above scenario

https://blogs.sap.com/2019/08/29/implement-security-in-whatsapp-integration-with-sap-s4hana/
former_member409575
Participant
0 Kudos
Now Part II is available which will show how you can enable One Time Password  in above scenario

https://blogs.sap.com/2019/08/29/implement-security-in-whatsapp-integration-with-sap-s4hana/
MaheshChandra
Active Contributor
Interesting Sudip, we made few chatbots but this conversation was Awesome.  no where Sara looks like a bot. Trying to implement this
former_member409575
Participant
0 Kudos
Hello Thanks, good to know that. Yes if you train your bot, possibilities are limitless.
sudipghosh
Active Contributor
0 Kudos
Hello Andreas,

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.

 

Regards,

Sudip
AndreasHuppert
Product and Topic Expert
Product and Topic Expert
0 Kudos
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.
sap_armageddon
Explorer
Thank you for sharing.
Rodrigo-Giner
Active Contributor
0 Kudos
Hi, thank for the blog.

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.

Could this be fixed ? how ?

thanks
Labels in this area