Use JavaScript to build a bot to take user input

Use the JavaScript actions Automation 360 to execute JavaScript functions to build a bot. Use the actions to create a bot that takes user input and provides the appropriate output.

Prerequisites

Ensure you have the following to build the bot:

  • Basic understanding of JavaScript programming language.
  • Basic experience with creating Automation Anywhere bots.

Procedure

  1. Log in to the Control Room.
  2. On the left pane, click Automation.
    A list of available bots and forms is displayed.
  3. Click Create a bot icon.
  4. In the Name field, enter Hello User.
  5. Click Create & Edit.
  6. In the Actions pane, click Variables to create the following new variables:
    1. Name lInputList, Type > List and Subtype > String.
    2. Name sInputName, Type > String.
    3. Name sOutput, Type > String.
  7. From the Actions pane, click Prompt > For value:
    1. In the Prompt window capture field, enter Enter your name here.
    2. In the Prompt message field, enter Please enter your name here.
    3. In the Assign the output to a variable drop-down list, select sInputName - String.
  8. From the Actions pane, click List > Add item:
    1. In the List variable drop-down list, select lInputList - List.
    2. In the Item to be added drop-down list, select sInputName - String.
    3. In the Add item field, select To end of list.
  9. Create a new JavaScript file.
    1. Open a notepad, and copy and paste the following code:
      function response(str){
      return "Hello "+ str
      } 
    2. Save the file in your desktop as Salutation.js, and select Save as type: as All Files.
  10. From the Actions pane, click JavaScript > Open:
    1. In the JavaScript session field, leave as Default.
    2. In JavaScript > Import existing file, for the JavaScript file field, select Desktop file.
    3. Click Browse and select the Salutation.js file from your desktop or where you saved the file.
    4. In the Assign the output to a variable drop-down list, select sOutput - String.
  11. From the Actions pane, click JavaScript > Run JavaScript:
    1. In the Enter name of the function to be executed field, enter response.
    2. In the Parameters drop-down list, select lInputList - List.
  12. From the Actions pane, click Message box:
    1. In the Enter the message to display field, enter $sOutput$.
  13. Click Save to save your bot , and then click Run.
  14. When the bot prompts to enter a name, enter the name and click OK.
    A message from the bot appears: Hello <User>.