Build a hello world bot with a Python function
- Updated: 2021/09/03
Build a bot that calls a Python function to say hello world.
Prerequisites
To run Python script from Automation 360, you must already have the latest version of Python 3.x installed on your device.
Here is a Python script with one simple function. This script is used in this
task.
# Function definition is here
def printme( str ):
print(str)
return str
Procedure
-
Create a new bot:
- On the left panel, click Automation.
- Click + Create > Task Bot.
-
Select the required platform as the target runtime environment. For
example, Windows or macOS.
Note: Windows is the default pre-selected platform.
- In the Create Task Bot window, enter the bot name.
-
Accept the default folder location: \Bots\
To change the default bot storage location, click Choose and follow the prompts.
- Click Create and edit.
Note: The default maximum size for individual bot is 50 MB. -
Create a variable.
-
Click Variables.
The Variables accordion menu is located below the Actions menu.
- Click the Create variable icon.
-
Enter sArguement in the name field.
Note: It is recommended to prefix the variable name with a lowercase character to indicate the variable data type. See Variable naming.
- Type Hello world! in the Default value field.
- Click Create.
-
Click Variables.
-
Provide the script with a Python Script > Open
action.
- Double-click or drag the Python Script > Open.
- Select the Manual input option.
-
Copy and paste the following text into the Enter script
here field.
def printme( str ): print(str) return str
-
Use a Python Script > Execute function
action to tell the bot to run the script.
- Double-click or drag Python Script > Execute function.
-
Type
printmein the Enter name of function to be executed field. -
Select the
sArgumentvariable from the Arguments to the function drop-down list. -
Create the variable
sPythonHellofor the Assign the output to variable field.
-
Insert a Message box
action to hold the Python function output.
- Double-click or drag the Message box > Message box action.
-
In the Enter the message to display field,
select and insert the variable
sPythonHello. - Select the Close message box after check box. Leave the default of 5 seconds in the field.
-
Close the script execution session with a Python Script > Close
action.
- Double-click or drag Python Script > Close.
- Click Save.
-
Click the Run icon.
The bot generates a pop-up Message box with the text
Hello world!. After five seconds, the Message box disappears.