Skip to content
Back to the app

Triggers, schedules and outcome billing ​

Start a workflow without clicking Run ​

Open Workspace → Schedules. Six ways to start a saved workflow:

TriggerWhat starts the runWhere the inputs come from
ScheduleA cron expression in your timezoneThe inputs saved with the schedule
WebhookAnother system posting JSON to the trigger's URLThe posted body (payload), or the fields your mapping picks
EmailA message to the trigger's address (run+…@runs.changents.ai)from, subject, text; attachments become the run's files
EventSomething that happened on the platform (see Event triggers)The event (payload.event)
FileA new or changed file in a synced SharePoint/OneDrive or Google Drive folderThe file, as the run's attachment; its name and link in payload.file
StreamA message on a Redis stream, Kafka topic or AMQP queue you run (see Stream triggers)The message (payload), or the fields your mapping picks

When every step of a real run has finished, its report shows Run this every week. It opens Workspace → Schedules with a schedule for Mondays at 08:00 ready: pick the saved workflow, change the cron or timezone if you want another time, and create it. The link is not shown for a simulation, or for a run with a failed step or a step waiting for approval.

The URL or address is the credential: anyone who has it can start the run as you, through your quota, your agent charters and your approval rules. Share it only with the system that needs it, and delete the trigger to revoke it. The address or URL is shown in full only to you, in your workspace.

A trigger always runs the workflow's released version when one exists, never the draft someone is editing, exactly as a schedule does. Every run appears under Runs like a manual one, and the trigger shows its last run and status.

Example: a carrier's demurrage and detention invoice arrives by email. Create an email trigger on the "Demurrage & detention dispute case" workflow (From CHANGENTS, in the marketplace) and have your mailbox forward carrier invoices to its address. The invoice attachment is checked in code, the dispute letter waits for a person, and the recovered amount is recorded when the carrier answers.

Sending the same event twice ​

A webhook caller can send an Idempotency-Key header. The same key on the same trigger within 24 hours starts no second run: the answer is 202 with the first run's id and "duplicate": true. An email trigger does the same with the message's id, so a message delivered twice starts one run. A schedule fires once for each scheduled time.

Runs started by a trigger or a schedule are queued like any other run and survive a server restart (see Running & Monitoring Workflows). The trigger or schedule shows the run's outcome once it ends.

Mapping webhook fields ​

With no mapping, the whole JSON body is the payload input. To map fields, set inputMapping on the trigger (API: PATCH /api/triggers/:id), for example {"invoiceNo": "invoice.number", "carrier": "invoice.carrier"}.

Signed webhook requests ​

The URL alone is enough to start a run. To require more, turn on Require signed requests when you create a webhook trigger, or Require signing on an existing one. A signing secret (whsec_…) is shown once; store it in the sending system. Rotate secret issues a new one and the old one stops working at once. Stop signing goes back to URL-only.

With signing on, each request must carry a Changents-Signature header (X-Changents-Signature is accepted too) in the same form CHANGENTS.AI uses for its own outgoing webhooks: t=<unix seconds>,v1=<hex>, where v1 is the HMAC-SHA256 of "<t>.<raw request body>" keyed with the secret. A request with no signature, a wrong one, a changed body, or a t more than 300 seconds from our clock is refused with 401 and starts nothing.

js
const crypto = require('crypto');
const body = JSON.stringify({ invoice: 'DD-1' });
const t = Math.floor(Date.now() / 1000);
const v1 = crypto.createHmac('sha256', secret).update(`${t}.${body}`).digest('hex');
await fetch(triggerUrl, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Changents-Signature': `t=${t},v1=${v1}`,
    'Idempotency-Key': 'invoice-DD-1',
  },
  body,
});

Triggers created before signing existed, and any trigger with signing off, keep accepting unsigned requests.

Sending the same request twice ​

Send an Idempotency-Key header (or Changents-Event-Id) with a value unique to the thing you are reporting. A repeat of the same key to the same trigger within 24 hours starts nothing: it answers 200 with "duplicate": true and the id of the run the first request started. A request whose run could not start (a disabled trigger, a workflow with no steps) does not use up its key, so you can send it again. Keys are stored only as a SHA-256 hash.

Event triggers ​

An event trigger starts a workflow when something happens on the platform. Pick the event, and optionally an agent type, when you create it.

EventWhen
run.finishedA real run (not a rehearsal or a simulation) ended completed, partial or cancelled
run.failedA real run ended failed
approval.decidedA person approved or rejected a step that was waiting on them
alert.raisedAn agent health alert, or an IoT device alert, was raised
document.syncedA synced folder had a new or changed file

These are not the outgoing webhook events; they never leave the platform. Only your own events start your triggers (your organisation's, if you are a member). The run receives the event under payload.event: its type, time, workflow, agent type, run id and the facts listed for it (a run's status and duration, an approval's decision, an alert's rule or device reading, a file's name and link).

A workflow never restarts itself through an event. Each event carries the workflows whose runs led to it; a trigger on a workflow already in that chain does not fire, so a workflow's own run, or a loop of two workflows starting each other, stops. A chain is also cut at five workflows.

GET /api/triggers/events lists your events of the last seven days and which triggers each one started. Events are deleted after seven days.

File triggers ​

A file trigger watches one of your synced folders (connect one under Vault → Synced folders). Each time the folder syncs, every file that is new, or whose modified time changed, starts the workflow once, with the file as the run's attachment. The first sync of a folder records what is already there and starts nothing. Up to 20 files, and 60 MB, are announced per sync; the rest are announced at the next one. Each arrival is also a document.synced event.

The folder syncs on its own schedule (daily at 03:00 UTC unless you set another), or when you press Sync on it, so a file starts its run at the next sync, not the moment it is saved.

Stream triggers ​

A stream trigger starts the workflow once for each message published to a Redis stream, for a system that publishes messages and cannot call a URL. Give the stream's address (redis:// or rediss://, with a password if it needs one), the stream name and, if you want your own, a consumer group (changents unless you set another).

  • Only messages published after the trigger is created start runs. The stream's history is not replayed.
  • The stream is read every few seconds, through a consumer group, so each message starts one run however many copies of the platform are running.
  • A message is acknowledged only once its run is queued. If the platform restarts in between, the message is delivered again and does not start a second run.
  • A message whose run can never start (the workflow was deleted, or the message is over 200,000 characters) is acknowledged and not retried. The trigger shows the reason.
  • A message's fields become payload. A message with a single field named payload or data holding a JSON object becomes that object.
  • The address is stored encrypted and is not shown again; the trigger shows the host, the stream name, when it was last read and the last error, if any.

On the hosted service the stream must be reachable on the public internet and use rediss:// (TLS). On an install you run on your own network (TOOL_EGRESS_ALLOW_PRIVATE=true, or air-gapped mode) it can be a private address, and an air-gapped install reads nothing else.

Kafka topics and AMQP queues ​

The same trigger reads two other kinds of broker. The start of the address says which:

Address starts withReadsName fieldConsumer group
redis://, rediss://A Redis streamThe streamchangents unless you set one
kafka://, kafka+ssl://A Kafka topicThe topicchangents unless you set one
amqp://, amqps://An AMQP 0-9-1 queueThe queueNone

A Kafka topic is read by a consumer that stays connected, in the consumer group you name.

  • A new group starts at the end of the topic, so only messages published after the consumer has joined start runs. Joining takes a few seconds after the trigger is created.
  • A message's position is committed once its run is queued. A message delivered again does not start a second run.
  • Put a user name and password in the address to sign in with SASL, and add ?mechanism=scram-sha-256 or ?mechanism=scram-sha-512 if the cluster does not use plain. Add ?brokers=host:port,host:port to name more brokers to connect through first.
  • A message that is a JSON object becomes payload. Any other message becomes payload.message, as text.

An AMQP queue is read every few seconds, like a Redis stream.

  • The queue must already exist. It is not created for you, so a mistyped name is reported on the trigger as a queue that does not exist.
  • Every message waiting in the queue starts a run, including ones published before the trigger was created.
  • A message is acknowledged once its run is queued. If that fails, it goes back on the queue.
  • A message delivered again starts a second run unless the publisher set a message id on it: the message id is what a redelivery is recognised by.
  • The path of the address is the virtual host: amqps://user:password@broker.example.com/orders.
  • A JSON object becomes payload; any other message becomes payload.message.

The address rules are the same for all three: on the hosted service a public address and the TLS form (rediss://, kafka+ssl://, amqps://); a private address only on an install you run on your own network. For a Kafka cluster this also applies to every broker the cluster names.

Through the API ​

MethodPathWhat it does
GET/api/triggersYour triggers
POST/api/triggersCreate: workflowId, kind, name, signing, eventFilter, fileSourceId, stream (url, key, group)
PATCH/api/triggers/{id}Enable, rename, change the mapping or event filter, signing on or off
POST/api/triggers/{id}/rotate-secretA new signing secret, returned once
DELETE/api/triggers/{id}Revoke
GET/api/triggers/event-typesThe events an event trigger can start on
GET/api/triggers/eventsYour platform events of the last seven days
POST/api/hooks/{token}Start a webhook trigger's workflow
*/api/schedules…List, create, pause, resume and delete schedules

Outcome billing ​

Billing → Outcome billing shows what your agents' confirmed results would bill at your rates:

  • a share of the demurrage and detention money a dispute recovered (default 20%), counted only once a person records the recovered amount on the invoice;
  • a fixed amount per support case closed as resolved by a person.

Each outcome names the invoice or case it rests on; nothing is billed on the model's say-so, and an outcome is billed once. An organisation owner or admin can set the rates and issue a month's outcomes as an invoice on terms, one invoice per currency.

Served from this deployment. No page view leaves it.