Integrate Chatbot with SAP Build Process Automation
- How to add API Trigger and Notifiers to an automation
- How to send data from a chatbot and trigger an automation in Unattended mode
Prerequisites
In this tutorial you will retrieve the specific Sales Order details through a chatbot (SAP Conversational AI) that interacts with your SAP Build Process Automation project.
- Step 1
-
Open the project you created in SAP Build Process Automation Application Capture.
-
Add Agent Attribute.
-
Release the project.
-
Deploy the project. Click Deploy.
-
Select Create a Trigger and click Next.
-
Select API and click Next.
-
Select Get Order Details From Application automation and click Next.
-
Set Name to Get Order Trigger and click Next.
-
Click Confirm then hit Deploy.
The project is now deployed.
Log in to complete tutorial -
- Step 2
Go to lobby landing page of SAP Build.
Go to Settings > API Keys.
To create your API Key. Click Add API Key.
Set Name to
myAPIKey
and click Next.- Select both options
trigger_read
andtrigger_execute
and click Next.
- Select both options
Click Add.
Click Copy and note down what was just copied to your clipboard.
It’s important to save your API Key, since it can only be read once from the Setting.
Your API Key is now created and ready to be used.
Log in to complete tutorial - Step 3
Navigate to SAP BTP Cockpit subaccount > Services > Instances and subscriptions.
Choose Create.
For the new instance:
- Select SAP Build Process Automation as Service.
- Select Standard Instance plan from the Plan list.
- Select Other as Runtime Environment.
- Set Instance Name as SPA-instance.
- Choose Create.
The instance is now added.Create a new Service Binding by selecting your SPA-instance instance > Select … to expand > Create Service Binding.
Put the name as
myServiceBinding
and click Create.Click … and then click View to view the Service Binding created.
Click Form and copy the
clientid
,clientsecret
and URL under theuaa
section. You will need it in the next steps.
Log in to complete tutorial - Step 4
- Navigate to Home > Monitor > Manage > Automations.
- From the shown triggers:
- Find your trigger (Created in Step 1.4 during deployment).
- Click on Actions and select Edit.
Copy URL and Payload.
You can notice that the inputs of the automation are specified in the request body also called as the Payload.
Log in to complete tutorial - Step 5
A ready CAI bot is used here.
This bot has a goal of emitting an API Call to SAP Build Process Automation using API Trigger, API Key and Service Binding we created previously.Using CONSUME API SERVICE feature in Conversational AI bot we can make API Calls.
Set URL to the one saved in step 4.
For Authentication tab:
- Set Authentication type to OAuth2 Authentication.
- Set Client ID, Client Secret and Authorization URL to those saved in step 3.
For Authorization URL add
/oauth/token
at the end of the URL.
For Headers tab:
- Click + New Fields to create a new field.
- Set Key to
irpa-api-key
and Value to the one saved in step 2.
For Body tab:
- Select Create a custom body.
- Paste the following:
JSONCopy{ "invocationContext": { "conversationId": "{{conversation_id}}" }, "input": { "orderNumber": "Order {{memory.orderNumber.raw}}" } }
memory.orderNumber.raw
is just a variable where an order number given by a user is stored.Click Save to save your changes.
- Step 6
To get Bot Developer Token:
- Go to Settings > Tokens.
- Note Developer Token somewhere and save it.
To get
Designtime API Token
:- Click Generate besides
Designtime APIs
. - Select Client Credentials and click Next.
Note Auth URL, Client ID and Client Secret somewhere and save it.
Don’t confuse these 3 information with those of the service binding’s.
We now have the proper tokens to create Notifiers.- Click Generate besides
Log in to complete tutorial - Step 7
Navigate to Home > Monitor > Manage > Automations.
Start Notifier:
- Click three dots under Actions in the same row as your Trigger.
- Select Add Notifier.
- Select CAI and click Next.
- Create the notifier as such:
Field Name Value Notify on Start Name Starting notifier Description Indicates that the automation has started Conversation ID ${invocation_context.conversationId}
Token Developer token from step 6.1
Auth URL Designtime APIs
token Auth URL from step6.2
Client ID Designtime APIs
token Client ID from step6.2
Client Secret Designtime APIs
token Client Secret from step6.2
What do you want to do? Send a message Delay in second 0 Message content IRPA: Bot Started. - Click Create.
Success Notifier:
- Click under Actions in the same row as your Trigger.
- Select Add Notifier.
- Select CAI and click Next.
- Create the notifier as such:
Field Name Value Notify on Success Name Success notifier Description Indicates that the automation has finished successfully Conversation ID ${invocation_context.conversationId}
Token Developer token from step 6.1
Auth URL Designtime APIs
token Auth URL from step6.2
Client ID Designtime APIs
token Client ID from step6.2
Client Secret Designtime APIs
token Client Secret from step6.2
What do you want to do? Send a message Delay in second 0 - Set Message content:
${output.order.orderNumber}: Price: ${output.order.orderAmount}€. Status: ${output.order.orderStatus}. Order Date: ${output.order.orderDate}. Country: ${output.order.shippingCountry}.
- Click Create.
- Click
Error Notifier:
- Click under Actions in the same row as your Trigger.
- Select Add Notifier.
- Select CAI and click Next.
- Create the notifier as such:
Field Name Value Notify on Failure Name Failure notifier Description Indicates that the automation has failed Conversation ID ${invocation_context.conversationId}
Token Developer token Auth URL Designtime APIs
token Auth URLClient ID Designtime APIs
token Client IDClient Secret Designtime APIs
token Client SecretWhat do you want to do? Send a message Delay in second 0 Message content Automation failed with error: ${error.details}
- Click Create.
The three notifiers are now created.- Click
- Step 8
Open your SAP Conversational AI chatbot.
Click Connect tab.
Click on SAP Conversational AI Web Client.
Put CAI with IRPA in Channel Name and click Create.
Click on the Web Client standalone link to open the chatbot in browser.
The chatbot opens in a new window.
Make sure your Desktop Agent is in Background (Unattended) mode.
To start my bot I type Start my automation according to what I set it up to respond to (Execute the API call) after asking for an order number.
The workflow of the execution:
- The process starts with the user triggering it in the chatbot (sending Start my automation).
- The chatbot asks for an Sales Order Number which will be used as an input for our automation.
- Once the Order Number is submitted by the user, the bot sends the API Request to SAP Build Process Automation according to what we configured it, and displays CAI Bot: Emitting the API Call.
- Once the API Request is reached, the SAP Build Process Automation Start notifier sends back a message declaring its start: IRPA: Bot Started.
- Upon a successful execution of the automation, the Success notifier is triggered and the Sales Order’s details are returned to the bot that displays them.
Log in to complete tutorial