Introduction
There is already a
blog post on this subject but I wanted to go deeper into this subject, in particular by specifying how to define an input from a response from the SAP Conversational AI to SAP Intelligent RPA and an output from SAP Intelligent RPA to SAP Conversational AI.
Main Part:
The prerequisites are:
- SAP Intelligent Robotic Process Automation (Desktop studio) – Installed on your machine
- SAP Intelligent Robotic Process Automation (Desktop Agent) – Installed on your machine
- Factory – Access to upload project to cloud
- Client ID and Secret – To setup Integration
- SAP Conversational AI – To create chat bot
- Chrome web browser – Live the chat bot
1 . To do a project with input and output
Open Desktop Studio.
After creating a project, when we add the workflow, it is very important to define in the context.
We will create a context like this :
In the workflow properties you must define the "Input Data Manager" property and the Input and output :
This project is very simple, it will read a text file and send the content in output.
- The first activity is Read text :
- And the second is the activity Log :
You will find the generated code here, I just added a line of code to log the input parameter in the step "Read_a_text_file".
// ----------------------------------------------------------------
// Step: Read_a_text_file
// ----------------------------------------------------------------
GLOBAL.step({ Read_a_text_file: function(ev, sc, st) {
var rootData_IO = sc.data;
ctx.workflow('integration', '1ed531ff-0e07-4acd-943e-d72247328ee0') ;
ctx.log("param entry :" + rootData_IO.input+ ".", e.logIconType.Info);
// Reads the content of a text file.
var file = ctx.options.path.local + "\\sample.txt";
var text = ctx.fso.file.read(file, e.file.encoding.UTF8);
rootData_IO.ws_text = text;
sc.endStep(); // Write_log
return;
}});
// ----------------------------------------------------------------
// Step: Write_log
// ----------------------------------------------------------------
GLOBAL.step({ Write_log: function(ev, sc, st) {
var rootData_IO = sc.data;
ctx.workflow('integration', 'ed195c97-52af-42e1-8e65-f0f9577fee91') ;
// Add a message to the log file and in the debug window along with a severity level.
ctx.log(rootData_IO.ws_text, e.logIconType.Info);
sc.endStep(); // end Scenario
return;
}});
Save the project test and create an export of the project (Menu File -> Export Project).
2 . In the factory:
Import the package “IntegrationB_4.0.zip“ (export package of the project) into factory :
Make sure that the scenario has been enabled "Make the scenario usable as a skill", then click on I/0 :
Save and generated the package.
- Create a trigger on an environment for this package , chose API, click on Create.
Use the copy button to copy the data into a text file. You will need it in the chatbot configuration.
The two important information from the Api Trigger are "URL" and the contains of "Payload sample"
You have also to retrieve the apiKEY into the environment and save the value in a text file
At this time, we can test the bot with a launch with postman see the documentation:
add a trigger of type API
3. Create a chatbot
See the documentation of SAP Conversational AI :
Here
On your home Page click on New Bot :
Click on “Perform Actions” :
Once you have click you will arrive on this page :
Now you have to choose some options :
2 - Select predefined skills for your bot
- You can choose “Greetings”
3 – Create your bot
- You fill the name of your SAP Conversational AI ( here I have choose bintegration)
4 – Data Policy
- Choose Non-personal
- Choose Store
- Choose Non-vulnerable
5 – Bot visibility
Then click CREATE A BOT, after few minutes you have this screen :
If you want, you can delete the Intents goodbye and greetings.
Then you click on Create a new intent :
For my chatbot I have delete the intents goodbye and greetings and create a new intent system.
Click on the intent system :
You can add expressions or delete this :
Build
Then click on the tab “Build” and add skill
After you've clicked on Add the skill "integration_check" is created :
Click on the link inside the skill which is called "integration_check" we see this screen :
Triggers
Click on to the tab trigger and add a condition.
Requirements
Click on the tab requirements
Enter #person as input :
Then click on NEW REPLIES , (for the case If
#input is missing) and click on SEND MESSAGE
Choose Text then Type the message "give your name please ?" and save :
This screen is displayed :
Actions
Click on the tab actions, then Click on “CONNECT EXTERNAL SERVICE” then choose “CONSUME API SERVICE”.
Set the ‘url’ of the trigger (see below contains of URL ) in the API Service Configuration after POST.
HTTP Method: POST
URL: https://api.xxxxxxxxxxxxxxxxxxxxxx.com/runtime/v1/apiTriggers/47a38323-xxxxx-xxxxxx42819/runs
Input schema: {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "Inherited from IntegrationC."
}
}
}
Payload sample: {
"invocationContext": "${invocation_context}",
"input": {
"input": ""
}
}
Fill the tab authentication and select OAuth2 Authentication:
Fill the Client Id, Client Secret and Authorization URL :
Ask your administrator to provide the following information :
- Client ID.
- Client Secret.
- Access Token URL: you need to copy this from the url property in the service key. You will find the url property under uaa
You need to add the suffix "/oauth/token" to this URL to form the Access Token URL :
https://uaa-url-domain-. .com/oauth/token
The value of irpa-api-key is the API key of your environment
Then fill the contains of the body
With this payload
{
"invocationContext": {
"conversationid" : "{{conversation_id}}"
},
"input": {
"input": "{{memory.input.raw}}"
}
}
The first element defines the conversationid
The second element of the body is the structure of the second element of the Payload sample of your Api Trigger, the contains will be the information of the answer from the chatbot : "{{memory.input.raw}}".
Then it is important to add this option at the end of the action UPDATE CONVERSATION , then choose RESET CONVERSATION :
Now we can trigger a job and check if that the job is in success into the factory.
4 . Now we can add SAP Conversational AI Notifier
Into the factory you have to add at least one SAP Conversational AI notifier on your API trigger.
Here, I have initialized 2 SAP Conversational AI notifiers, the first will be triggered when the bot starts and the second if the bot has been executed successfully. (you can add others CAI notifiers).
Before to do this you have to retrieve the token of your chatbot.
To do this in the chatbot configuration click on setting on the top right and copy the Developer token
On your environment of the factory click on add Notifier of the trigger.
Select CAI , click on Next
For the first SAP Conversational AI Notifier
- Choose Start (Notify on)
- Put it into the field token.
- And initialize the Conversation ID with ${invocation_context.conversationid}
For the second SAP Conversational AI notifier
- Choose Success (Notifier on)
- Put it into the field token.
- Initialize the Conversation ID with ${invocation_context.conversationid}
- In the message content put : Success !!!! result : BOT ${output.ws_text} :
The SAP Conversational AI notifier must be tested from a web page:
To make the contains of this web page in the chatbot
In the tab connect of the chatbot configuration, click on create
Copy the information of the contain of Web Client script in an editor text, save with extension html
Code in the editor text :
When you have launched this page in a browse you will see this result
"Hello from my IRPA bot" send when the bot start
"Success !!!!
result : Le monde est vaste , explorons le." is sent when the bot finish with success
Logs in the bot
Conclusion
Now you know exactly how to define parameters between SAP Intelligent Robotic Process Automation and SAP Conversational AI. If you face any difficulties in implementing the above process steps, you can leave your comments or queries in this blog post, will try my best to respond at the earliest.
Thanks for your time!
Sabine Smaï
Learn More
For more information on interface of SAP Intelligent RPA and SAP Conversational AI.
Do check out this
blog post where we can also avoid node service implementation.