Tabs & Spaces Developers

Build

Events

An event is something that happens in your app: a deal is won, a form is sent, a build fails. You declare your events in your manifest and report them when they happen. In a space where your app has a tab, people can make a trigger that starts a task when your event is reported: "when Acme CRM says a deal was won, a task to thank the customer, for Ada".

How it goes

  1. Something happens in your app, and you report it: from your tab's page, from your server while it answers an action, or from your server at any time with the tab's event key.
  2. The workspace checks it against your manifest: the event's name, and its fields.
  3. Triggers in that space listening for it start their task, for the person who made the trigger. The task says what happened, and can use your event's fields.

Your app is never told about the task: triggers are the space's own. For the other way, the workspace telling your server what happens to your app there, see Hearing the workspace.

Declaring an event

json
{
  "events": {
    "deal_won": {
      "description": "A deal was won",
      "fields": {
        "title": { "type": "string", "required": true, "description": "The deal" },
        "amount": { "type": "number" },
        "stage": { "type": "string", "enum": ["new", "renewal"] }
      }
    }
  }
}
  • description is what people see when they choose your event in a trigger: say what happened, in a few words.
  • fields take the same types as collections, and are checked when you report the event.
  • A field called title, name or subject names what the event is about, in the trigger's history.

See The manifest for every rule.

Reporting from your tab

ts
import { connect } from "@tabs-and-spaces/sdk";

const tands = await connect();
await tands.emit("deal_won", { title: "Globex", amount: 12000, stage: "renewal" });

It's reported for the person looking, in the space your tab is in. Only people in the space can report events (someone only looking at a public space can't).

Reporting from your server

While your server answers an action, it can report events with the key the action's request carries:

ts
import { dataClient } from "@tabs-and-spaces/sdk/server";

const data = dataClient(body);
await data.emit("deal_won", { title: body.input.title });

Reporting from your server, at any time

When something happens outside a request (a webhook from another service at 3 a.m., a job finishing), your server reports it with the tab's event key. Your tab asks for one, once:

ts
import { connect } from "@tabs-and-spaces/sdk";

const tands = await connect();
const { key, eventsUrl } = await tands.requestEventKey();
// Send both to your server, with who and where (tands.context), and keep the key secret.

The person sees what's asked ("Let this tab report events from its server?") and allows it. Only people who manage the space's tabs can; for anyone else it fails with FORBIDDEN, and with DECLINED if they choose Not now. Your server then reports with it whenever it likes:

ts
import { reportEvent } from "@tabs-and-spaces/sdk/server";

await reportEvent({ key, eventsUrl }, "deal_won", { title: "Globex", amount: 12000 });
  • It's checked like any report: your manifest's events and their fields, and the same limits.
  • Events report for the person who allowed it, in that tab's space: triggers there start their tasks as usual. Events reported this way do start triggers (a person allowed them).
  • A tab has one key. Asking again makes a new one, and the last stops working. Anyone who manages the space's tabs can Turn off the key below the tab.
  • The key stops working too when the person who allowed it can no longer reach the tab, the tab is removed, or your app is removed. Reports then fail with 401: ask for a key again next time someone opens your tab.

In a trigger

In a Tasks tab, Recurring… → When something happens → Something happens in an app lists the space's Custom tabs whose app reports events. People choose your event, and optionally a value one of its fields must have ("only when stage is renewal").

A new trigger: when something happens in an app, Notes, Someone added a note, every time; it creates a task called Follow up: {{text}}.
A trigger on your event. The task can use what the event carries, here {{text}}.
The task's title and description can use your fields by name, like {{title}} or {{amount}}, as well as {{summary}} (what it's about) and {{details}} (every field, one per line).

Your actions in workflows

The same space's workflows can use your actions as steps: Use an app picks one of your Custom tabs here and an action, with its inputs written out (they may say {{previous}}, the last step's result, and {{task}}). An action that changes something asks the person the workflow runs for first, on a card in the task's thread; one that only reads runs at once. What your server answers becomes the next step's {{previous}}.

Limits

An app can report up to 60 events a minute in a workspace; more are refused (429). A trigger that fires more than 20 times in an hour pauses until someone resumes it.

While the workspace is read-only

A workspace whose bill is long overdue is read-only until it's paid. Events from your tab's page are refused then (423 WORKSPACE_READ_ONLY). Events from your server are still taken (200), because what happens elsewhere doesn't wait for a bill.

The workspace holds those events, and starts their triggers once it's paid, oldest first. It holds them for a week at most, and up to 200 at once in a workspace. Anything older or beyond that is let go. Held events start about ten an hour per trigger, so a trigger doesn't pause for firing too often. Each task they start says when its event really happened. Meanwhile, each trigger in the space's Tasks tab shows how many it's holding, and until when.

tands dev plays this too: with Read-only on, your server's events show as held.

Starting tasks on your events

Events only start tasks through a trigger in the space. To take people there, call openTrigger(): the workspace opens a new trigger in the space's Tasks tab, set to start on your event in this tab, and the person chooses the task and saves it.

ts
try {
  await tands.openTrigger("deal_won");
} catch (error) {
  // NO_TASKS_TAB: triggers live in a Tasks tab, and this space has none yet.
}

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