Skip to Content
Technical Articles
Author's profile photo Sabine SMAI

Step by step SAP Intelligent RPA and SAP Conversational AI Integration (with input/output)

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:

  1. SAP Intelligent Robotic Process Automation  (Desktop studio) – Installed on your machine
  2. SAP Intelligent Robotic Process Automation (Desktop Agent) – Installed on your machine
  3. Factory – Access to upload project to cloud
  4. Client ID and Secret – To setup Integration
  5. SAP Conversational AI – To create chat bot
  6. 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 :

  • IO (folder)
    • ws_text
    • input

 

In the workflow properties you must define the “Input Data Manager” property and the Input and output :

also%2C%20in%20the%20properties%20define%20Input%2C%20Input%20Data%20Manager%20and%20Ouput%3A

 

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 :

create%20export%20of%20project%2C%20then%20import%20the%20package%20%u201CIntegrationB_4.0.zip%u201C.

 

Make sure that the scenario has been enabled “Make the scenario usable as a skill”, then click on I/0 :

Don%u2019t%20forget%20active%20Make%20the%20scenario%20usable%20as%20a%20skill%20After%20click%20on%20I/0%20we%20must%20have%20the%20input%20and%20output

 

Save and generated the package.

 

  • Create a trigger on an environment for this package , chose API, click on Create.

 

Then%20copy%20and%20paste%20in%20an%20editor%20text%2C%20it%20is%20also%20copy%20and%20paste%20the%20contain%20of%20the%20API%20Keys.

Use the copy button to copy the data into a text file. You will need it in the chatbot configuration.

 

The%20two%20important%20information%20from%20the%20Api%20Trigger%20are%20URL%20and%20the%20contains%20of%20Payload%20sample

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” :

Click%20on%20Button%20Blue%20%u201CNEW%20BOT%u201D

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

  • Choose Public

 

Then click CREATE A BOT, after few minutes you have this screen :

 

 

If you want, you can delete the Intents goodbye and greetings.

 

If%20you%20want%2C%20you%20can%20delete%20the%20Intents%20goodbye%20and%20greetings

Then you click on Create a new intent :

add%20your%20intent

 

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 :

Then%20click%20on%20the%20tab%20%u201CBuild%u201D%20And%20Add%20skill

 

Build

Then click on the tab “Build” and add skill

 

After you’ve clicked on Add the skill “integration_check” is created :

 

the%20skill%20integration_check%20is%20already%20created

 

 

Click on the link inside the skill which is called “integration_check” we see this screen :

 

click%20on%20the%20link%20inside%20the%20skill%20on%20integration_check%20we%20show%20this%20screen%3A

Triggers

Click on to the tab trigger and add a condition.

click%20on%20to%20the%20tab%20trigger

 

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 :

complete%20the%20fills%20and%20chose%20send%20message

 

This screen is displayed :

Add%20a%20condition%20Click%20on%20the%20tab%20requirements

 

Actions

Click on the tab actions, then Click on “CONNECT EXTERNAL SERVICE” then choose “CONSUME API SERVICE”.

After%20click%20on%20the%20tab%20actions%20then%20Click%20on%20%u201CCONNECT%20EXTERNAL%20SERVICE%u201D%20then%20chose%20%u201CCONSUME%20API%20SERVICE%u201D

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": ""
    }
}

 

You%20set%20the%20%u2018url%u2019%20of%20the%20trigger%20after%20POST

Fill the tab authentication and select OAuth2 Authentication:

Fill%20the%20tab%20autentification

 

Fill the Client Id, Client Secret and Authorization URL :

 

Fill%20the%20Client%20Id%2C%20Client%20Secret%20and%20Authorization%20URL

 

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

The%20contain%20of%20irpa-api-key%20is%20the%20contain%20of%20your%20API%20keys%20of%20your%20environment

Then fill the contains of the body

contains%20o%20the%20body

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 :

Click%20and%20rest%20conversation

Now we can trigger a job and check if that the job is in success into the factory.

We%20can%20test%20inside%20the%20chatbot%20if%20the%20bot%20is%20launched%2C%20with%20the%20parameter%20input

 

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

click%20on

 

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

  1. Choose Start (Notify on)
  2. Put it into the field token.
  3. And initialize the Conversation ID with ${invocation_context.conversationid}

 

For the second SAP Conversational AI notifier

  1. Choose Success (Notifier on)
  2. Put it into the field token.
  3.  Initialize the Conversation ID with ${invocation_context.conversationid}
  4. 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

click%20on%20create

Copy the information of the contain of Web Client script in an editor text, save with extension html

 

Copy%20the%20information%20of%20the%20contain%20of%20Web%20Client%20script%20in%20an%20editor%20text%2C%20save%20with%20extension%20html

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%20in%20the%20bot

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.

and see also this blog post.

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Paul PINARD
      Paul PINARD

      Hello Sabine,

      Thank you for this great blog post, pretty sure it will be useful for a lot of people!

      Would you be able to add the "SAP Conversational AI" tag in your article as a primary tag so people from the SAP Conversational AI community can see it as well?

      Regards,

      Paul

      Author's profile photo Drashti Patel
      Drashti Patel

      Hello Sabine SMAI

       

      I followed all the steps mentioned in your blog, but facing an error in iRPA factory - "Your job cannot be distributed because no agent is defined in your environment".

      Though I have added an agent and connected it with my local desktop agent.

       

      Regards,

      Drashti

      Author's profile photo Sabine SMAI
      Sabine SMAI
      Blog Post Author

      Hi,

       

      Have you share your agent with the agent group see in the doc help portal :

      https://help.sap.com/viewer/c836fab4182e45548b6c6c6d0d0a9146/Cloud/en-US/bf1d5916a4b9478e8aa99708ec1dcde1.html

      in the factory can you see your agent :

       

       

      Regards,

      Sabine

      Author's profile photo Vladimir Kosovtsev
      Vladimir Kosovtsev

      This is actually brilliant one, Sabine. As far as the info on this matter is scarce or spreaded all over the blogs and help topics but never sufficient, this one is so much helping.

       

      Tho I can't  still figure out about that Token field in p.4 Notifications, and can't understand why invocontext in_RPA is like conversation_id while RPA_out is like conversationid.

      1. Choose Success (Notifier on)
      2. Put _it_ into the field token. It what? Can't figure this out.

      Oh, sorry, that is the Developer token

      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

      thank you, you're actually a hero. Kindest regards.