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: 
Hello Guys,

Welcome to Part 2 of the series SAP Conversational AI Overview & Build your first BOT.

In this blog post, I'll be touching the area, which I believe most of you have been waiting with bated breath.

SAP Conversational AI + S4HANA Cloud

At the end of this post, you'll be able to pull records/status from your S4HANA Cloud System by just chatting with your bot, and you won't even have to log in to your S4HC system.

Sounds cool.... right!! ?

Before diving directly into the integration part, let me make a few points about S4HANA Cloud.

S4HANA Cloud integrates with any other system using APIs. For every Business Context like Purchase Order, Sales Order, Purchase Requisition, etc. SAP has provided a set of whitelisted APIs which are listed at SAP API Business Hub.

At the time of writing this blog post, SAP has released 365 APIs for S4HANA Cloud.

Now a question arises in mind, what if I need to use my custom data or have a custom API with customized data. Here comes into action the two beneficial objects which SAP calls Custom CDS Views and Custom Business Objects. Both of these data objects can be exposed as custom APIs for consumption.

To summarize, we have the following 3 methods to integrate with S4HANA Cloud:

  • Using standard whitelisted APIs

  • Creating custom CDS views and exposed as API

  • Creating custom business objects and exposed as API


For the sake of simplicity and understanding, we'll be working on a use case that involves Custom Business Objects(CBO).

The whole use case consists of 3 parts:

  1. Creating a Custom Business Object in S4HC and exposing as API.

  2. Developing a nodeJS web server that is deployed on SAP Cloud Platform - Cloud Foundry environment. This web server acts as a middleware between CAI and S4HC.

  3. Adding intents and skill to your bot.


Part 1 - Creating CBO in S4HC


Step 1 - Login to your S4HC system and open app Custom business objects.


Step 2 - Create a new CBO with the name 'NEW_MATERIALS.'


Make sure to check the below-highlighted properties of CBO.


 

Add the following fields, this CBO can hold the data for new materials which can be added manually and finally Publish the CBO.


 

Step 3 - Once the CBO is published and UI is generated.

Click on the Go to Generated UI link and add a few entries into the CBO.


 


 

Step 4. Now we need to expose the created CBO as an API for consumption outside the S4HANA system. This process involves a few steps like

  • Create a communication user

  • Create a communication system

  • Create a communication scenario

  • Create a communication arrangement


Create a communication user using the app 'Maintain Communication User.'


Create a communication system using the app 'Communication System.'


Now under the 'Users for Inbound Communication' section, assign the communication user created in the previous step and save.


 

Create Custom Communication Scenario using the app 'Custom Communication Scenario.'



Now add the CBO, which we created in Step 2  as the inbound service and publish.


Now got to the communication arrangement tab and create a new arrangement.


Assign the communication system to the arrangement and save the communication arrangement.

Now our custom data service is ready.



Part 2 - Develop a Node.js webserver


Step 1 - Create a nodejs application and deploy it on SAP Cloud Platform - Cloud Foundry environment.

This nodejs application will interact with the custom Odata service using which we can access the S4 HANA  Cloud system.
const request = require('request')
const express = require('express')
const bodyParser = require('body-parser')

var app = express()
app.use(bodyParser.json())

app.post('/getmaterialdetails', (req, res) => {
const material = req.body.conversation.memory.material.raw
const url =
'https://myXXXXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/YY1_NEW_MATERIALS_CDS/YY1_NEW_MATERIALS?$filter=MaterialNumber eq \'' + material +
'\'&$format=json'
request.get(url, (error, response, body) => {
if (error) {
res.json({
replies: [{
type: 'text',
content: 'Material Not Found'
}]
})
} else {
var temp = JSON.parse(body)
res.json({
replies: [{
type: 'text',
content: 'For material ' + material + ' details are: '
},{
type:'text',
content: 'Material Description : '+temp.d.results[0].MaterialDescription +'\n Quantity :'+temp.d.results[0].Quantity_V
} ],
})
}
}).auth(<Communication User>, <Password>)
})

 

Step 2 - Deploy the nodejs application on the SAP Cloud Platform.

Step 3 - Use the deployed application URL with the proper path as a webhook of skill in SAP CAI.

 

Part 3 - Create intent and skills in CAI


Step 1 - Create an intent with certain expressions for fetching the details of a particular material from the S4HC system.


 

Step 2 - Specify the entity for each expression, as shown below.

Step 3 - Create skill with trigger conditions as below.



Step 4 - Specify the requirements and save the material number in bots memory.


Step 5 - Add webhook as the actions in the skill and provide the Nodejs webserver URL with the correct path.


 

Now you can test your bot.



You can verify the details from S4 HANA Cloud System.







Upcoming topics in this series of the blog:

  •  SAP CAI + S4HANA Cloud + Whatsapp = A marvelous user experience!


Stay tuned for more upcoming fantastic stuff.

 

I hope you all have enjoyed this blog post, and I've been able to make myself clear. Please let me know your thoughts, doubts in the comment section below, and if you enjoyed, please like and share.

Wishing excellent health and safety to all of you and your friends & families.

 
4 Comments
Labels in this area