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
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
sudipghosh
Active Contributor
0 Kudos
I updated the twilio function code, please use updated code . Can you please record a video and send to me. i am unable to understand what you are trying to convey. Because if you understood correctly we are using SAP CAI sdk to send message and getting response based on intent and skill that we are getting in whatsapp. Now if you meant that only it is giving reply to your first message and other message is not replied you first check the monitor in sap cai it is reaching or not. If it is not reaching there we have to look at twilio where it is going wrong. Because even in trial environment you can test the functionality properly.
Rodrigo-Giner
Active Contributor
0 Kudos

I created a new public bot (k-mus/test-whatsapp) with “Authorization: Token 56c330d8cd22a95dd0d94c5e734e8012”

if you setup this bot via whatsapp you will only get the “Hello :)” but not “world”, the bot only show the first message group only below the screenshots.

I miss the old SCN, I have no idea how to send you a pm in this new portal.

former_member409575
Participant
0 Kudos
Hello,

I have tested and found as you have defined two message group the reply is coming in two array objects. But in the twilio  function code i am showing only first array object as response.
dta = res.messages[0].content;

Lets look at how i have tested.



Now in order to fix I have just used for loop and it worked pretty well.



I hope you can make the adjustment in your code because you just need to add the for a loop as per the picture, still if you are facing the issue i will help you out personally to fix this 🙂

 

Regards,

Sudip

 
Rodrigo-Giner
Active Contributor
0 Kudos
Hi, you are concatenating the values of the 2 messages but still the bot it's sending just one reply. I want to know if this is a limitation with the integration or if the bot can show an array or a collection of responses.

If I say "Hi" I expect the whatsapp bot to work as the test in SAP CAI and show me 2 different ballons texts and not only one with the values concatenated.

Regards
0 Kudos
It is good one. I have a question whether whats app integration can be done in SAP S/4 HANA on premise or it is only possible with SAP S/4 HANA cloud
0 Kudos
In continuation to my previous question. Actually our client requirement is to send the sales Invoice form or sales contract form to customer or PO to vendor using whats app. kindly reply me at the earliest. Thanks in advance
sudipghosh
Active Contributor
0 Kudos
Here i am doing it in S/4HANA onpremise, it is possible in both S/4HANA cloud and S/4HANA Onpremise, in case of s/4hana cloud you dont need cloud connector and api management to expose the service to internet. Here in order to expose the odata i have used sap cloud connector. i hope this answer will help 🙂
0 Kudos
Sudip.

Really appreciate your fast response. This helps. I hope we can also send the forms (Invoice form or contract form) to customers. Any comments please

How to get the Cloud connector, I need to contact to SAP for this.

Beside cloud connector any other things I need to have for this

Thanks
former_member1232
Active Contributor
0 Kudos
Thanks for the fantastic blog again.

No on-premise S/4HANA can take this advantage to connect with WhatsApp channel, correct?

 
sudipghosh
Active Contributor
 

Hello Amit,

It is On-Premise only, you can integrate with On-Premise. Cloud, Hybrid Everything, Possibilities are just limitless. For on-premise this is the Architecture. For S/4HANA Cloud you don't need cloud connector and API Management as your odata/api/webservice will be exposed to internet.

 

Regards,

Sudip
former_member1232
Active Contributor
0 Kudos
Thanks for the quick clarification Sudip..I am trying now! 🙂
former_member409575
Participant
0 Kudos
Thank you
former_member409575
Participant
0 Kudos
Thank you so much
former_member409575
Participant
0 Kudos
Thank you so much
Thank you for Awesome blog, i have tried your cloud version, it is working
former_member409575
Participant
0 Kudos
Thank you so much, now S/4HANA Cloud version is also available 🙂
former_member409575
Participant
0 Kudos
Please try, you can do it
former_member409575
Participant
0 Kudos
Thank you so much sure try, now S/4HANA Cloud version is also available
former_member409575
Participant
0 Kudos
Thank you so much
former_member409575
Participant
0 Kudos
Thank you so much for your comment
former_member409575
Participant
0 Kudos
Avinash Thank you so much
former_member409575
Participant
0 Kudos
Thank you so much, I am glad that you liked it
former_member409575
Participant
0 Kudos
Hello Satish thank you 🙂
former_member409575
Participant
0 Kudos
thank you so much, I am glad that you found it interesting. Now SAP S/4HANA Cloud Version is also available please have a read.
former_member409575
Participant
0 Kudos
Hi Satish, thank you so much
former_member409575
Participant
0 Kudos
Thank you so much 🙂
former_member409575
Participant
0 Kudos
Thank you so much now SAP S/4HANA Cloud Version is also available, try it out
former_member409575
Participant
0 Kudos
Hi, Saksham Thank you so much, yes it made. Now i have blogged SAP S/4HANA Cloud Version also.
former_member409575
Participant
0 Kudos
Hello Rajesh, Thank you so much.
former_member409575
Participant
0 Kudos
Hello Kishore, thank you so much for valuable comment.
former_member409575
Participant
0 Kudos
Thank you Imran bhai for your comment
former_member409575
Participant
0 Kudos
Thank you so much Priyanka :-), i am glad that you found it interesting. now S/4HANA Cloud version is also available.
former_member409575
Participant
0 Kudos
Thank you Arun for your comment.
former_member409575
Participant
0 Kudos
Thank you so much, I am glad that you found it cool.
former_member409575
Participant
0 Kudos
Great to know that, thank you so much
Grt article, thx for sharing
former_member409575
Participant
0 Kudos
You are welcome
former_member55862
Participant
Hi! Sudip,

Excellent blog and thanks for sharing!

Regards,

AQIB
bhaskar_idp
Explorer
0 Kudos
Hi Sudip,

 

I am trying to integrate SAP C/4HANA Marketing Cloud with Whatsapp by using Twilio.

I need help here to establish message body to send directly message from Marketing Cloud. I am not a technical guy but trying to do that.

Steps are ready:

1. Communication setup from Marketing cloud to SAP CPI is done.

2. Custom iflow is ready

3. Twilio Test account with Sandbox is ready

4. Need message body that accepted by Twilio API(Number, Text, Media URL). This can be setup in CPI

Please help me on this.

Regards,

Bhaskar

 
sudipghosh
Active Contributor
0 Kudos
Hello,

Do you have odata service or web service ready for marketing cloud, if you do have that then first you need to integrate that with SAP CAI, rest of the steps are same.

Regards,

Sudip
0 Kudos
Hi SUdip,

 

Nice blog, just 1 query are there any restrictions in number of messages that can be sent/received with Twilio trial account ?

 

Do we have any document available for that ?

 

Regards,

Vinay
0 Kudos

Hello Sudip,

 

I’ve completed all the above steps. Able to see the response in NodeJS terminal. But I couldn’t get response in Whatsapp. Can you please let me know where issue would be

former_member409575
Participant
0 Kudos
Check your Twilio function, issue is there most probably
former_member409575
Participant
0 Kudos
Trial account always will have limitation, i dont know exactly how many messages you can send but once your credit will get finished you have to create another account and use it
SateeshUppada
Explorer
0 Kudos
Hi Sudip,

Very nice blog! I have one general question, if we want to achieve the WhatsApp integration with SAP ECC system, do we still need the Twilio kind of messenger communication between SAP and WhatsApp or can we directly connect to WhatsApp through API’s ?

 

 

Regards,

Sateesh U.
former_member409575
Participant
0 Kudos
Hello Sateesh,

I guess you couldn't understand this correctly, sorry about this. Ultimately we are consuming odata service from S/4HANA there is no other control S/4HANA have in this scenario. So same for ECC. And for your infomration you can't directly consume whatsapp api you need partner like messagebird, twilio. I hope this clarification works for you.

Regards,

Sudip
former_member652084
Discoverer
0 Kudos
Hi Sudip,

That was really a wonderful blog. So simple and easy to understand. I was able to implement the same. Is there a way to format the the replies that are sent by SAP CAI. For ex: I am trying to pass a list from SAP CAI which doesnt get displayed in WhatsApp. Whereas if i try to pass a plain text it displays over WhatsApp. I believe it has to do with the way we decypher the reply from CAI in twilio through js. But can you guide how should I approach this problem and format it in the same manner.

 

Once again thanks a lot for guiding us.

 
0 Kudos
Hi Sudip,

 

Thanks for sharing this. Very Nice Blog.

I am not a Tech guy and have never done these things. But I could get it working all my myself without any help.

 

Regards,

Sireesh
former_member212573
Participant
0 Kudos
Hi Sudip,

Its new to Re-Skill yourself.

Regards,

Pankaj
sudipghosh
Active Contributor
0 Kudos
I didnt get you, could you please explain lil more
Labels in this area