Triggers
A trigger starts a task when something happens, as a schedule does at a time:
| Trigger | Starts the task when | Watched by |
|---|---|---|
| File | a file is created (or changed, or deleted) in a folder | the agent, which also runs the task |
| a mail that matches arrives in a mailbox | the agent, which also runs the task | |
| Webhook | another system calls the trigger's web address | the server; the task runs on any free agent, a group or one agent |
| Hotkey | someone presses a key combination on the agent machine | the agent (its tray app), which also runs the task |
| Work queue | a work queue has new items | the server; the task runs on any free agent, a group or one agent |
Like schedules, triggers run the task's public version on behalf of the user who created the trigger (that user's vault access applies). Whoever changes its task, agent, settings or inputs, or renews its webhook token, takes it over: from then on their vault access applies. Runs started by a trigger show its name under Started by on the execution pages.
The event in the task
The event's details reach the task as its trigger input, a record. Declare it to use them:
input --name:trigger --type:record --required:false
log --message:"New file: $trigger.Path$"
| Trigger | Fields of $trigger$ |
|---|---|
| File | Path, Name, Folder, Extension, Size (bytes), Event (created, changed or deleted), Time |
Id, From, FromName, To, Cc, Subject, Date, Body, HtmlBody, Attachments (names), Folder |
|
| Webhook | Body (JSON as a record or list; any other body as text), Query (the address's parameters), ContentType, ReceivedAt |
| Hotkey | Keys, Machine, UserName, Time |
| Work queue | Queue (its name), Waiting (new items when the run started), ReceivedAt |
A mail's Id works with the mail command, for example to save its attachments:
input --name:trigger --type:record --required:false
mail --action:saveattachments --server:imap.company.com --credential:$mailbox$ --id:$trigger.Id$ --destination:C:\In\$trigger.Id$
The trigger can also give the task's other inputs fixed values (under INPUTS in the trigger form).
Create a trigger
Open Triggers (Manage triggers permission, Developer by default) and click New trigger. Choose what starts the task, then fill in:
| Field | Description |
|---|---|
| Name | For example New invoices. |
| Task | The task to run. Tasks without a public version are disabled. |
| Agent (watches and runs) / Runs on | File, mail and hotkey triggers: the agent that watches and runs the task. Webhook and work queue triggers: Any available agent, an agent group or one agent. Triggers run only on unattended robot agents; workstation agents cannot be chosen. |
| Active | Whether the trigger starts the task. |
File triggers
| Field | Description |
|---|---|
| Folder | On the agent machine or a share it reaches (\\server\share\in). Environment variables such as %USERPROFILE% work. |
| Files | A filter such as *.pdf (default *.*). |
| When a file is | Created (default; a file renamed into the filter counts as new), Changed or Deleted. |
| Subfolders too | Watch the folders inside it as well. |
A new file is sent once it is complete: when it can be opened and its size has stopped growing, so a large copy does not start the task half way. A folder that does not exist yet is looked for again every 30 seconds, and the trigger shows the problem meanwhile.
Mail triggers
| Field | Description |
|---|---|
| IMAP server, Port, Security | For example outlook.office365.com, 993, SSL/TLS. |
| Sign-in | User name and password, or Microsoft 365 (OAuth) with an app registration: then also the Tenant and the Mailbox address, and the credential holds the application (client) id as user name and the client secret as password (as for the mail command). |
| Vault, Credential | Where the mailbox password (or app secret) is kept. |
| Mail folder | INBOX by default. |
| From contains, Subject contains | Optional filters. |
| Check every | 15 to 3600 seconds (default 60). |
Each unread mail that matches starts the task once and is marked as read. Mails are taken oldest first, at most 20 per check. Sign-in problems are shown on the trigger (once, not at every check).
Webhook triggers
When a webhook trigger is created, Botream shows its address and a token, once. Other systems call it with POST:
curl -X POST "https://rpa-server/api/hooks/12" \
-H "X-Botream-Token: <token>" \
-H "Content-Type: application/json" \
-d "{\"orderNo\": \"A-17\"}"
- The token goes in the
X-Botream-Tokenheader, or as?token=in the address. A wrong or missing token answers404, as if the trigger did not exist. - The answer is
202with{"status": "Started", "executionId": "1042"}, or"Queued"when no agent is free; a trigger that is turned off, or whose run cannot start (for example its task was deleted), answers409with the reason inmessage. - New token in the trigger's menu replaces the token; the old one stops working at once.
- The address needs no sign-in. Publish it to the systems that call it only, preferably over HTTPS.
Hotkey triggers
Click the Key combination field and press the keys, for example Ctrl+Shift+F9. A combination needs Ctrl, Alt, Shift or Win, except F-keys, Pause and Print Screen, which may stand alone. Two hotkey triggers of an agent cannot share a combination, and a combination another program holds is refused (the trigger shows why).
Hotkeys work while someone is signed in on the agent machine and the Botream Agent tray app runs.
Work queue triggers
| Field | Description |
|---|---|
| Queue | The work queue to watch; the list shows how many new items each has. |
| Runs at once | 1 to 20 (default 1): how many runs may work the queue at the same time, on different agents. |
While the queue has new items, the task starts. It should take them with loop --type:queue, which works the queue until it is empty:
loop --type:queue --queue:Invoices --variable:item
runtask --name:"BookInvoice" --invoice:$item.Data$
endloop
- The server checks the queue as soon as items are added (by a task, on the Queues page or through the API) or a failed item is put back, when a run ends and an agent becomes free, and every few seconds.
- With Runs at once above 1, one more run starts at each check while more items wait than runs are going, up to that number.
- Items left when a run ends (added meanwhile, or put back for a retry) start the next run.
- A run that took no item, for example a task that does not use the queue or fails at once, is not started again until new items arrive. The trigger shows Problem (The last run took no item from the queue: new items start the task again) meanwhile.
- When no agent is free, the trigger shows Waiting for an agent and the server tries again at the next check. The items wait in the queue, so nothing is dropped.
When the agent is busy
An agent runs one task at a time. An event that finds no free agent waits on the server, and the trigger shows Waiting for an agent with the number of waiting events. The server tries again every few seconds, oldest event first. Events wait up to an hour (and at most 1,000 per trigger); then they are dropped and the trigger says so. Waiting events are kept in the database, so they survive a server restart. Turning a trigger off drops its waiting events.
Events an agent notices while it cannot reach the server wait on the agent and are sent when it is connected again (up to an hour), also when the agent is restarted meanwhile.
A folder trigger remembers which files its folder held when it was last watched. Files created, changed or deleted while the agent was not running (the machine was off, nobody was signed in) are sent, oldest first, when the agent watches the folder again; files moved in from the same drive count as new although they keep their old times. A folder with more than 200,000 matching files keeps no list: new and changed files are then told by their times, so files moved in and deleted files are not caught up. A new trigger, or one whose settings were changed or which was switched off, starts with the files that arrive from then on.
The Triggers page
Each trigger shows what it listens to, the agent, its Last event (Started with a link to the run, Waiting for an agent, or Problem with the reason when you hover it), how many runs it started, and an Active switch. Creating, changing and deleting triggers and renewing tokens are recorded in the audit log.