Lea y revise la documentación de Automation Anywhere

Automation 360

Cerrar contenidos

Contenidos

Abrir contenidos

Build a bot to parse JSON response using JavaScript

  • Actualizado: 2021/08/11

    Build a bot to parse JSON response using JavaScript

    Use the subscription key created in the Microsoft Azure to build a bot to parse the JSON response using Automation 360 REST Web Services and JavaScript actions.

    Antes de empezar

    Ensure you have the following to build the bot:

    • Created an account in the Azure portal and have the subscription key available.

      Set up Azure portal

    • Access to the Control Room or Community Control Room
    • Your workstation is a registered device in the Control Room.

    Procedimiento

    1. Inicie sesión en Control Room.
    2. En el panel izquierdo, haga clic en Automatización.
      Se muestra la lista de formularios y bots disponibles.
    3. Click Create a bot icon.
    4. In the Name field, enter API_Sentiment_Score_Bot.
    5. Click Create & Edit.
    6. From the Actions pane, click Variables to create a new variable:
      1. In the Name field, enter sURI.
      2. In the Type field, select String.
      3. In the Default value field, access your previously created resource and paste the value here: https://westus.api.cognitive.microsoft.com/text/analytics/v2.1/sentiment.
      4. Click Create.
    7. Create a new Variable:
      1. In the Name field, enter sSubscriptionKey.
      2. In the Type field, select String.
      3. In the Default value field, paste the value from the K1 field: 0abfa73d93f1469d9d4b5db459394315.
      4. Click Create.
    8. From the Actions pane, select REST Web Services > Post method and place it at the Start of the bot.
      1. In the URI field, select $sURI$ and click Yes, insert.
      2. In the Authentication Mode drop-down list, select No Authentication.
      3. Click Header > Custom Headers > (Add):
        1. In the Name field, enter Ocp-Apim-Subscription-Key.
        2. In the Value field, select $sSubscriptionKey$ and click Yes, Insert.
      4. In the Content type drop-down list, select JSON (application/json).
      5. In Custom Parameters, enter the following code:
        {
        "documents": [
        {
        "language": "en",
        "id": "1",
        "text": "I love this world"
        }
        ]
        }
      6. Create a new dResponse variable of Type > Dictionary and Subtype > String.
      7. In the Assign the output to a variable drop-down list, select dResponse -Dictionary of Strings.
      8. Click Create & Select.
    9. From the Actions pane, drag Message box to the bot. In the Enter the message to display field, select dResponse -Dictionary of Strings, and click Yes, insert.
    10. Create a new sOutput variable of Type > String.
    11. From the Action pane, click Dictionary > Get.
      1. In the Dictionary variable drop-down list, select dResponse -Dictionary.
      2. In the Key field, enter Body.
      3. In the Assign the output to a variable drop-down list, select sOutput -String.
    12. Create a new lParseOutput variable of Type > List and Subtype > String.
    13. Create a new sSentimentValue variable of Type > String.
    14. From the Action pane, click List > Add item.
      1. In the List variable drop-down list, select lParseOutput -List.
      2. In the Item to be added drop-down list, select sOutput -String.
      3. In the Add Item field, select To end of list.
    15. From the Action pane, click JavaScript > Open.
      1. In the JavaScript session field, select Default.