Technical Articles
SAP Conversational AI Chatbot Integration with C4HANA
One of the key success for any company would be customer retention and customer satisfaction. With emerging support maintenance/operational cost and tough competition, it makes more mandatory for any business to adopt the innovative technology and grab profit immensely by maintaining a successful algorithm for a long term without human intervention. Chatbots can be fully automated with a human touch there by providing a complete 24*7 support without any human intervention.
This blog details how to integrate SAP Conversational AI Chatbots with C4HANA using SAP Cloud Platform as a middleware.
To develop the bot, we need three systems/platforms namely
- SAP Conversational AI
- SAP Cloud platform
- C/4 Hana system
System landscape:
Let us discuss briefly about these three systems.
SAP Conversational AI:
SAP Conversational AI formerly known as recast.ai is an end-to end bots platform build on robust natural language processing (NLP) technology. Using this platform, chatbots can be developed and trained for any customer use case and can be easily deployed on most of the user messaging channels like Webchat, Facebook messenger, twitter, slack etc.
SAP Cloud platform:
SAP Cloud Platform is SAP’s innovative cloud development and deployment platform. It is an enterprise platform-as-a-service (enterprise PaaS) that provides comprehensive application development services and capabilities, which lets you build, extend, and integrate business applications in the cloud.
It has two environments for application development- Neo and Cloud Foundry.
Neo: It is SAP Proprietary and supports only Java, HTML5 and HANA XS applications.
Cloud Foundry: It is based on the open-source application platform managed by the Cloud Foundry Foundation. It supports many languages including Node.JS, PHP, Java, Ruby, Python etc.
In our case, we use Cloud Floundry as a middleware to receive web-hook calls from SAP Conversational AI, to trigger OData calls to and from C/4 HANA SYSTEM using the Node JS Application hosted on it and send the response back to Bot. The Node JS app is invoked using webhooks in SAP Conversational AI.
Let us think of a simple use case where the user wants know the status of a service request he raised (here in C/4 HANA system). To develop the bot according to the use case we can divide the development process into 3 .
- Creation of chatbot using SAP Conversational AI
- Integration of Bot created on SAP Conversational AI with SAP Cloud platform.
- Development of Node.js application on SAP cloud platform and Integration with C/4 Hana system.
- Creation of chatbot using SAP Conversational AI:
- Create a new bot in SAP Conversational AI with Greetings as a Predefined skill.
- Create a new intent under train in bot and add different expressions to understand the user’s intent. An intent is box of expressions that mean the same thing but expressed in different ways by different users.
- Now create a new skill get Status under Build of the Bot builder.
- This Skill should be triggered if the intent GetStatus is identified in the chat. So the same condition is maintained in the Triggers under the Build of the Skill.
- For getting Status of the ticket bot requires ticket id(number). The user may say ‘get status of ticket 12345678’ or simply ‘get status of my ticket’.
In the former case bot automatically identifies the ticket id as the number which is a golden entity is present, but in the latter bot needs to ask the user for the ticket id.
Under the requirements tab under Build of the skill we store the number detected in the user expression as Ticket ID. If the Ticket id is missing in the expression, we will ask the user for the same.
- If Ticket ID is missing randomly anyone of the messages below will trigger to user. If the reply the bot sends is selected from a pool of messages the user won’t feel the bot being monotonous every time.
2. Integration of Bot created on SAP Conversational AI with SAP Cloud platform:
- Once the requirement is completed under the Actions tab in the Build of the skill a web-hook is called to get the status of the given ticket id from SAPC4C using node.js application running on SCP.
- The URL for webhook call routine is maintained in the Bot webhook base URL under the settings of the bot.
3. Development of Node.js application on SAP cloud platform and Integration with C/4 Hana system.
- Launch SAP Web IDE from the SAP Cloud platform cockpit. Enable the Tools for Node.js Extensions under Settings->Workspace Preferences->Extensions and Save.
- Create a new project in Workspace under File->New->Project from Template.
- Select Environment as Cloud Foundry and Template Multi-Target Application.
- Click on next, give a project name click on next and finish.
- Create a new Node.js module under the project. Give Module name as NodeModule and Main JS file as index.js
- Create a http Get request as shown in the below screenshot. The request header Authorization and tenant details can also be maintained in package.json file instead of hardcoding.
Please note that Authorization details should be base encoded. i.e the base64 encoded string of username:password.
Here in http request we are using SAP C4C standard OData service ServiceRequestCollection to get the status of the ticket by passing the ticket id received from user.
- In the package.json file add these node modules under devDependencies and save. These are the node modules we are using the application.
- Save the inde.js file. Now select the API end point settings for the project by right clicking on the project under ChatBot-GetStatus ->Project->Project Settings Project->Cloud Foundry->Cloud Foundry Settings.
- Select the API endpoint, Organization and Space and click on Save.
- Now Right click on NodeModule->Build->Build. After the Build is successfully completed we will get the message below in console log.
- Run the NodeModule as Node.js application. Once the application is up and running we can see the below message in the console log and URL for the application.
- This application URL is the URL maintained in the Bot Webhook base URL.
Now our Bot is ready let’s chat with the Bot and get the status of a ticket.
The Status in the C4C for the same ticket is the same as the reply we got in Bot.
Extensibility :
- We can create the bots according to any use-case and train it.
- CRUD operations can be performed in C/4 HANA systems using Standard OData services by extracting data from conversation with user.
- The bots developed on SAP Conversational AI can be deployed on most of the user messaging channels like Webchat, Facebook messenger, twitter, slack etc.
Hello! This is a very good example of how to create a Multi Target Application connected to an instance and a Chatbot. I tried making my own but for some reason it failed. Could you please share your js code maybe on Github? you can erase your authentication and OData URL.
Hello Ruby,
Thanks for this wonderful blog. Can you please share the js script, which will be of more help.
Thanks in advance..
I am getting problem while build. its showing error of routes. can anyone please help me? I am trying to implement it on trial account.
Hi Ruby
The js file which you had shown, I am not able to make it work. There are build issues. Is it possible to share the whole js file ?
Regards
Rahul
Hi,
The blog is really helpful. Can you please share the nodejs code as well? It will be really helpful.