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: 
supmalak93
Participant
2,487
Artificial intelligence-based voice enabled chat bot for MES system would be great asset for any manufacturing company. Through voice/chat commands shop floor operators can interact with the system while doing their operational activity and Supervisor or business personal can easily look into any report.

Today in this blog I will show how to develop a voice based chat bot application for your SAP ME system step by step.

 

Prerequisites:You need to have access to below mentioned systems .

  1. SAP MII and SAP ME

  2. SAP Cloud Platform

  3. SAP Conversational AI

  4. SAP Cloud Connector


Step 1: Configure cloud connector for SAP MII system:

The cloud connector serves as the connection between applications in SAP Cloud Platform and existing on-premise systems. To configure cloud connector with SAP MII system you can refer this blog .

https://blogs.sap.com/2016/08/01/cloud-connector-configurations-for-sap-mii/

 

Step 2: Create Transactions in SAP MII:

Write transactions(BLS) in SAP MII which will interact with SAP ME system. For example if you want to execute SFC(Shop floor control) write transactions to start an SFC, Do data collection for that SFC , Complete and SFC.

 

Step 3: Develop Rest APIs in SAP Cloud Platform:

Once you performed Step 1, your MII system is connected with SAP Cloud Platform using Cloud Connector, Now you can develop Rest APIs in SAP Cloud Platform which will call your MII transactions .

You can’t directly call your SAP MII transactions from SAP CAI as most of the time MII/ME system is not exposed to public network and other reason is SAP CAI supports https type of service only ,for this reason you can develop services in SAP Cloud Platform which will create a secure public Rest API for your SAP MII transactions.

I have used Node.js as a programing language for developing APIs. Steps to develop Rest APIs in SAP Cloud Platform for SAP MII/ME Transactions.

 

Step 3.1 : Create a destination in SAP Cloud Platform  and configure it with proper URL that you have used while configuring Cloud Connector as part of Step 1.


 

Step 3.2: You can now use ‘sap-cf-axios’ Node JS module to develop your API in SAP Cloud Platform which will call your MII transaction though SAP Cloud Platform Destination service.

Sample source code :
var SapCfAxios = require('sap-cf-axios').default;

var axios = SapCfAxios('put your SCP Desinatination name');

var config = {
method: 'GET',
url: '/XMII/Illuminator?QueryTemplate=' + query,
headers: {
"content-type": "application/json"
},

}
try {
let resp = await axios(config);

return res.type("application/json").status(200).send(resp.data);
} catch (error) {
console.error('MII Destination Calling error===>>>' + error);
return res.type("text/plain").status(500).send(JSON.stringify(error));
}

 

Step 3.3: You can create also create XSUAA service instance for your application and bind it to provision oAuth authentication to your developed APIs.

Once you application is deployed, open your application instance in SAP Cloud Platform Cockpit and go to Environment variable section and look for “xsuaa” node, there you will find clientid, clientsecret and url . Please take a note of that.

 

You can create and bind all mentioned service instance either though SAP Cloud Platform Cockpit or though mta.yml file

 

Step 4 : Develop and build SAP Conversational AI Conversational flow:

Now you are done with all service creation, only part pending is building conversational flow using SAP Conversational AI.

Step 4.1: First you need to define Intents and Entities and train your Bot with those data, It will help the bot to understand the phrases or sentences from your command. For example if you want to start one SFC  , you can create Intent @StartSFC and train it with phrases like “I want to start SFC 1234 at Operation ABC and Site XYZ”,”Please start SFC 1234 at Operation ABC and Site XYZ” etc and identify SFC number as #NUMBER(Golden Entity in CAI) Entity, Operation number as #OPERATION Entity and Site as #SITE Entity.

Step 4.2: You need to create a skill in SAP CAI for performing a action. In this section I will discuss about one particular skill but same way you can define other skills based on your need .I will show STARTSFC skill which will perform SAP ME start SFC transaction.

Create a Skill called STARTSFC and specify @StartSFC Intent (created in previous step) as triggering Intent of this skill and in the Requirement section check if  SFC, Site, Operation number is present in the Phrase user provided, if not ask user for that and save the SFC, Site, Operation number in memory variable called SFC, Site, Operation.

Step 4.3: Once you are having all required parameter for your transaction to execute (for this case Start SFC is the transaction), you can go to Action tab of your skill and specify the API URL you have created in Step 3 and pass all necessary parameter in URL( For GET request) or in body(For POST Request) . Choose OAuth2 Authentication as authentication type and provide Client ID, Client Secret , Authorization URL which you got from step 3.3.

Now your bot is ready with Start SFC skill , train the bot also you can execute it from CAI tool .


 

Step 5 : Develop a interface for your chat bot and enable voice :

Now its time to give a interactive user interface to your chat bot application which I have developed using SAPUI5 . I have created one SAPUI5 Fragment with a button at bottom right to the corner of dialog, on click of which I am listening to user’s voice command. You can refer below pasted code for speech to text conversion and once you get the text out of speech need to call SAP CAI dialogue flow API (https://api.cai.tools.sap/build/v1/dialog) and pass your message.
	var recognition;
try {
//var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
recognition = new window.webkitSpeechRecognition();
}
catch(e) {

$('.no-browser-support').show();
$('.app').hide();
}
recognition.continuous = false;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.start();

recognition.onresult = function (event) {

var vInWrittenVal=event.results[0][0].transcript;
//here capturing the text from voice commands
//Need to pass the text to SAP CAI Dialog flow by calling https://api.cai.tools.sap/build/v1/dialog
};

 

Conclusion:

After performing mentioned steps you will be able to talk to your SAP ME system and perform necessary operations.
11 Comments
Labels in this area