Skip to main content
Modules

Utils

Utils

The Utils module is responsible for performing actions considered useful for the development of certain robot routines.

Methods

calculateDateDistance

Method responsible for calculating the distance between two dates in a given time unit.

js
const distance = await Utils.calculateDateDistance["v1_0_0"]({
dateFrom: '2024-01-01',
dateTo: '2024-12-31',
unity: 'days',
})

Required parameters

  • dateFrom: String - start date.
  • dateTo: String - end date.
  • unity: String - time unit of the result. Values: years | months | days | hours | minutes | seconds.

Optional parameters

  • inputFormat: String - format of the input dates (e.g. YYYY-MM-DD, DD/MM/YYYY). If it is not provided, it tries to detect it automatically.

Return

The constant or variable created, such as the distance of the example shown earlier, receives a number representing the distance between the two dates in the unit provided.

callRobot

Method responsible for calling another robot from the robot in execution.

js
const result = await Utils.callRobot["v1_0_0"]({
callerRobot: 'meu-robo',
robotKey: 'chave-do-robo-chamado',
args: { parametro: 'valor' }
})

Required parameters

  • callerRobot: String - identifier of the robot that is making the call.
  • robotKey: String - key of the robot that will be called.

Optional parameters

  • args: Any - arguments that will be passed to the robot called.

Return

The constant or variable created, such as the result of the example shown earlier, receives an object with the following property:

  • result.error: String - error message if the call fails. If there is no error, this property is not present.

clipboardWrite

Method responsible for storing a value temporarily in the clipboard.

js
await Utils.clipboardWrite["v1_0_0"]({
content: "Roberty"
})

Required parameters

  • content: String - expects a value to be stored temporarily in the clipboard.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

clipboardRead

Method responsible for reading the value stored temporarily in the clipboard.

js
const valor = await Utils.clipboardRead["v1_0_0"]()

Required parameters

This method has no required parameters.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the valor of the example shown earlier, receives an object with the following property:

  • valor.content: String - contains the value stored in the clipboard.

count

Method responsible for counting the number of elements of a value.

js
const total = await Utils.count["v1_0_0"]({
value: [1, 2, 3, 4, 5]
})

Required parameters

  • value: Any - value to be counted. It accepts strings (character count), arrays (item count) and numbers (digit count).

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the total of the example shown earlier, receives a number representing how many elements the value provided has.

delay

Method responsible for pausing the robot for a given period of time.

js
await Utils.delay["v1_0_0"](5)

Required parameters

  • The amount in seconds the robot must wait.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

downloadFilesInBatch

Method responsible for downloading multiple files from URLs into a local folder.

js
const result = await Utils.downloadFilesInBatch["v1_0_0"]({
targetFolder: 'C:/Users/Roberty/Downloads',
files: [
{ url: 'https://exemplo.com/arquivo1.pdf', nameToSave: 'documento1.pdf' },
{ url: 'https://exemplo.com/arquivo2.pdf', nameToSave: 'documento2.pdf' },
],
})

Required parameters

  • targetFolder: String - path of the folder where the files will be saved.
  • files: Object[] - list of files to be downloaded. Each object must contain:
    • url: String - URL of the file to be downloaded.
    • nameToSave: String - name the file will be saved with.

Optional parameters

  • createTargetFolderIfNot: Boolean - if true, it creates the destination folder if it does not exist. Default value: false.

Return

The constant or variable created, such as the result of the example shown earlier, receives an object with the following properties:

  • result.allFilesDownloaded: Boolean - indicates whether every file was downloaded successfully.
  • result.filesWithSuccess: String[] - list of the names of the files downloaded successfully.
  • result.filesWithError: String[] - list of the names of the files that failed.
  • result.errorsByFile: Object - object with the errors of each file that failed, indexed by the file name.

execCommand

Method responsible for executing a command in the operating system terminal.

js
await Utils.execCommand["v1_0_0"]({
command: 'notepad.exe C:/Users/Roberty/Desktop/arquivo.txt',
})

Required parameters

  • command: String - command to be executed in the terminal.

Optional parameters

  • waitCommandFinish: Boolean - if true, it waits for the command to finish before the robot execution continues. Default value: false.

Return

This method has no return.

focusProcess

Method responsible for focusing the screen of a process opened on the user's computer.

js
await Utils.focusProcess["v1_0_0"]({
processName: "chrome"
})

Required parameters

  • processName: String - expects the exact name of the process that will be focused.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

getDeviceToken

Method responsible for getting the token of the device where the robot is being executed.

js
const token = await Utils.getDeviceToken["v1_0_0"]()

Required parameters

This method has no required parameters.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the token of the example shown earlier, receives a string with the token of the device.

getInstanceByRobotKey

Method responsible for getting the execution instance of a robot from its key.

js
const instance = await Utils.getInstanceByRobotKey["v1_0_0"]({
robotKey: 'chave-do-robo',
})

Required parameters

  • robotKey: String - key of the robot whose instance will be obtained.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the instance of the example shown earlier, receives a string with the identifier of the robot instance.

killProcess

Method responsible for ending a process opened on the user's computer.

js
await Utils.killProcess["v1_0_0"]({
processName: "chrome"
})

Required parameters

  • processName: String - expects the exact name of the process that will be ended. This parameter is not required if processId is provided.
  • processId: Number - expects the id of the process that will be ended. This parameter is not required if processName is provided.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

maximizeProcess

Method responsible for maximizing the screen of a process opened on the user's computer.

js
await Utils.maximizeProcess["v1_0_0"]({
processName: "chrome"
})

Required parameters

  • processName: String - expects the exact name of the process that will be maximized.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

minimizeProcess

Method responsible for minimizing the screen of a process opened on the user's computer.

js
await Utils.minimizeProcess["v1_0_0"]({
processName: "chrome"
})

Required parameters

  • processName: String - expects the exact name of the process that will be minimized.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

runPythonCode

Method responsible for executing a snippet of Python code and returning its output.

js
const output = await Utils.runPythonCode["v1_0_0"]({
code: 'print("Hello from Python!")'
})

Required parameters

  • code: String - Python code to be executed.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the output of the example shown earlier, receives a string with the content printed to stdout by the execution of the Python code.

screenshot

Method responsible for capturing an image of the whole screen and saving it to a file.

js
await Utils.screenshot["v1_0_0"]({
fullPath: `C:\\Users\\Roberty\\Downloads\\imagem.png`
})

Required parameters

  • fullPath: String - expects the full path where the captured image will be saved, including the file name and its extension (e.g. .png).

Optional parameters

This method has no optional parameters.

Return

This method has no return.

screenshotRegion

Method responsible for capturing an image of a specific region of the screen and saving it to a file.

js
await Utils.screenshotRegion["v1_0_0"]({
byPositionProtocol: {
x: 0,
y: 0,
width: 800,
height: 600,
fullPath: 'C:/Users/Roberty/Downloads/regiao.png'
}
})

Required parameters

  • byPositionProtocol: Object - object with the coordinates and settings of the region to be captured:
    • x: Number - x coordinate of the upper left corner of the region.
    • y: Number - y coordinate of the upper left corner of the region.
    • width: Number - width of the region in pixels.
    • height: Number - height of the region in pixels.
    • fullPath: String - full path where the captured image will be saved.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

sendWebhookResponse (Profissional)

Method responsible for answering a value to the webhook of your robot.

js
await Utils.sendWebhookResponse["v1_0_0"]({
webhookCallId: "webhookCallId"
})

Required parameters

This method has no required parameters.

Optional parameters

  • args: Any - receives a value to be answered to the webhook.
  • webhookCallId: String - receives the webhookCallId of the robot.

Return

This method has no return.

startProcess

Method responsible for starting a process on the user's computer.

js
const process = await Utils.startProcess["v1_0_0"]({
fileName: "chrome",
arguments: "https://www.google.com"
})

Required parameters

  • fileName: String - expects the exact name of the process that will be started or, if necessary, the full path of the desired executable.

Optional parameters

  • arguments: String - expects a string with the arguments for the process initialization.

Return

The constant or variable created, such as the process of the example shown earlier, receives an object with the following properties:

  • process.id: Number - returns the id of the process started.
  • process.processName: String - returns the name of the process started.

waitHumanAction

Method responsible for pausing the robot execution waiting for a human action. The robot waits until the user confirms the continuation or until the time limit is reached.

js
const result = await Utils.waitHumanAction["v1_0_0"]({
timeout: 300000
})

Required parameters

  • timeout: Number - maximum time in milliseconds the robot will wait for the human action.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the result of the example shown earlier, receives an object with the following property:

  • result.result: String - indicates the result of the wait. Values: CONTINUE (the user confirmed) | TIMEOUT (the time limit was reached).