Skip to Content
Technical Articles
Author's profile photo Sudip Ghosh

Google Translate integration with SAP CAI Chatbot

Hello Everyone,

Welcome to my another blog, In this blog i am going to discuss how language barrier can be removed from Enterprise Chat bot so that people can get system insight by interacting with chat bot in their own language. For example my mother tongue is Bengali definitely i would be happy to interact with AI based Chat bot in Bengali and get the S/4HANA system insight in Bengali. Like Russian is most widely speaking language followed by German and french in Europe as per google and people would love to interact with S/4HANA system in Russian Language.


Current Situation and Challenges

India have 29 States and in 29 states we have different regional culture and every states have different language and among all the language most common languages are Hindi, English, Telugu, Tamil, Bengali, Kannada, Malayalam, Oriya, Punjabi, Urdu, Sanskrit. Except English most of language Indians use as their mother tongue and there are many places in the world where people prefer to do all the business operation in their own language not in English. Now a days Enterprise Chat bot is a game changer stuff for a organization. But its a challenge to build chat bot and train chat bot in these language except English. SAP CAI is also not an exception, Except English, German, French and Spanish other languages are only standard support available means sentiment analysis, Gold Entities, Enrichment type those are not possible. Full details is available here. At the same time finding developer who knows how to design bot in every languages is a pretty big challenge.


How to overcome this Challenge

To answer this question lets ask question ourselves how many of us  have used Google Translate to convert and understand language. I am sure number will be pretty high, at least i have used and still using in many situation. In this situation also we will be using google translator engine in between a human and SAP CAI Bot. So we don’t have to train our bot into different languages. Translator is going to manipulate the text it receives from user and translate into English then pass it to SAP CAI and the response from SAP CAI is again translator will translate in the Language user asked question.

Look at this two minute coolest demo video i have recorded, Then we will go to Implementation part. I hope you liked the background positive music too 🙂

Well if you are reading this line that means you got interest and you want to continue the reading. lets get into the main business How to implement. As you see i have hosted my SAP CAI Bot in telegram many people might started thinking this guy have used standard channel connector available in SAP CAI, but hold on my friends in standard connector you cant add translator 😛

Then How ?

We have to rebuild the Telegram connector from scratch and add the translation logic. Lets have a look at the technical architecture which will definitely clear many things.

One thing i would like to mention in most of the cases when we build connector normally the hosting platform (Alexa, Slack, Google Assistant etc) where we host the bot make web hook call where it pass the message to SAP CAI. But in telegram case it is different here it doesn’t make any web hook call here we have to make a polling program which will poll the messages from telegram bot using Telegram sdk.

Lets break this whole integration into smaller piece, so that it would be easy to make sense.

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 telegram bot by chatting with Godfather and get the access token for your bot keep it with you which we will be using in our Node.js program. Check this awesome documentation

9. Develop node.js based connector or polling program which will be used as translator between SAP CAI and Human.

const translate = require('@k3rn31p4nic/google-translate-api');
var TelegramBot = require('node-telegram-bot-api'),

    // Be sure to replace YOUR_BOT_TOKEN with your actual bot token on this line.
    telegram = new TelegramBot(<Your telegram Token>, { polling: true });
    var sapcai = require('sapcai');
    var build = new<Your SAP CAI Token>, 'en')
    var detectlang , transtext, cairesponse, chatid;

telegram.on("text", (message) => {
  chatid =;

  //google translate code start.
  translate(message.text, { to: 'en' }).then(res => {

    detectlang = res.from.language.iso;
    transtext = res.text;
    build.dialog({ type: 'text', content: transtext}, { conversationId: chatid })
     .then(res => {
      cairesponse = res.messages[0].content;

      translate(cairesponse, { to: detectlang }).then(res => {
        telegram.sendMessage(chatid, res.text);
      }).catch(err => {

  }).catch(err => {

  .catch(err => console.error('Something went wrong', err))


Now in this code replace the SAP CAI and Telegram token with your token.

10. Deploy and run this node.js application into AWS EC2 or any local machine. If you want to deploy and run into AWS then checkout this awesome step by step blog.


In my previous blog i have shown how to implement translation capability for google Assistant Integration with SAP S/4HANA, you may refer if you are looking for

I hope everyone enjoyed this blog, Don’t forget to like comment and share. Your likes, comment and share definitely helps me to write more such content for you :-). I wish all the readers have a nice weekend ahead.






Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Randy Lukas
      Randy Lukas

      Thank you so much for sharing and scaling it up globally.

      Author's profile photo Sudip Ghosh
      Sudip Ghosh

      Randy Thank you so much for your comment. Yes, google translate does the magic.

      Author's profile photo Raffael Herrmann
      Raffael Herrmann

      Hi Sudip,

      Interesting article. It reminds me of the “Babel fish” from Hitchiker’s guide to the Galaxy. ?

      One technical question. You say in opposite to other bot interfaces for Telegram bots you have to poll instead of using a webhook. May I ask what’s the reason therefore? In general Telegrams bot API has a webhook feature. (See my blog over here.) So is it because the used NodeJS library doesn’t support it or is there another reason?

      Best regards

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Hello ,

      Hi first of all thanks, Yes i have seen that webhook and i know you can trigger a api call but the problem is there is no good documentation to capture the response which can be used as text response, normally in chat bot we need response as a format telegram understand and session is very important. Which i was looking for and couldn't find it.



      Author's profile photo Somnath Paul
      Somnath Paul

      Brilliant post, as usual!!

      Author's profile photo Ashwin Katkar
      Ashwin Katkar

      Hi Sudip,

      I was working on integrating SAP CAI with whatsapp with help of twilio and SAPCAI SDK. In Feb 2021 SAP team made mandatory to include OAuth token with developer token which i dont see supported in current SAPCAI SDK on npm.

      Any idea how we can resolve this issue? Here is sample of code for Twilio funtion.

      exports.handler = function(context, event, callback) {
      console.log('invoked with', event)
      global.twiml = new Twilio.twiml.MessagingResponse();
          var sapcai = require('sapcai')
      	let build = new'<CAI APi KEY>', 'en')
        build.dialog({ type: 'text', content: event.Body}, { conversationId: event.From })
        .then(function(res) {
          dta = res.messages[0].content;
          callback(null, twiml);