Technical Articles
How to provision voice enabled AI based chat bot to your SAP ME System
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 .
- SAP MII and SAP ME
- SAP Cloud Platform
- SAP Conversational AI
- 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.
Excellent blog Supriya!
Thank you so much!
Superb blog on an innovative idea!
Thank you so much.
Great blog Supriya, congrats!
Thanks a lot.
Good Job, Well done.
I got a question if you a spare minute to message me. thanks
Thanks .Yes,you can ask your question.
Hi,
I am trying to follow your instruction to connect with ArcGIS Server through the Rest services instead of using the food bot. but it's seem I am missing somenthing.
What I am trying to do is to have the chatbot ask a question and then pass the input as a query string to arcgis server using the json and get the replay
Any idea what should I do ?
Thanks
Yes you can do it . Please check if ArcGIS Server can be accessed though Rest API , try to run APIs from ArcGIS Server using any REST Client (For example POSTMAN) ,check if you can access or pass data to the server .If you can then you can very well build your conversational flow using SAP Conversation AI .
Hi there,
I am not sure about POSTMAN , but I am sure about the json and rest JavaScript API.
Do you have video to follow , I wonder if you can ping me when you have time to chat .
my email account is moaen.mustafa@gmail.com if you use Google Duo