Skip to Content

Integrate Chatbot with SAP Process Automation

Integrate SAP Process Automation with SAP Conversational AI using API Triggers and Notifiers
You will learn
  • How to add API Trigger and Notifiers to an automation
  • How to send data from a chatbot and trigger an automation in Unattended mode
shielddzIlyes YamounNovember 7, 2022

In this tutorial you will retrieve the specific Sales Order details through a chatbot ( SAP Conversational AI ) that interacts with your SAP Process Automation project.

  • Step 1
    1. Open the project you created in SAP Process Automation Application Capture.

    2. Add Agent Attribute. (Complete Agent Management Settings)

      Agent Attribute
    3. Release the project.

      Release the project
    4. Deploy the project:

      • Click Deploy.
      Deploy button
      • Select Create a Trigger and click Next.
      Trigger creation
      • Select API and click Next.
      Trigger type selection
      • Select Get Order Details From Application automation and click Next.
      Trigger automation selection
      • Set Name to Get Order Trigger and click Next.
      Trigger Name
      • Click Confirm then hit Deploy.
      Confirm and deploy project

    The project is now deployed.

  • Step 2
    1. Go to lobby landing page of SAP Process Automation.

      Lobby Page
    2. Go to Settings > API Keys.

      API Keys page
    3. To create your API Key:

      • Click Add API Key.
      Add API Key
      • Set Name to myAPIKey and click Next.
      • Select both options trigger_read and trigger_execute and click Next.
      Select Scope
      • Click Add.
      Add button
      • Click Copy and note down what was just copied to your clipboard.
      Copy API key

      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.

  • Step 3
    1. Navigate to SAP BTP Cockpit subaccount > Services > Instances and subscriptions.

    2. Choose Create.

      Navigate to instances and subscriptions
    3. For the new instance:

      • Select SAP 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.
      Instance details

    The instance is now added.

    1. Create a new Service Binding by selecting your SPA-instance instance > Select to expand > Create Service Binding.

      Navigate to Service Bindings creation tab
    2. Put the name as myServiceBinding and click Create.

      Name the service binding and create it
    3. Click and then click View to view the Service Binding created.

      View Service Binding
    4. Click Form and copy the clientid, clientsecret and URL under the uaa section. You will need it in the next steps.

      Note down information
  • Step 4
    1. Navigate to SAP Process Automation > Monitor > Manage > Automations.
    2. From the shown triggers:
      • Find your trigger (Created in Step 1.4 during deployment).
      • Click on Actions and select Edit.
      Edit Trigger
      • Copy URL and Payload.
      Copy Info

      You can notice that the inputs of the automation are specified in the request body also called as the Payload.

  • Step 5

    A ready CAI bot is used here.
    This bot has a goal of emitting an API Call to SAP 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.

    1. Set URL to the one saved in step 4.

      Set URL
    2. 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.

      Authentication tab
    1. 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.
      Headers tab
    2. For Body tab:

      • Select Create a custom body.
      • Paste the following:
      JSON
      Copy
      {
          "invocationContext": {
          "conversationId": "{{conversation_id}}"
          },  
          "input": {
              "orderNumber": "Order {{memory.orderNumber.raw}}"
          }
      }
      
      Body tab

      memory.orderNumber.raw is just a variable where an order number given by a user is stored.

    3. Click Save to save your changes.

    Is adding /oauth/token to the Authentication URL mandatory?

  • Step 6
    1. To get Bot Developer Token:

      • Go to Settings > Tokens.
      • Note Developer Token somewhere and save it.
      CAI Developer token
    2. 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.

      CAI Designtime API token

    We now have the proper tokens to create Notifiers.

  • Step 7
    1. Navigate to SAP Process Automation > Monitor > Manage > Automations.

      Find Trigger
    2. Start Notifier:

      • Click
        More Options button
        under Actions in the same row as your Trigger.
      More options in screen
      • 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 step 6.2
      Client ID Designtime APIs token Client ID from step 6.2
      Client Secret Designtime APIs token Client Secret from step 6.2
      What do you want to do? Send a message
      Delay in second 0
      Message content IRPA: Bot Started.
      • Click Create.
    3. Success Notifier:

      • Click
        More Options button
        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 step 6.2
      Client ID Designtime APIs token Client ID from step 6.2
      Client Secret Designtime APIs token Client Secret from step 6.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.
      Create Notifiers
    4. Error Notifier:

      • Click
        More Options button
        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 URL
      Client ID Designtime APIs token Client ID
      Client Secret Designtime APIs token Client Secret
      What do you want to do? Send a message
      Delay in second 0
      Message content Automation failed with error: ${error.details}
      • Click Create.
      Create Fail Notifiers

    The three notifiers are now created.

    Will a Success notifier work if a Start notifier isn't created?

  • Step 8
    1. Open your SAP Conversational AI chatbot.

    2. Click Connect tab.

    3. Click on SAP Conversational AI Web Client.

      SAP Conversational AI Web Client
    4. Put CAI with IRPA in Channel Name and click Create.

      Create Channel
    5. Click on the Web Client standalone link to open the chatbot in browser.

    6. The chatbot opens in a new window.

      Open Chatbot in new Window

      Make sure your Desktop Agent is in Background (Unattended) mode.

      Put Agent in unattended mode

    7. 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.

    8. 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 Process Automation according to what we configured it, and displays CAI Bot: Emitting the API Call.
    • Once the API Request is reached, the SAP 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.
    Response From SPA

Back to top