Skip to content

Server events and webhooks ​

Without these, your server half runs only when someone clicks, types a command, or on a timer of at least five minutes. Events wake it when something happens on the server; webhooks wake it when an outside service — GitHub, Twitch, a game server, a calendar — has news.

Both need a server half and manifest version 2.

Events ​

json
{ "manifest_version": 2, "events": ["member.joined", "member.left"] }
EventWhenWhat you get
member.joinedsomeone joins the serveruser: { id, name }
member.leftsomeone leaves, is kicked or banned (no reason given)user
voice.joinedsomeone joins a voice channeluser, channel: { id, name }
voice.leftsomeone leaves a voice channeluser, channel
reaction.on_own_postsomeone adds or removes a reaction on your plugin's own postaction: "added" | "removed", message_id, emoji (null when the reaction is encrypted), user, channel
role.changedsomeone gets or loses a role — by an admin, their own onboarding choice, or another pluginaction: "added" | "removed", user, role: { id, name }, by ({ user }, { plugin } or { self: true }). A change your own plugin made is never sent back to you.

Every event also has type, server_id and at. Never message content — a plugin can never read a channel. Events cover every channel on the server, private ones included, which is why the admin sees them before installing.

js
import { events, output } from "./server-sdk.js"; // the server SDK, bundled into your module

const posts = [];
for (const ev of events() ?? []) {   // null when this run is something else
  if (ev.type === "member.joined") {
    posts.push({ channel_id: WELCOME_CHANNEL, content: `Welcome, ${ev.user.name}!` });
  }
}
output({ posts }); // up to 3 posts, needs bot:post; they appear live

Bursts arrive together (several events in one run, oldest first, at most about once a second). Each install has an hourly event budget (600 by default; the node and server admins can lower it). Past it, events are dropped — never delivered late — and the admin sees the count on the Activity tab. A paused plugin gets no events.

Webhooks ​

json
{ "manifest_version": 2, "webhooks": [{ "name": "github", "description": "New releases" }] }

A server admin opens your plugin's Permissions tab and presses Make link. Dissent shows a secret link once:

https://<their node>/api/v1/hooks/<install>/github/<secret>

They paste it into the outside service. New link replaces it (the old one stops at once); Delete switches it off. The link grants nothing but "wake this plugin with this message".

A POST runs your server half with trigger "webhook":

js
import { webhook, output } from "./server-sdk.js"; // the server SDK, bundled into your module

const call = webhook();               // null unless this run is a webhook call
if (call?.headers["x-github-event"] === "release") {
  const release = call.json()?.release;
  output({ posts: [{ channel_id: NEWS_CHANNEL, content: `New release: ${release.name}` }] });
}

call is { webhook, content_type, headers, body, body_base64?, received_at, json() }. Only a short list of headers reaches you (content type, user agent, GitHub/GitLab/Twitch event names and delivery ids) — never cookies, Authorization, or the sender's address.

What the node checks, and what the caller sees:

CheckAnswer
Wrong install, name or secret; webhook switched off; no longer in your manifest404 (always the same)
Body over 256 KB413
X-Hub-Signature-256 (GitHub) or X-Dissent-Signature sent and wrong401
Webhook-Timestamp / X-Dissent-Timestamp older than 5 minutes401
Over 30 calls a minute to this webhook (adjustable)429 with Retry-After
Plugin paused, or its server half is not running503
A delivery id seen in the last day (X-GitHub-Delivery, Webhook-Id, …)200 {"duplicate": true}, not run again
Accepted202 at once — your code runs in the background, its output is never sent back

Signing (optional, recommended). For GitHub, paste the link's last part (the secret) as the webhook's Secret: Dissent then checks X-Hub-Signature-256 on every call. Your own senders can send X-Dissent-Timestamp: <unix seconds> and X-Dissent-Signature: sha256=<hex HMAC-SHA256(secret, timestamp + "." + body)>.

A webhook held at ten times its limit for five minutes pauses the plugin; the admin sees why and can press Resume.

Webhooks that answer (replies) ​

For a companion app that asks your plugin something and needs the answer — a DAW bridge, a game server, a stream deck, a build bot — mark the webhook "reply": true:

json
{ "manifest_version": 2, "webhooks": [{ "name": "ask", "description": "The companion app asks", "reply": true }] }

Your server half then answers the caller with { reply: { body } }:

js
import { plugin, storage } from "./server-sdk.js";

export const run = plugin({
  webhooks: {
    ask: (call) => {           // call.reply === true: the caller is waiting
      const q = call.json();
      return { reply: { body: { tempo: storage.get("tempo") ?? 120, asked: q?.what ?? null } } };
    },
  },
});

The caller gets 200 with body as JSON (any JSON value, 64 KB at most), or 204 when your run answered no reply. You may still answer { posts }, { followups }, { edits } in the same run — they are carried out after the caller has its answer. You cannot set a status, a header or a redirect.

It is a bigger ask than a plain webhook, because a reply link reads what your plugin returns:

  • The admin sees "answers whoever calls … with what it returns" before installing, and an update that adds "reply": true (to a new webhook or an old one) waits for the admin's Approve. Until then the webhook runs as a plain one.
  • Only signed calls. When the admin makes the link, Dissent also shows a reply key (whsec_…) — once, and never in the link. Every call must carry a timestamp (≤ 5 minutes old) and a signature made with that key; anything else is 401 and runs nothing. A link copied from a log is not enough to read anything. New link makes a new key too.
  • It runs while the caller waits, in its own small pool of runs (it never takes the slots plain webhooks use), within the usual 2-second limit, and at half the plain per-webhook limit (15 a minute by default).
  • A run that fails, times out or answers more than 64 KB gets one fixed answer: 502 {"ok": false, "error": "the plugin did not answer"} — never your error text.

Signing a call (the key's bytes are the base64 after whsec_):

js
// Node.js — the companion app
import { createHmac } from "node:crypto";
const key = Buffer.from(REPLY_KEY.replace(/^whsec_/, ""), "base64");
const body = JSON.stringify({ what: "tempo" });
const ts = String(Math.floor(Date.now() / 1000));
const sig = "sha256=" + createHmac("sha256", key).update(ts + "." + body).digest("hex");
const res = await fetch(LINK, { method: "POST", body,
  headers: { "Content-Type": "application/json", "X-Dissent-Timestamp": ts, "X-Dissent-Signature": sig } });
const answer = res.status === 200 ? await res.json() : null;
python
# Python
import base64, hashlib, hmac, json, time, urllib.request
key = base64.b64decode(REPLY_KEY.removeprefix("whsec_"))
body = json.dumps({"what": "tempo"}).encode()
ts = str(int(time.time()))
sig = "sha256=" + hmac.new(key, ts.encode() + b"." + body, hashlib.sha256).hexdigest()
req = urllib.request.Request(LINK, data=body, method="POST", headers={
    "Content-Type": "application/json", "X-Dissent-Timestamp": ts, "X-Dissent-Signature": sig})
answer = json.load(urllib.request.urlopen(req))

A Standard Webhooks library works too: give it the reply key as its secret (webhook-id, webhook-timestamp, webhook-signature). GitHub's X-Hub-Signature-256 is not accepted on a reply webhook (it has no timestamp). Twitch's first check is still answered by Dissent itself and only on plain webhooks — Twitch never reads a reply.

Each call needs a fresh timestamp, and the same signed bytes twice is refused as a replay — put something that changes (a counter, the time) in the body when you ask the same thing again.

In the kit, host.webhook("ask", body) returns reply: { status, body } — what the caller would get.

Live push to a companion app ​

A reply webhook answers when the companion asks. When something changes on your side — a vote lands, a member presses a button, a timer fires — the companion should hear at once, not on its next poll. It does that by holding the webhook's companion stream open, and your server half fills it:

js
import { plugin, companion, storage } from "./server-sdk.js";

export const run = plugin({
  interactions: {
    next_scene: () => {
      const scene = (storage.get("scene") ?? 0) + 1;
      storage.set("scene", scene);
      companion.send("ask", { scene });      // "ask" is the reply webhook above
      return { content: `Scene ${scene}`, visibility: "private" };
    },
  },
});
  • companion.send(webhook, data) names one of your "reply": true webhooks; data is any JSON up to 4 KB (send what changed, not everything). Up to 20 a run, 120 a minute per plugin (the site's limit). It works from any run — a command, a click, an event, a webhook, a timer — except a profile answer, which only reads.
  • The companion connects with GET <link>/stream, signed like a call with the reply key, over <timestamp>.stream:<install id>:<webhook name> instead of a body. Each signature opens one connection. Opening counts as one call to the webhook.
  • What arrives (Server-Sent Events): ready; message with your JSON as data and an increasing id; dropped with {"count": n} when the node let messages go; a keep-alive line every 15 s; and bye with a reason just before it closes.
  • One stream per webhook — a new connection replaces the old one. It closes after 30 minutes (connect again), at once when the admin makes a New link or switches the webhook off, and within about 10 seconds when the plugin is paused or removed or its server half is turned off.
  • Nobody connected? The node keeps the last 32 messages (64 KB) for one minute, then lets them go and tells the companion how many it missed. It is a live push, not a mailbox: keep the state that matters in storage and let the companion ask for it (the reply webhook) when it connects.
js
// Node.js 18+ — the companion app
import { createHmac } from "node:crypto";
const key = Buffer.from(REPLY_KEY.replace(/^whsec_/, ""), "base64");
const [install, webhook] = new URL(LINK).pathname.split("/").slice(-3, -1);
const ts = String(Math.floor(Date.now() / 1000));
const sig = "sha256=" + createHmac("sha256", key).update(`${ts}.stream:${install}:${webhook}`).digest("hex");
const res = await fetch(LINK + "/stream", { headers: { "X-Dissent-Timestamp": ts, "X-Dissent-Signature": sig } });
const text = res.body.pipeThrough(new TextDecoderStream());
let buf = "", event = "";
for await (const chunk of text) {
  buf += chunk;
  for (let i; (i = buf.indexOf("\n")) >= 0; ) {
    const line = buf.slice(0, i); buf = buf.slice(i + 1);
    if (line.startsWith("event: ")) event = line.slice(7);
    else if (line.startsWith("data: ") && event === "message") console.log(JSON.parse(line.slice(6)));
    else if (line === "") event = "";
  }
}
// When it ends, wait 5 seconds and connect again with a fresh signature.

A Python reader with only the standard library is in the kit's sdk/limits.md. In the kit's mock host, host.server.companion lists what companion.send pushed.