Build
Hearing the workspace
Events go from your app to the workspace. This is the other way: the workspace tells your app when something happens there, at its server, on its open pages, or by doing what your manifest says. The clearest case is removal. When an owner removes your app, you're told, so you can let go of what you keep for that workspace: tokens, settings, anything stored per workspace. Your app can also hear what happens in the workspace (tasks, files, people and spaces) without anybody having it open.
Listening
Name the events in your manifest, with the path the workspace sends them to:
{
"permissions": ["tasks.read"],
"listen": {
"events": ["app.installed", "app.removed", "task.created", "task.updated"],
"webhook": "/tands/events"
}
}events: what you listen for, each once. The workspace sends only these.webhook: a path on your app's own origin, like a tab'surl. An address anywhere else is refused, so events only ever go to your app.
Admins see what your app hears when they install it, beside what it reads. A tab with no server can't have a webhook: it has no server to send to.
What you hear
Your app's own
Its lifecycle. These need no permission.
| Event | When | data |
|---|---|---|
app.installed | It's installed in a workspace | by, permissions |
app.updated | A new manifest is taken (an admin chose Check for updates), or, without a server, new files | by, permissions |
app.permissions_changed | What it may read changed | by, permissions, added, removed |
app.removed | It's removed. Nothing more is sent after this one. | by, dataDeleted |
workspace.read_only_changed | The workspace became read-only for an unpaid bill, or stopped being | readOnly |
byis who did it:{ id, name }, ornullwhen nobody did.permissionsis everything it may read now.dataDeletedsays whether the admin removed its data in the workspace too.
What happens in the workspace
Each needs the read it goes with in your manifest's permissions (a manifest that listens without it is refused), and carries what it's about as reading the workspace returns it. A server told with nobody looking doesn't need to read it back.
| Event | When | Needs | data |
|---|---|---|---|
task.created | A task is added | tasks.read | by, task |
task.updated | Its title, status, assignees or due date change | tasks.read | by, task, changed, before |
task.deleted | It's deleted | tasks.read | by, task (as it was) |
file.added | A file is uploaded, or comes back from the trash | files.read | by, file, recovered |
file.removed | It goes into the trash (a folder's files with it) | files.read | by, file |
member.joined | Someone joins the workspace | members.read | by, member |
member.role_changed | An owner or admin changes someone's role | members.read | by, member, from, to |
space.created | A space is created | spaces.read | by, space |
space.archived | It's archived | spaces.read | by, space |
space.unarchived | It comes back from the archive | spaces.read | by, space |
space.deleted | It's deleted, with its tasks and files | spaces.read | by, space |
action.decided | Someone approves or declines one of your actions an agent asked for, or it expires | none | by, approval, action, input, status, note |
message.posted | A message is posted (an agent's answer once it's written) | messages.read | by, message |
message.edited | Its author changes what it says | messages.read | by, message |
message.deleted | It's deleted | messages.read | by, message (where it was: id, spaceId, tabId, threadId) |
taskis a task astasks.listreturns it;fileasfiles.listreturns it (never its content);memberasmembers.listreturns it.changedlists what changed oftitle,status,assigneesanddueAt;beforehas what those were. Moving a task within its column, or changing its description, isn't sent.spaceis{ id, kind, name, description, visibility, createdAt }.action.decided:statusisapproved,declinedorexpired;noteis what the person who declined said. An approved action also runs on your server as usual.- A new version of a file isn't sent.
messageis a message asmessages.listreturns it: mentions as@Name, files named, never read. A deleted one says only where it was, never what it said. An agent's answer is sent once, when it's written, not while it's thinking (an answer tried again is sent again, with the sameid). Reactions aren't sent.
Only where your app is. With nobody looking, nobody's access decides what your app hears, so where it is does:
- Tasks and files are heard from the spaces where your app has a tab. A private space is heard only if someone there added your tab: their choice, as with reads.
- People are heard across the workspace.
- Spaces: public ones, and private ones only where your app has a tab. My Space and direct messages are never heard of.
- Messages are heard only from the spaces where your app has a tab, public or private: never from the rest of the workspace, even public spaces, and never from DMs or My Space, even with your tab there.
- A space's own app (made in a space, for it alone) hears that space's tasks, files and messages, and nothing of the rest.
A webhook hears what happens from when it's first sent something: it isn't sent history from before. Event names your deployment doesn't know yet are accepted in your manifest and not sent, so a manifest can list events newer deployments send.
What's sent
A POST to your webhook, with a JSON batch of up to 100 events, in order:
{
"workspace": { "id": "6650…", "slug": "acme", "name": "Acme" },
"app": { "id": "acme-crm" },
"events": [
{
"id": "acme-crm:12",
"seq": 12,
"type": "app.removed",
"at": "2027-01-15T08:00:00.000Z",
"data": { "by": { "id": "6651…", "name": "Ada Lovelace" }, "dataDeleted": false }
}
],
"missed": 0
}seqcounts from 1 for your app in that workspace, and keeps counting if it's installed again.idis<app>:<seq>. Events come at least once, so drop anidyou've had already.missedcounts events that were dropped before they could be sent (see Kept so long).
Checking it
Every request carries Authorization: Bearer <token>. The token is signed by the workspace's deployment with the same keys as tab tokens, and vouches for exactly this body. Check it with verifyEvents():
import { fetchKeys, verifyEvents } from "@tabs-and-spaces/sdk/server";
const WORKSPACE = "https://chat.acme.com"; // a deployment you serve
const keys = await fetchKeys(WORKSPACE); // cache these
export async function onEvents(request: Request) {
const batch = await verifyEvents(request, {
keys,
audience: "https://crm.example.com", // your app's origin
issuer: WORKSPACE,
});
for (const event of batch.events) {
if (event.type === "app.removed") await forgetWorkspace(batch.issuer, batch.workspace.id);
}
return new Response(null, { status: 204 });
}It throws a TokenError when:
- there's no token;
- the token isn't signed by one of
keys; - it's for another app or deployment, or has expired;
- it isn't an events token;
- it was signed for another body or batch.
Answer 401. Decide which deployments you serve as for tabs: read the token's issuer, check it against your list, then verify with its keys.
The token's claims, if you check it yourself:
| Claim | What it is |
|---|---|
iss | The deployment's address |
aud | Your app's origin |
use | app-events |
wsp | The workspace's id |
app | Your app's id |
sha | The body's SHA-256, base64url |
exp | Five minutes after it was signed |
A tab's token is never an events token, and verifyToken() refuses events tokens, so neither can stand in for the other.
Answering
| You answer | What happens |
|---|---|
2xx | The batch is taken. The next one, if any, follows. |
410 | Sending stops. Admins see it in Settings → Apps, and can send again. |
| Anything else, or no answer in 10 seconds | It's tried again later, waiting longer each time, up to an hour between tries. |
One batch is in flight at a time for each workspace, so events arrive in order. After three days of failures, sending stops, and Settings → Apps shows owners and admins what went wrong, with Try again. Events wait meanwhile.
Answer quickly: take the batch, then do slow work afterwards.
Your pages hear too
Your app's pages hear what it listens for, with or without a server, and so does a tab with no server: name the events in listen, without a webhook.
While a page is open, onEvent is called as it happens, for what happens where the page is and across the workspace, and only what the person looking may see:
import { connect } from "@tabs-and-spaces/sdk";
const tands = await connect();
tands.onEvent("task.created", ({ data }) => addCard(data.task));
tands.onEvent((event) => console.log(event.type)); // every typeA page opened later catches up with events.since(cursor): what your app heard after cursor, everywhere, as the person looking may see it. Keep the cursor it gives (in your app's data, say) and pass it next time; without one, it starts from the oldest kept.
const seen = await tands.values("user").get("events-cursor");
const { events, cursor, missed } = await tands.events.since(seen);
for (const event of events) apply(event);
if (missed > 0) await reloadEverything(); // some were dropped before you caught up
await tands.values("user").set("events-cursor", cursor);Who may see what:
- Your app's own lifecycle: everyone in the workspace.
- People, and public spaces: the workspace's people, not guests (they see only their own spaces).
- A space's tasks, files and messages, a private space's news, and your actions' approvals: those who can read that space.
The cursor moves past what the person can't see, so the next call doesn't scan it again. more says more wait: ask again with cursor.
Reacting with nothing open
A page hears only while someone has it open, and a tab with no server has no server to tell. To do something whenever an event happens, open or not, give listen reactions: each runs one of your records actions on your app's own data, with fields from the event. The workspace does it: none of your code runs.
{
"permissions": ["tasks.read"],
"data": {
"collections": {
"log": {
"scope": "tab",
"fields": {
"title": { "type": "string", "required": true },
"task_id": { "type": "string" },
"status": { "type": "string" },
"who": { "type": "string" }
}
}
}
},
"actions": {
"log_task": { "description": "Log a task", "records": { "collection": "log", "op": "create" } },
"update_entry": {
"description": "Change an entry",
"records": { "collection": "log", "op": "update" }
},
"delete_entry": {
"description": "Delete an entry",
"records": { "collection": "log", "op": "delete" }
}
},
"listen": {
"events": ["task.created", "task.updated", "task.deleted"],
"reactions": [
{
"on": "task.created",
"run": "log_task",
"input": {
"title": "{{task.title}}",
"task_id": "{{task.id}}",
"status": "{{task.status}}",
"who": "{{by.name}}"
}
},
{
"on": "task.updated",
"when": { "changed": "status" },
"run": "update_entry",
"match": { "task_id": "{{task.id}}" },
"input": { "status": "{{task.status}}" }
},
{ "on": "task.deleted", "run": "delete_entry", "match": { "task_id": "{{task.id}}" } }
]
}
}| Field | Required | Rules |
|---|---|---|
on | Yes | An event in listen.events. |
run | Yes | One of your records actions that creates, updates or deletes, on a workspace, space or tab collection (not user: nobody's looking when it runs). |
when | No | Up to 10 paths into the event and the value each must be (or a list, one of them). A list in the event, like changed, need only include it. null: missing. |
match | To update or delete | The fields of the records to change or delete, up to 50 of them. Matching none does nothing. |
input | No | The fields to set. Not for deleting. |
Values are written as they are, or with {{path}} filled in from the event's data: {{task.title}}, {{by.name}}, {{task.assignees.0.name}}; {{event.type}} and {{event.at}} are the event's own. On its own, {{path}} keeps what's there (a number stays a number; missing is null); in other words, it becomes words, people and spaces by their names and lists by commas ("{{by.name}} closed {{task.title}}"). What's filled in is checked against the collection's fields, as anything your app saves is.
Where. It acts where the event happened: a space collection in that space, a tab collection in each of your tabs there, a workspace collection once. An event outside any space (someone joining the workspace) can only go to a workspace collection.
As your app. Its records are made by your app (createdBy is app:<your id>, with your app's name), and its open pages are told the data changed, as with any change.
In order, once each. Reactions are done in the order things happened, a moment after (within half a minute at most). One that doesn't work (a required field left empty, say) is passed over, and the workspace's owners and admins see why in Settings → Apps; anything else that breaks is tried again later. While the workspace is read-only they wait, and are done once it isn't.
Installing shows them as What it does by itself, with the actions they run.
Trying them: tands dev does your reactions on its sample data when you send a test event, and says what each did.

Kept so long
The workspace keeps each app's events for 30 days, and at most the last 5,000. Events dropped before they could be sent are counted in the next batch's missed.
Older deployments
Deployments before 0.9.0 send nothing, and ignore listen. A deployment that sends events says so when it fetches your manifest: its tands-features header includes events. Event names it doesn't send yet are kept and not sent, so your manifest can list newer ones.
A deployment that doesn't hear messages yet doesn't know messages.read either, and refuses a manifest asking for it.
A deployment that doesn't do reactions yet ignores them: your pages and server still hear.