Technical Articles
Google Assistant Integration with SAP S/4HANA
Hello All,
Welcome to another blog, this blog is about another coolest project of mine i was working from couple of days, “Google Assistant Integration with SAP S/4HANA”. Google Assistant is another voice assistant system by Google which most of the people use.
But How this integration make sense?
Think about situation where you want to know some system insight may be you want to know your ticket status or order status and for this either you have to login to the system or have to ask someone who is in front of system. Now instead of doing all this you open your mobile and say ‘OK Google’ Tell me my ticket Status or Tell me my order status. How simple isn’t it.
Now many people might’ve have started thinking that SAP Conversational AI would be used for designing the bot and then it would be integrated with Google Assistant but the trick is here that is no standard channel or connector available in SAP CAI like Alexa or Facebook messenger to directly integrate with Google Assistant.
So how we will build this Integration?
As there is no standard direct integration possible from SAP CAI to Google Assistant, we have look for the option, and the option i am talking about here is Google DialogFlow. Dialogflow is a Google-owned developer of human–computer interaction technologies based on natural language conversations. It is similar to SAP CAI and it does have standard Prebuilt integration with Google Assistant.
Let’s have a look at the technical architecture, After looking at architecture i believe most of the developer would be able to connect the dot.
If you look at architecture then one thing is clear in this picture that we are going to build or design the chat bot in SAP CAI which is integrated with SAP S/4HANA. Now if you are having experience in building chat bot in any platform you might have also experienced with Fallback intent or Fallback skill. it helps you to handle unexpected utterances, or when a customer says something that doesn’t map to any intents in your skill. So Practically we are not going to build any intent in Dialogflow so whenever user ask anything it is going to fulfillment from fallback and it make a Web-hook call which is noting but a node.js application running on SAP Cloud Platform. This node.js application is having two important features first one is it take the user input from google assistant and it pass to SAP CAI through SAP CAI SDK and get the response from CAI. Second one is just another hack think about you are not comfortable in talking or chatting in English then you speak your own regional language Yes it has translator capabilities it translate your language in English and Pass it to CAI and then it get the response in English from CAI and before passing to Dialogflow it translate to your regional language, cool isn’t it.
Lets break this whole integration into smaller pieces, so that it would be more simpler.
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. Build Node.js Based connector or Web hook application and Deploy to SAP Cloud Platform Cloud Foundry
const express = require('express')
const bodyParser = require('body-parser')
const translate = require('@k3rn31p4nic/google-translate-api')
var sapcai = require('sapcai');
const app = express()
const port = process.env.PORT || 3000
// const port = 3000
app.use(bodyParser.json())
app.post('/sapcai',(req,res) => {
const response = res;
const msg = req.body.queryResult.queryText;
const sessionID = req.body.session.substr(36,115);
var build = new sapcai.build(<SAP CAI Token>, 'en')
var detectlang , transtext, cairesponse;
//google translate code start.
translate(msg, { to: 'en' }).then(res => {
detectlang = res.from.language.iso;
transtext = res.text;
build.dialog({ type: 'text', content: transtext}, { conversationId: sessionID })
.then(res => {
cairesponse = res.messages[0].content;
translate(cairesponse, { to: detectlang }).then(res => {
response.send({fulfillmentText: res.text})
console.log(res.text);
}).catch(err => {
console.error(err);
});
}).catch(err => {
console.error(err);
});
})
.catch(err => console.error('Something went wrong', err))
})
app.listen(port, () => {
console.log('Server is running on port '+port)
})
9. Create a Google Action project
Create new project
Select project type Conversational
Now Set a invocation name and save, Here i have given Ms. Sarah (So when i will say talk to Ms. Sarah. It will start the action)
Then Click on Action and click on Add your first action button
Now click on build it will navigate you to Dialogflow Screen
10. Configure and Create the agent
A. Create an agent Name it anything
here i have given Sarah
Now Create a new Intent Called End Conversation And add the training Data (Thank you, Thanks, Thank you google) And Add also response as ‘You are welcome’ and set this intent as end of the conversation. So whenever people will say thank you it will trigger this intent and it will end the conversation.
B. Setting Welcome message in Default Welcome Intent, so when some one start your agent in google Assistant, it will trigger this.
C. Enabling Web hook for fallback intent
Click on Fallback Intent
Enable the Web hook for Fallback intent
D. Set the Web hook URL as fulfillment for Fallback intent( which we have built in Step 8
Go to Fulfillment
Set the URL of deployed node.js based connector
All Done, you can test it now.
Here i have attached a video of this Integration testing, hope everyone would like it.
Please don’t forget to comment like and Share.Your Valuable comment and suggestion really help me to write more interesting content.
Regards,
Sudip
Dear Sudip,
Very good post, thank you for sharing your approach! It also might be SAP T-hub + Speech-to-Text API from SAP ML, so it is possible to make SAP Cloud sole case as well.
However, the biggest gap I can see in your approach is authentication and authorization. Is the user authorized to get PO data from S4HANA?
We have solved this in our Intelligent Decision Dimensions product for SAP ECC and S4HANA and have 300+ business scenarios already covered there. Based on our experience, to use the product is much cheaper then to develop AI content from scratch, as it will roughly take you up to 3000 hours just to make a pilot implementation that will cover a few business lines.
<external link removed by moderator>
Kind Regards,
Siarhei
Hello Siarhei Tsikhanenka
Well i don't know you have got a chance to check my previous blog post or not where i have shown how to handle security in Enterprise Chat bot that same thing can be applied here. In my previous blog post i have shown how we can handle One Time Password based authentication in Enterprise Chatbot using Authy. Same thing can be applied here too :-). The main intent of this blog post is how to make integration between Google Assistant and S/4HANA through SAP CAI.
For security Gap definitely you can have a look at my previous blog.
Regards,
Sudip
Sudip,
Authy, Twilio that are good tools, for sure, for authentication. However, authorization is a bit different and more complicated thing to do.
No issues, nice post. Keep going 🙂
Kind Regards,
Siarhei
Awesome Blog, Just tried out this weekend. It was absolutely working.A big Thumbs up.
good to know that and thank you so much 🙂
Thank you for sharing, Awesome step by step tutorial.
Thank you so much 🙂
hahaha..Video mast hai!!! you are a rock star!!
heheh, Thank you so much 🙂
I tried similar for my S/4HANA, let me tell you it's not easy to train your bot, they born dumb you need to infuse intelligence like Matrix plug.
https://blogs.sap.com/2019/10/11/hey-google-siri-alexa-s4hana-chatbot-is-trending
Training is very important, its just like human when we Came to this earth we didn't know anything then slowly our parents taught us similarly when you create a bot it ll be super dumb you have to train more n more to make super intelligence. The more Training you do your bot will be more intelligent. I had look at your blog its nice overview with stats and architecture. If you are looking for training your bot in different languages like hindi or any regional or any other then you can try to infuse translators, in that case you have to build custom channel connetor. I have covered this how to infuse translator in sap cai. Have a look at this blog.
Thanks for sharing! Bro.. Your blog is really nice! Very True...I am trying to educate my bot just like a kid..Hoping to see a successful demo like yours!! Back in our days, when I use to work for SAP, these fun things were missing...Machine Learning and practical AI
Sudip, A big Thank you. I was able to deliver Chat bots using SAP CAI on HANA MDC and demoed it...
But I want to know about Cloud Foundry. How to create sub account and deploye NOE.JS there ? any light?
really awesome.
Funny query is making it more cool.
Thanks,
Shivam
What is the Webhook URL that you used.. as the one i am using after deploying is not working.
URL Used:
xxx-xxxxxxxxxx.cfapps.eu10.hana.ondemand.com
Please suggest
Hi Sudeep - Nice blog. Thanks a lot, it was very useful. How do you enable single sign on or ensure authentication using Dialogflow? Basically get user information
Good one, Sudip!