Tabs & Spaces Developers

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:

json
{
  "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's url. 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.

EventWhendata
app.installedIt's installed in a workspaceby, permissions
app.updatedA new manifest is taken (an admin chose Check for updates), or, without a server, new filesby, permissions
app.permissions_changedWhat it may read changedby, permissions, added, removed
app.removedIt's removed. Nothing more is sent after this one.by, dataDeleted
workspace.read_only_changedThe workspace became read-only for an unpaid bill, or stopped beingreadOnly
  • by is who did it: { id, name }, or null when nobody did.
  • permissions is everything it may read now.
  • dataDeleted says 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.

EventWhenNeedsdata
task.createdA task is addedtasks.readby, task
task.updatedIts title, status, assignees or due date changetasks.readby, task, changed, before
task.deletedIt's deletedtasks.readby, task (as it was)
file.addedA file is uploaded, or comes back from the trashfiles.readby, file, recovered
file.removedIt goes into the trash (a folder's files with it)files.readby, file
member.joinedSomeone joins the workspacemembers.readby, member
member.role_changedAn owner or admin changes someone's rolemembers.readby, member, from, to
space.createdA space is createdspaces.readby, space
space.archivedIt's archivedspaces.readby, space
space.unarchivedIt comes back from the archivespaces.readby, space
space.deletedIt's deleted, with its tasks and filesspaces.readby, space
action.decidedSomeone approves or declines one of your actions an agent asked for, or it expiresnoneby, approval, action, input, status, note
message.postedA message is posted (an agent's answer once it's written)messages.readby, message
message.editedIts author changes what it saysmessages.readby, message
message.deletedIt's deletedmessages.readby, message (where it was: id, spaceId, tabId, threadId)
  • task is a task as tasks.list returns it; file as files.list returns it (never its content); member as members.list returns it.
  • changed lists what changed of title, status, assignees and dueAt; before has what those were. Moving a task within its column, or changing its description, isn't sent.
  • space is { id, kind, name, description, visibility, createdAt }.
  • action.decided: status is approved, declined or expired; note is 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.
  • message is a message as messages.list returns 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 same id). 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:

json
{
  "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
}
  • seq counts from 1 for your app in that workspace, and keeps counting if it's installed again.
  • id is <app>:<seq>. Events come at least once, so drop an id you've had already.
  • missed counts 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():

ts
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:

ClaimWhat it is
issThe deployment's address
audYour app's origin
useapp-events
wspThe workspace's id
appYour app's id
shaThe body's SHA-256, base64url
expFive 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 answerWhat happens
2xxThe batch is taken. The next one, if any, follows.
410Sending stops. Admins see it in Settings → Apps, and can send again.
Anything else, or no answer in 10 secondsIt'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:

ts
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 type

A 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.

ts
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.

json
{
  "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}}" } }
    ]
  }
}
FieldRequiredRules
onYesAn event in listen.events.
runYesOne of your records actions that creates, updates or deletes, on a workspace, space or tab collection (not user: nobody's looking when it runs).
whenNoUp 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.
matchTo update or deleteThe fields of the records to change or delete, up to 50 of them. Matching none does nothing.
inputNoThe 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.

What it hears (app removed, tasks added and changed, messages posted) and what it does by itself (log a new task), as an admin sees them before installing.
Installing shows what your app hears, and what it does by itself.

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.

Search every page: actions, the manifest, the SDK, tokens…