Trigger SAP Build Process Automations with Alexa
2023-11-8 03:37:45 Author: blogs.sap.com(查看原文) 阅读量:10 收藏

Introduction

Hello SAP community,

Have you ever wondered how amazing it would be to operate within your SAP system simply by using the power of your voice?

In this blog post, I’d like to share my experience with you regarding the integration of an SAP system with an external digital voice assistant. For this project, I utilized the Amazon Alexa digital voice assistant for voice recognition, coupled with SAP Build Process Automation to construct automations that can be triggered via Alexa.

I will provide a comprehensive, step-by-step guide from the very beginning, explaining the settings and tools you need to initiate an automation process in SAP using voice commands.

The connection between SAP and Alexa offers a large number of possibilities, ranging from launching Fiori Apps to automating extensive business processes—all initiated with a simple voice command. Feel free to experiment! Additionally, it’s worth noting that the implementation described here is not limited to Alexa as a digital voice assistant. With a few adjustments, you can adapt this approach for use with various other voice assistants or even create your own.

What do I need for the connection?

  • SAP Build Process Automation (Standard Plan)
  • Amazon Developer Account (in Demo version for free)
  • Roles in SAP BTP: ProcessAutomationAdmin, SubaccountAdmin

Architecture

Before we dive into the details, let me provide you with some insights into how Alexa and SAP Build Process Automation cooperate in the following implementation:

Architecture%20of%20the%20connection%20between%20SAP%20and%20Alexa

Architecture of the connection between SAP and Alexa

When a user issues voice commands to the Alexa speaker, Alexa processes the spoken text using natural language processing. Alexa then associates the text with a predefined intent, which is further linked to a corresponding intent handler. Inside the intent handler (the backend code), we perform two essential post-requests:

  1. The first post-request is responsible for handling authorization and generating an access token.
  2. The second post-request is used to effectively trigger the automation within SAP Build Process Automation.

The triggered automation will be loaded into the Desktop Agent and executed from there.

Let’s get started

Now that we understand how Alexa and SAP can seamlessly collaborate, it’s time to initiate the connection.

We’ll commence within the SAP Business Technology Platform (BTP) by configuring a few settings, enabling us to begin working with SAP Build Process Automation to create the automation that we intend to activate through Alexa. To effectively utilize SAP Build Process Automation, it’s imperative not only to have the necessary permissions to access it via the cloud web interface but also to install the Desktop Agent locally on every computer where you intend to initiate automations. You can download the Desktop Agent from the following link: https://tools.hana.ondemand.com/#cloud.

Once we’ve constructed an automation, we’ll proceed to develop a skill and an intent within Amazon’s Developer Console. Here, we’ll implement the two POST methods in the backend code to trigger the automation that we created in the preceding steps.

Configurations in SAP BTP

If you haven’t already done so, the initial step involves creating an instance of SAP Build Process Automation. This instance will provide us with a key that contains essential information required for the subsequent POST requests. To create an instance, follow these steps:

  1. Navigate to “Instances and Subscriptions” within your SAP Build subaccount in the SAP Business Technology Platform (BTP).
  2. Click on the “Create” option.
  3. Fill in the necessary information as depicted in the image below, ensuring that you also specify your own runtime environment.

By completing these steps, you will have the required instance of SAP Build Process Automation and the associated key with the essential information for your POST requests.

Create%20new%20Instance

Create new Instance

Connect Desktop Agent to SAP Build Process Automation

To fully leverage the capabilities of your SAP Build Process Automation Application, it’s crucial to establish a connection between the Desktop Agent and the application. To guide you through this process, please refer to the following video tutorial:

While the user interface design may have undergone some changes, the video remains relevant and will provide you with the necessary steps to connect the Desktop Agent with your application.

Build your SAP Build Process Automation

Now it’s time to create your own automation. To get started, you can refer to one of the many SAP tutorials available.

When initiating a new project, I typically opt for “Automated Processes,” and within this category, I select “Business Processes.” Within Business Processes, you can seamlessly integrate automations. These automations can be built from scratch, but personally, I often use the “Screen Capture” feature. To access “Screen Capture,” add an Application to your project. When you do this, a pop-up window will appear, allowing you to enable the Screen Capture functionality. This essentially means that you can record your screen clicks, and the tool will automatically generate code based on your captures.

Feel free to test your application during the development phase using the integrated testing tool. This will help you ensure that your automation functions as expected and meets your requirements.

Add a trigger

Now that your automation is built and you’ve confirmed its functionality through testing, it’s time to add a trigger to your process. To achieve this, follow these steps:

  1. Begin by releasing and deploying your project.
  2. Next, navigate back to the “Process” tab of your project.
  3. Add an API Trigger as shown in the following image.
  4. After creating the trigger, the application will guide you to the Monitor tab of the SAP Build Application. Alternatively, you can manually navigate there by leaving your project, clicking on “Monitor” in the top bar of the SAP Build Process Automation start page, and opening the “Triggers” tab.
  5. Within the “Actions” column of each trigger, click on the three dots, then select “View.” This action will open a pop-up window, providing you with the Trigger-URL and a definitionID, both of which you will need for the Post-Request later on.

(Note: If you don’t see the “View” button, please double-check that you have deployed the project in which the trigger was created.)

Add%20a%20API-Trigger

Add a API-Trigger

Create an Alexa Skill and an Intent

At this stage, we’ve completed the implementations and configurations within SAP Build Process Automation, and it’s time to shift our focus to the Amazon Developer Console.

If you haven’t already, please sign in to the Amazon Developer Console. Once logged in, you can create your first Skill by clicking on “Create Skill” on the Developer Console’s starting page. Please fill in the required information as per the following images, making sure to adjust the configurations for hosting service, region, and primary locale to meet your specific needs.

Create%20Skill

Create Skill

Within the newly created skill, you’ll find several tabs, with “Build,” “Code,” and “Test” being essential for a functioning prototype of the connection between SAP and Alexa.

  1. Inside the “Build” tab, you can train the language model to understand the specific sentences you want it to recognize.
  2. In the “Code” tab, you can develop the actual response that Alexa should provide when it receives a command. This is where you’ll also implement the Post-Requests later on.
  3. The “Test” tab allows you to test your code without needing an Amazon speaker or your phone. To test the implementation with a Smart Speaker or your phone, connect the Smart Speaker to your phone and log in to your Developer Account on the Alexa App. In the app, you can find “My Skills,” where you’ll see the skills you’ve developed alongside other skills you’ve downloaded. Click on one of the skills that are still in development, and you’ll have the option to activate this skill. Once the skill is activated, you can start it with your phone or a connected smart speaker.

Feel free to explore the development possibilities within the Developer Console. There are many great Tutorials on YouTube to help you get started with Alexa development.

If you plan to publish the skill later, the “Distributions” and “Certifications” tabs will become relevant. However, for a working prototype, they are not necessary.

Post-Requests

At this stage, we have a fully functional SAP Build Process Automation and at least one custom-built intent within our Alexa Skill. It’s time to establish the communication between these two components.

As illustrated in the architecture of the implementation, we require two Post-Requests to be implemented within the corresponding Intent Handler for the custom intent.  You can directly copy and paste this code, then insert your own URLs, Client-ID, and other required details to make the code operational.

const DemoIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'Demo';
    },
   handle(handlerInput) {

    var accessToken = {
    method: 'POST',
    url: 'UAA-URL',
    headers: {'content-type': 'application/x-www-form-urlencoded'},
    data: new URLSearchParams({
        grant_type: 'client_credentials',
        client_id: '',
        client_secret: '',
        audience: 'UAA-URL without "https://"'
    })
    };

    return axios
    .request(accessToken)
    .then(function (response) {
        console.log(response.data.access_token);
        accessToken = response.data.access_token;

        let data = JSON.stringify({
          definitionId: 'Trigger-DefinitionId',
        });

        let trigger = {
          method: 'post',
          maxBodyLength: Infinity,
          url:
            'Trigger-URL',
          headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer ${accessToken}`,
          },
          data: data,
        };
        
         axios.request(trigger)
        
         return handlerInput.responseBuilder
          .speak("Done")
          .reprompt('Can I help you with something else?')
          .getResponse();

      })
      .catch(function (error) {
        console.error(error);

        let speakRepromt = 'Can I help you with something else?';

        return handlerInput.responseBuilder
          .speak('Error occurred')
          .reprompt(speakRepromt)
          .getResponse();
      });
  },
};

The UAA-URL and client credentials can be found within the key of your SAP Build Process Automation Instance. As for the Trigger-DefinitionID and Trigger-URL, as mentioned earlier, you can locate them in the Monitor tab of the SAP Build Process Application.

Success

At this point, you should have successfully implemented a functioning SAP Build Process Automation, created an Alexa Skill with custom intents, and established the connection between the two, enabling you to trigger automations by voice commands. Congratulations!

However, if you encounter occasional issues where your automations don’t work as expected, even though they typically do, consider checking the Desktop Agent. Sometimes, it might still be operating in the wrong mode (while developing, it’s usually in “Design Mode,” but for unattended automations, it should be in “Unattended Mode”). Additionally, if you encounter problems, it can often help to shut down and then restart the Agent completely to ensure it operates smoothly.

Conclusion

In this blog, I’ve provided you with a comprehensive, step-by-step guide on how to set up a one-way connection between SAP Build Process Automation and Alexa. I hope this post has sparked new ideas and possibilities for you.

If any questions have arisen or if you require further clarification on any aspect of this implementation, please don’t hesitate to leave a comment. I’ll do my best to answer as soon as possible.

If you like, please feel free to share your thoughts and feedback in the comments and follow my profile for similar content.


文章来源: https://blogs.sap.com/2023/11/07/trigger-sap-build-process-automations-with-alexa/
如有侵权请联系:admin#unsafe.sh