Expressions
Expressions are CEL. They are written in integration definitions and in hooks. An expression is at most 2,000 characters.
Syntax
| Where | Written as | Example |
|---|---|---|
| An integration or hook written as JSON | ${{ <CEL> }} | "${{ body.event.type == \"app_mention\" }}" |
| An integration or hook written in HCL | $${{ <CEL> }} | "$${{ body.data.id }}" |
A hook's when | bare CEL, or ${{ <CEL> }} | event.inputs.query != '' |
A field that contains one expression must be the whole string, ${{ ... }}, with
nothing around it but spaces. Such fields are rejected otherwise, with
must be an expression, written as ${{ ... }}.
A field that contains text (a request's url, query, headers and body
strings, a tool input's default, asymmetric.key, and a hook step's with
strings and request fields) may contain any number of expressions inside it:
https://api.example.com/issues/${{ task.marks["linear.issue"] }}/commentsWhen the text is one expression and nothing else, it keeps the expression's
type, so a body field written ${{ {"channel": target.channel} }} sends a JSON
object. Otherwise each expression is written into the text.
In JSON, an integer is a number. An integer of 2^53 or more, or of -2^53 or
less, is its digits as text. Bytes are base64 text. A timestamp is RFC 3339
text in UTC. A duration is text in seconds, as in 90s. A type is its name. A
double that is not a number or is infinite is text: NaN, Infinity or
-Infinity. A map is an object with text keys. A map with two keys that JSON
writes the same, such as 1 and "1", fails the expression.
Evaluation
| The expression is | When it fails to evaluate |
|---|---|
a condition (when, ignoreWhen, respond.when, expect.success, a hook's when) | it counts as false |
in a request's url, query, headers or body, or a hook request | the request is not sent and fails |
| anywhere else | it reads as nothing: no mark is kept, a capture is null, a title is empty |
Reading a field that is not there fails. has() tests whether a field is
there:
has(body.data.assignee) ? body.data.assignee.email : ""has() takes only a field of a value. For a field of a function's result, use
in, as in "message" in parseJson(body.payload).
Functions
Besides the standard CEL functions, every expression can call:
| Function | Returns | Description |
|---|---|---|
parseJson(string) | dyn | Reads a JSON text as a value, as in parseJson(body.payload).type. Fails when the text is not JSON. |
htmlUnescape(string) | string | Decodes &, < and > in a text, as in htmlUnescape(body.event.text). It does not rewrite Slack tokens such as <@U123>. |
No expression may read a secret. An expression containing secret. or
secret[ is rejected.
Integration positions
A position is the path of a field, with * for any key or index. Returns is
what the expression must return, when anything is required. These tables leave
out the integration. prefix and write [*] as .*: the check and positions
APIs write webhook.events.*.when as integration.webhook.events[*].when, and
a check names a real index, as in integration.webhook.events[0].when.
| Position | Returns | Variables |
|---|---|---|
webhook.verify.hmac.signed, webhook.verify.hmac.freshness.at, webhook.verify.asymmetric.key, webhook.verify.asymmetric.signed, webhook.verify.asymmetric.freshness.at | body, headers, raw | |
webhook.respond.when | bool | body, headers, raw |
webhook.respond.body | body, headers, raw | |
webhook.ignoreWhen | bool | body, headers, raw |
webhook.route.by, webhook.delivery | body, headers, raw | |
webhook.events.*.forEach | list | body, headers, raw |
webhook.events.*.when | bool | body, headers, raw, item, lookup |
webhook.events.*.lookup.request.url, .query.*, .headers.*, .body | body, headers, raw, item | |
webhook.events.*.lookup.with | body, headers, raw, item | |
webhook.events.*.lookup.request.expect.success | bool | the above, response, status |
webhook.events.*.lookup.request.capture.*, webhook.events.*.lookup.capture.* | the above, response, status | |
webhook.events.*.raise.message, .author.email, .opens.title, .opens.description, .opens.assignBy.email, .opens.chat.by.email, .branch, .marks.*.value | body, headers, raw, item, lookup, captures | |
webhook.events.*.raise.attachments.each | list | body, headers, raw, item, lookup, captures |
webhook.events.*.raise.attachments.name, .type, .size, and .fetch request fields | the above, file | |
poll.request.url, .query.*, .headers.*, .body | cursor, connection | |
poll.request.expect.success | bool | cursor, connection, response, status, headers |
poll.request.capture.* | cursor, connection, response, status, headers | |
poll.cursor | body, cursor | |
poll.events.* | as for webhook.events.* | body, cursor, and as for webhook.events.* |
actions.*.request.url, .query.*, .headers.*, .body | task, ask, chat, reply, request, notice, target, connection, uploaded, inputs | |
actions.*.request.expect.success | bool | the above, response, status, headers |
actions.*.request.capture.* | the above, response, status, headers | |
actions.*.usage.inputTokens, .outputTokens, .cost, .currency, .model | task, ask, chat, reply, request, notice, target, connection, uploaded, inputs, response, status, capture | |
actions.*.uploads.each | list | task, ask, target |
actions.*.uploads.prepare.url, .query.*, .headers.*, .body | the above, connection, file | |
actions.*.uploads.prepare.expect.success, .capture.* | the above, response, status, headers | |
actions.*.uploads.send.url, .query.*, .headers.* | task, ask, target, connection, file, prepared | |
actions.*.uploads.send.expect.success, .capture.* | the above, response, status, headers | |
actions.*.uploads.complete.url, .query.*, .headers.*, .body | task, ask, target, connection, uploaded | |
actions.*.uploads.complete.expect.success, .capture.* | the above, response, status, headers | |
actions.*.uploads.ready.url, .query.*, .headers.*, .body | task, ask, target, connection, file, prepared | |
actions.*.uploads.ready.expect.success, .capture.* | the above, response, status, headers | |
tools.*.inputs.*.default | task | |
tools.*.output | task, inputs, connection, response, status, capture | |
connection.oauth2.identity | response | |
on.*.*.to.* | task, ask, chat, reply, request, notice | |
on.*.*.mark.*.value | task, ask, request, target, connection, uploaded, response, capture |
item is seen only when the event has forEach. lookup is seen only when
the event's lookup has call. Captures are the names in
the event's lookup.capture, each seen by its own name. inputs is seen by an
action only when a tool calls it. A capture named like a built-in name shadows
it, and is warned about.
What an action has at run time depends on what calls it:
| Called by | Has |
|---|---|
| a tool | task, inputs, connection |
an event's lookup.call, for a read-only tool | inputs, connection |
an on binding for a task event | task, ask, target, uploaded, connection |
an on binding for a chat event | chat, reply, target, uploaded, connection |
an on binding for an inbox request event | task, request, target, uploaded, connection |
an on binding for a notice event | notice, target, uploaded, connection |
a schedule | connection |
An expression in an action, a binding or a tool's output is checked against
what calls it, as the table above lists:
| Expression | Checked against |
|---|---|
on.*.*.to.*, on.*.*.mark.*.value | what the binding's event has |
actions.*.request fields | what each binding, tool, lookup and schedule that names the action has. It must check for each of them. A lookup counts only for a tool that a lookup of the same integration calls |
actions.*.uploads fields | what a binding of a task event has. Only those bindings send files |
tools.*.output | what a tool has, and what a lookup has when a lookup of the same integration calls the tool |
An action that nothing names is checked against what any caller has. An
expression that reads a variable its caller does not have gets a warning, as in does not check: Unknown variable: task. A notice event has no such variable
for a binding of notice.raised that reads task.title.
Integration values
| Name | Type | Description |
|---|---|---|
body | dyn | The delivery or poll response, parsed as JSON. |
headers | dyn | The delivery's headers, by lowercase name. |
raw | string | The delivery's body as text. |
cursor | string | The poll's cursor, "" before the first. |
connection | string | The team's OAuth access token. |
response | dyn | The response body, parsed as JSON when it is JSON, else text; null when empty. |
status | dyn | The response's HTTP status. |
capture | map | The request's capture values, by name. |
item | dyn | The current entry of forEach. |
file | dyn | The current entry of attachments.each, or of uploads.each. |
prepared | map | The capture values of uploads.prepare for the current file, by name. |
uploaded | list | The files that uploads sent. Each has id, name, type, size and prepared. Empty for an action without uploads. |
inputs | map | The tool's inputs, by name. |
lookup | dyn | The output of the tool an event's lookup.call names. Unset when the call fails. |
target | map of string | The values of the binding's to, and channel from routes. |
task:
| Field | Type | Description |
|---|---|---|
task.title | string | The task's title. |
task.url | dyn | The task's address in Spotlight. |
task.pullRequests | list of string | The addresses of the task's pull requests, one for each repository, the first opened first. Empty without one. |
task.line | string | The key of the task's line. |
task.station | string | The name of the task's station. |
task.stationKey | string | The key of the task's station. |
task.marks | map of string | The task's marks, by kind, as in task.marks["slack.thread"]. For a task created from a chat, also the chat's marks that do not find it. |
ask:
| Field | Type | Description |
|---|---|---|
ask.body | string | What the task asks, when it waits on a person; otherwise "". When it waits on an approval, ends with a link to decide it. |
ask.link | dyn | The address of the conversation in the inbox, or null. |
ask.station | string | The name of the task's station. |
ask.attachments | list | The files of the question, as a handover's screenshots. Each has id, name, type and size. Empty when the task does not wait on a person. |
chat:
| Field | Type | Description |
|---|---|---|
chat.marks | map of string | The chat's marks, by kind, as in chat.marks["slack.channel"]. For chat.refused, the marks of the happening. |
reply:
| Field | Type | Description |
|---|---|---|
reply.body | string | What Spotlight says to the chat. |
reply.link | dyn | The address of the task the reply is about, else of the chat, in Spotlight; null for chat.refused. |
reply.proposals | list | The chat's open proposals, listed in reply.body, for the last words of a run; otherwise empty. Each has number, title, and line and station, which can be null. |
request:
| Field | Type | Description |
|---|---|---|
request.form | string | What the request asks for: memories for proposed memories, alert for a station alert. |
request.link | dyn | The address of the request in the inbox, or null. |
notice:
| Field | Type | Description |
|---|---|---|
notice.form | string | ended when a search for a better station config ended, advice for advice about a station. |
notice.headline | string | The notice's headline. |
notice.points | list of string | The notice's points, in order. |
notice.link | dyn | The address of the notice in the inbox, or null. |
notice.externalLink | dyn | The notice's link outside Spotlight, such as a pull request, with url and label; null without one. |
Hook positions
| Position | Returns | Variables |
|---|---|---|
hook.when | bool | event, task, run, vars, hook |
hook.steps.*.with.* | the above, step | |
hook.steps.*.request.url | the above, step | |
hook.steps.*.request.headers.* | the above, step | |
hook.steps.*.request.body | the above, step | |
hook.brief | the above, step |
A hook's match is compiled into conditions of the same kind as when.
Hook values
| Name | Type | Description |
|---|---|---|
event | object | The event's fields. Every event has event.at, an ISO 8601 time. The rest are listed per event in Events. |
task.id | string | The task's id. |
task.title | string | The task's title. |
task.url | string | The task's address in Spotlight. |
task.line | string | The key of the task's line. |
task.station | string | The name of the task's station. |
task.stationKey | string | The key of the task's station. |
task.marks | map of string | The task's marks, by kind. |
task.repositories | list of string | The line's repositories, as owner/name. |
task.pullRequest | dyn | The address of the task's first pull request, or null. |
task.pullRequests | list of string | The addresses of the task's pull requests, one for each repository, the first opened first. Empty without one. |
run.id | string | The run's id. Only on events that happen in a run. |
vars | map of string | The hook's vars. |
hook.key | string | The hook's key. |
step.<name>.status | string | done, failed or waiting, for a step before this one. |
step.<name>.output | dyn | That step's response. |
Type-checking
Every expression is type-checked against the variables of its position when the definition is written.
| Problem | Integration | Hook |
|---|---|---|
| does not parse | error, write rejected | error, write rejected |
| does not type-check, or returns the wrong type | warning, definition kept | error, write rejected |
An integration warning reads does not check: <message>, followed by . Did you mean <suggestion>? when there is one. Warnings are returned in the
resource's warnings, and the Terraform provider shows them as warnings on the
attribute.
body and response are dyn unless a shape declares them. See
Shapes.
Check API
POST /api/v1/expressions/checkType-checks one expression where it would be written, as terraform plan
does. Needs the plan permission; a workspace token without it gets
403. It takes the same credentials and returns the same problems as the
resource API.
| Field | Type | Description |
|---|---|---|
position | string | Where the expression is written, as in integration.webhook.events[0].when or hook.steps[0].with.text. Begins with integration or hook. |
expression | string | The CEL, without ${{ }}. |
definition | object | The whole integration or hook, as it would be created. |
{
"position": "hook.when",
"expression": "event.inputz.query != ''",
"definition": { "key": "grafana-reads", "on": "tool.used", "steps": [{ "name": "notify", "call": "grafana.search" }] }
}The response:
| Field | Type | Description |
|---|---|---|
type | string or null | The CEL type the expression returns, or null when it does not check. |
errors | array | Each has message, span (start, end, or null) and suggestion (or null). |
warnings | array | Each has position and message. |
422 when the request is not shaped as a check, when the position names
neither an integration nor a hook attribute, when the definition has errors
(each listed under definition), or when the position contains no expression in
the definition.
Positions API
GET /api/v1/expressions/positionsReturns every position, integration and hook, as a list. It needs any credential.
| Field | Type | Description |
|---|---|---|
position | string | The position, beginning with integration or hook, with [*] for any key or index, as in integration.webhook.events[*].when. |
returns | string or null | bool, list, or null. |
variables | array | The variables the expression can read, each with name, type and nested fields. |
addedVariables | array | Variables that only some definitions add: item, captures, inputs. |
calls | array | What can call an expression at the position, each with by (task, chat, inbox-request or notice for a binding of that kind of event, tool, lookup or schedule) and the variables that this caller has. Empty where the variables do not depend on what calls the expression. |