Skip to Content
Technical Articles
Author's profile photo Christoph Ruehle

Build a chatbot on SAP Conversational AI which communicates with S/4HANA Cloud

Recast.AI (meanwhile renamed to SAP Conversational AI), a company acquired by SAP, has created a development environment for conversational user experience technology. It uses natural language processing via chatbots and enables SAP to include conversational intelligence into their solutions.

In the meantime, we wanted to enable and test the usage of an intelligent chatbot with SAP S/4HANA Cloud, specifically how a bot on SAP Conversational AI can retrieve data from a S/4HANA Cloud system.

This blog post provides an overview how to build a basic bot on SAP Conversational AI and connect it to a S/4HANA Cloud system using standard APIs. To implement the ‘business logic’ of the bot, SAP Function-as-a-service (beta) is used. Finally, the bot is connected to the third-party messaging platform Telegram.


Let’s get started

The use case foresees an SAP S/4HANA Cloud user who wants to provide their customers with a simple solution to gather information on their order’s delivery status. Therefore, we create a simple bot on SAP Conversational AI.

Below you can find an overview of the architecture:

As a first step, follow along this tutorial to learn how to create a simple bot and choose a name for your bot, e.g. ‘S/4HANA Cloud Delivery-Bot’. Choose ‘Greetings’ as a predefined skill.

Once your bot is set up and understands greetings, feel free to add additional intents. We have created the following intents for our example (‘@joke’ is of course optional 🙂 ):

We’ve used the following expressions for the intent ‘@get-help’:

(You get the idea. Feel free to add additional expressions.)

For ‘Actions’ we have created the following message:

At this point, our bot should understand a basic greeting, should respond to it and we should be able to ask how it can help us.

The conversation should look something like this:


Me: Hi

Bot: Hey. What can I do for you?

Me: What can you do?

Bot: I can retrieve the order status for you. Just say e.g. “What is the order status?”.


Now to the most important part and key-skill of our bot. Delivery-status.
Let’s start by creating the intent ‘@delivery-status’.

Create a few expressions such as “What is my order status?” or “Where is my order?”.

Go to the Build tab and click on “+ Create skill” additionally to your already available “greetings”, “get-help” skills (if you have not added “get-help” as a skill, you have to do so).

Choose the “Business”-tag for the “delivery-status”-skill.

Click on the created “delivery-status”-skill and define when the skill is triggered:

Go to “Requirements” and define what the skill requires in order to be completed. We define the order-number (“#number”) as “orderID”.

Click on the triangle-arrow on the right and go to “Edit Replies”.

Under “Edit Replies” we have created the following response:

Next, go to “Actions” and “Add New Message Group” by choosing “Add Condition to trigger messages” (see condition below) and add the message “Let me check the status for you…”.

Now we have to choose “Call Webhook” where we will call the function’s http-trigger. Let’s jump to the SAP Cloud Platform to implement the business logic for our chatbot. We will come back to the SAP Conversational AI-platform later.

Follow this tutorial to set up your SAP Cloud Platform function-as-a-service environment.
Once your Function – Instance was created, click on it.

Choose “Open Dashboard”.

Go to “Create Function”, choose a “Function Name” and click on “Create”.

Use the following code and paste it into an index.js – file in the editor:

module.exports = {
	handler: function (event, context) {		
		console.log('event data: ' + JSON.stringify(;		

		var replyMsg;

		var intent =['intent'];
		console.log('intent detected: ' + intent);

		if (intent == 'delivery-status') {
			var orderNumber =['orderID'] || false;
			if (orderNumber) {
				orderNumber = parseInt(orderNumber, 10);
				var request = require('sync-request');
				var res = request('GET', '\'' + orderNumber + '\')?$select=OverallSDProcessStatus&$format=json', {
					headers: {
						'APIKey': '<YOUR API KEY HERE>'

				console.log('SalesOrder service response: ' + res.body.toString('utf8'));
                var response = JSON.parse(res.body.toString('utf8'));     
				if (response.error) {
					replyMsg = 'I could not find your order, please double check the order number';				
				} else {
					orderStatus = response.d.OverallSDProcessStatus; 
					if (orderStatus == 'C') {
						replyMsg = 'Your order was handed over to shipping already.';				
					} else {
						replyMsg = 'Your order is still in processing.';				
			} else {
				replyMsg = 'Could not understand your order number, please double check';				
		var response = {
			"replies": [{
					"type": "text",
					"content": replyMsg
		console.log('Send reply to user: ' + JSON.stringify(response));
		return response;

Now we log on to the SAP API Business Hub with our user, search for “Sales Order” and choose the following API:

Click on “Show API Key” and copy it.

Paste it into the ‘APIKey’: <‘YOUR API KEY HERE’> – placeholder in our code.

Please note, the above sample coding uses the API Business Hub’s sandbox system. In case you want to connect it to your S/4HANA Cloud tenant, you’d have to create a communication arrangement by following this guide.

Use the following code and paste it into the “Dependencies” – field below the editor:

  "dependencies": {
    "sync-request": "6.0.0"

Click on “Create Trigger”, choose a name and click on “Create”.

Once you click on “Create” you can see the “Trigger Details” and choose “Ok”.

Copy the “Trigger-URL” ( and paste it into your SAP Conversational AI account where we have left off.

In order to only send the required data to our function, go to “Body” in edit-mode, choose “Create custom body” and type in the following code:

	"intent": "{{nlp.intents[0].slug}}",

Once you have clicked on “Save and Deploy” your chatbot should be able to retrieve the order-status from S/4HANA Cloud.

You can test your chatbot by clicking on the button in the bottom-right-corner.

Congratulations! You have created a working chatbot which can retrieve a delivery status from S/4HANA Cloud! 🙂


As a last step you can connect your chatbot to a third-party messaging platform. SAP Conversational AI offers a connection to the following platforms:

Choose the platform you would like to use and follow the set-up guide.

You can find the original chatbot on SAP Conversational AI:

Chat with our bot on Telegram:

For questions or comments, feel free to reach out to us or leave a comment below. 🙂


Mathias Rup:
Twitter: @der_mathias

Christoph Ruehle:
Twitter: @chrisruehle 

Assigned Tags

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

      Thanks for the wonderful tutorial. Can you please throw some light on how we can make a chatbot for S/4 hana on prem systems.


      Author's profile photo Mathias Rup
      Mathias Rup

      Hi Shivani, to connect to an SAP S/4HANA system on-premise the SAP S/4HANA Cloud SDK might be the better option. It allows to deploy the application to SAP Cloud Platform Cloud Foundry (instead of SAP Cloud Platform Functions), offers various connectivity options, and also covers resilience mechanisms in case the on-prem system is e.g. in maintenance. Best

      Author's profile photo José Darío Jaimes Alvárez
      José Darío Jaimes Alvárez

      Hi Mathias R u p,

      It’s really interesting your comment and tried to use Cloud Foundry but it was a little complicated. At the end, I decided to use SAP Functions and it was easier.

      If you know how to deployed codes lines into Cloud Foundry, I’ll appreciate it.



      Author's profile photo AAMIN SHIRAZ BAROLIA

      Hello José Jaimes,

      Could you please share the steps you followed in using SAP Functions.



      Author's profile photo José Darío Jaimes Alvárez
      José Darío Jaimes Alvárez



      I followed the steps in this technical article but I got an error and I couldn´t continue. You can see the error in the post made on August 12, 2019 at 11:56 pm.

      At the end, I decided to use Cloud Foundry where I got cool results using TWILIO – SAP CAI – Cloud Fountry (trial using nodeJS) – SAP API hub and a SAP ERP System test on the cloud.

      As additional information:

      1. I read the technical article by Sudip Ghosh on;
      2. You can see my prototype on this link (audiio in spanish):


      José Jaimes



      Author's profile photo Sharath Bhushi
      Sharath Bhushi


      How does one get past the instance module if the plan is 'hdi-shared' and not trial as it states in the image as shown? The result of which 'open dashboard' option is unavailable to the user??

      Author's profile photo José Darío Jaimes Alvárez
      José Darío Jaimes Alvárez

      Hi Christoph Ruehle,


      Could you say something about this kind of issue when I try to paste the Dependencies value ?


      Author's profile photo Richard Paul
      Richard Paul

      Thats some interersting and insightful content for Chatbot Builders. Do Keep posting such relevant content.