Apps: blocks, buttons, forms and commands
Posting cards with KembleBlocks, hearing what people press, answering, opening forms, and adding commands to Kemble’s menus.
An app is registered with Kemble — its name, the scopes it asks for, the URL Kemble sends interactions to, its commands and a signing secret — and a workspace installs it. Everything it does is on behalf of a person and within what the workspace allows: an administrator can narrow its scopes and the channels it may use under Apps & agents, and switching it off stops its token, its buttons and its commands on the next request.
Post a card
curl -X POST https://kemble.io/api/apps/messages \
-H "authorization: Bearer $APP_TOKEN" \
-H 'content-type: application/json' \
-d '{
"channelId": "'$CHANNEL'",
"text": "Expense from Ali: £42 on train tickets",
"blocks": [
{ "type": "section", "text": { "format": "markdown", "text": "*Ali* spent **£42** on train tickets." } },
{ "type": "actions", "blockId": "decide", "elements": [
{ "type": "button", "actionId": "approve", "label": "Approve", "value": "expense-42", "style": "primary" },
{ "type": "button", "actionId": "reject", "label": "Reject", "value": "expense-42", "style": "danger",
"confirm": { "title": "Reject it?", "text": "Ali will be told.", "confirmLabel": "Reject", "denyLabel": "Keep it" } }
] }
]
}'text is required: it is what notifications, search and screen readers get, so write it to say what the blocks say. The blocks are drawn in its place, in Kemble Work and Kemble Circle alike.
- The token must carry chat.write, and the workspace must still grant it. It is resolved as the person who authorised the app: the app posts only where they may post, through the channel’s own permissions and overwrites, and only in the channels its installation allows.
- A direct conversation only when it is the app’s own conversation with that person — never one between two people.
- Add "visibleTo": "<user id>" to answer one person in the channel without storing anything.
- PATCH /api/apps/messages/:message with { "text", "blocks" } changes a message the app posted ("blocks": null removes them); DELETE /api/apps/messages/:message removes it.
- Sixty posts a minute per app in each workspace.
Blocks
- heading — a line of bold text, up to 150 characters.
- section — text (format markdown or plain, up to 3,000 characters), with an optional accessory: an image, a button, a select or a date picker.
- fields — up to 10 short texts, drawn in two columns.
- image — an https url and alt text, with an optional title.
- context — up to 10 small texts and images.
- divider.
- actions — up to 5 buttons, selects and date pickers.
- input — a question, in a form only: a text_input, a select or a datepicker, with a label and an optional hint.
- table — up to 10 columns and 100 rows, with an optional title: every row has one cell per column, and a cell is plain words, a number or null (never Markdown or a link). People scroll it sideways and copy it as CSV.
- chart — "chart": "bar" or "line", a title, a summary (what it shows, in words), an xLabel and a yLabel, up to 50 categories and up to 4 series of one number (or null) per category, and an optional unit. Its numbers are also a table, read by screen readers and opened under “The numbers”. At most five tables and charts in one message.
- accent — { "type": "accent", "color": "green" }: the colour of the card’s edge in Kemble Circle, one of red, red-deep, amber, green, steel, graphite or ash (never a hex value). At most one in a message, and never on its own. It carries no words, and Kemble Work draws nothing for it.
A button has an actionId, a label and a value, and a style of default, primary or danger; add confirm to ask first. A button with a url is a link: it opens the page and sends nothing. A select’s source is static (its own options, up to 100), users (people in the workspace) or channels (channels the person can see); set multiple to allow several. A message holds up to 50 blocks and 16,384 bytes of them.
An incoming webhook may post blocks too — add "blocks" beside "text" in the POST to /api/hooks/:token — but not buttons, selects or date pickers that send something, because a webhook has nobody to tell. Link buttons are fine.
Two more shapes of the same webhook
For tools that already post to another service. Both are shown once, beside the plain address, when a webhook is made or given a new address. An older webhook gets them when it is given a new address, or, where there is no New URL, when it is made again.
POST /api/hooks/:token/slack takes text, blocks, attachments, username, icon_url and mrkdwn, as JSON or a payload= form, and answers 200 ok or a short word such as no_text, invalid_payload, channel_is_archived, action_prohibited or no_service.
POST /api/webhooks/{id}/{token} (or /api/v10/webhooks/{id}/{token}) takes content, embeds, username, avatar_url, thread_name and multipart payload_json with files[n]. Add ?wait=true to get the message back, and ?thread_id= to post in a thread. GET, PATCH and DELETE on .../messages/{id} reach only that webhook’s own messages. /github and /slack after the address take those formats too.
Anything too long is cut to fit, and nothing a post says can mention anybody. When a tool sends too fast, it is told how long to wait.
Hearing what people do
When somebody presses a button, makes a choice, picks a date, submits or closes a form, or runs one of the app’s commands, Kemble POSTs JSON to the app’s interaction URL: v, type (block_action, view_submission, view_closed or command), interactionId, appId, organizationId, userId, channelId, messageId, targetUserId, command, actions, view, triggerId, responseUrl, sentAt and message. A button’s value is always the one on the card, never one the person’s client sent.
Answer within three seconds with a 2xx. The body may be empty, or carry a response (the same shape as a response URL takes), a view to open a form, or — for a form’s submission — errors to keep it open with a message under each named question, or a view to replace it.
Check the signature
import { createHmac, timingSafeEqual } from 'node:crypto'
// rawBody: the exact bytes received, before any JSON parsing.
function fromKemble(headers, rawBody, secret) {
const timestamp = headers['x-kemble-timestamp']
const signature = headers['x-kemble-signature'] ?? ''
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false
const expected = createHmac('sha256', secret).update(timestamp + '.' + rawBody).digest('hex')
return signature.length === expected.length && timingSafeEqual(Buffer.from(signature), Buffer.from(expected))
}The timestamp is inside what is signed, so a captured request cannot be replayed behind a fresh one, and a request more than five minutes old — or from five minutes in the future — should be refused. x-kemble-interaction carries the interactionId, so a repeat can be recognised.
Answer later: the response URL
curl -X POST "$RESPONSE_URL" \
-H 'content-type: application/json' \
-d '{ "text": "Approved by Ali", "replaceOriginal": true }'- replaceOriginal: true changes the message that was pressed; without blocks, the card becomes plain text.
- { "deleteOriginal": true } removes it.
- Otherwise the answer goes to the person alone ("visibility": "ephemeral", the default) or to the channel ("visibility": "channel"), where it is posted by the app — and only if the person who acted may post there.
- The URL is the authorization, like an incoming webhook’s: keep it private. It works five times in thirty minutes.
Open a form
const body = JSON.stringify({
triggerId: payload.triggerId,
view: {
v: 1, callbackId: 'reject-reason', title: 'Why reject?', submitLabel: 'Reject',
blocks: [{ type: 'input', blockId: 'reason', label: 'Reason',
element: { type: 'text_input', actionId: 'text', multiline: true, maxLength: 200 } }],
},
})
const timestamp = Math.floor(Date.now() / 1000)
const signature = createHmac('sha256', secret).update(timestamp + '.' + body).digest('hex')
await fetch('https://kemble.io/api/apps/views', {
method: 'POST',
headers: { 'content-type': 'application/json', 'x-kemble-timestamp': String(timestamp), 'x-kemble-signature': signature },
body,
})A trigger opens one form, in front of the person who acted, within ten seconds of the interaction; the request is signed the same way Kemble signs its own. To change a form that is open, send { organizationId, viewId, view } instead. A form holds up to 100 blocks; its answers arrive in view.values, by blockId and then actionId, already checked against the questions asked — a required question answered, a choice from the list, a date that is a date.
Commands
- chat — a /command in the composer; what follows the name arrives as command.text, and as typed options when the command declares them (below). Up to 25.
- message — in a message’s menu, under Apps; the message arrives in message, as the person reads it. Up to 5.
- user — in a person’s menu, under Apps; the person arrives as targetUserId. Up to 5.
- global — in the ⌘K palette. Up to 5.
- Running one needs message.app_commands where it is run, and the app must be allowed in that channel.
- A community can keep an app — or any one of its commands, of any of the four kinds — to chosen roles and channels. A command kept to some channels runs only from a conversation in one of them: a person’s command or a palette shortcut run from a page with no conversation is refused before your app hears of it.
Command options
A chat command may declare up to 25 options: each a name, a description, a type — string, integer, number, boolean, user, channel, role, mentionable or attachment — and whether it is required (required options come first). A string, integer or number option may list up to 25 choices (a name and a value), or set autocomplete to suggest values as it is typed. An integer or number option may set minValue and maxValue, and a string option minLength and maxLength (in characters, 1,000 at most). People write them after the command as name: value — /warn user: @ali reason: Late again — and Kemble Circle’s message box draws them, with its people, role and channel lists.
Kemble checks every value before the app hears anything: a required option is there, a number is a number and inside the bounds the option set, words are neither shorter nor longer than it allows, a choice is on the list, and a person, role or channel is one the person running the command can see where they ran it. The command then arrives with command.options beside command.text: a list of name, type and value — a string, a number or a boolean; for a person, role or channel its id, with resolved giving its kind, id and the name the person reads, and nothing else. A command that declares no options is sent as before.
For an option with autocomplete, Kemble POSTs an interaction of type command_autocomplete as the person types: command.focused names the option, and command.options holds what has been typed so far, unchecked. Answer within three seconds with choices — up to 25, each a name and a value of the option’s type. The person reads the name; the value of the one they pick is what is written into the box and what the command then carries, so show a readable name and send your own id. A value typed by hand is still possible, and arrives checked only against the option’s type and bounds. It carries no triggerId and no responseUrl; an answer that is late or unreadable simply offers no suggestions.
A chat command may be a family instead: subcommands — up to 25, each a name, a description and its own options — and groups of sub-commands, one level deep. Such a command declares no options of its own and is never run bare: people write /perms add user: @ali, or /perms role add role: @mods, and Kemble Circle’s message box offers the sub-commands and then draws the chosen one’s options. The command arrives with command.subcommand and, inside a group, command.group, beside that sub-command’s options. A word that is none of them is refused before your app hears anything.
An option of type attachment takes a file. The person chooses one of their own uploads — never somebody else’s — and its resolved gives the file’s id, name, contentType and size, with a url that opens that one file and nothing else until expiresAt, fifteen minutes after the command was run. Fetch it within that time; the address is not renewed and grants nothing else.
Commands for a person’s own account
In Kemble Circle a person can add your app to their own account, not only a community. Mark a chat command "personal": true to offer it there: after a consent screen that lists what your app may do and see, the person can run it in their direct messages and group conversations, and in communities whose stewards allow apps from people’s accounts. Only chat commands can be personal, and only an app in the directory with an interaction URL can be added. Kemble Work has none of this: a Work workspace adds apps for everybody, as Slack does.
A personal command’s options are words, numbers and yes or no only — string, integer, number and boolean, with choices and bounds as above — and none may use autocomplete, so your app is told nothing while the person is typing. A manifest that breaks either rule is refused. The interaction arrives as any command does, with personal: true: userId is the person who ran it, channelId and organizationId are the place, and message and targetUserId are always null. Your app is never told the conversation’s messages or who is in it.
Answer in your acknowledgement or through responseUrl, as with any command. With visibility: "channel" your words are posted as the person’s own message, drawn as said with your app, through everything their own message would meet; they must be words — blocks there are refused with app.personal_words_only — and they mention nobody. With visibility: "ephemeral" the person alone sees them, and blocks may go there. A form you open with triggerId asks for words, dates and your own choices: a select of people or channels is refused with app.personal_form. A personal app holds no token and cannot post on its own; it answers only the interaction it was handed.
- A person who removes your app stops it at once: its response URLs and forms stop working too.
- A community that turns off apps from people’s accounts stops them there at once, answers still on their way included.
- So does a person’s account being switched off, or a community being suspended: nothing more is said as them through a response URL, a form or a button. A forwarded copy of an answer still says it was said with your app.
- A personal app’s forms and answers to the person alone carry no pictures — an image block, or an image in a section or a context line, is refused with app.personal_picture — since the person’s browser would load it from your server.
- It is not run where somebody in the conversation has blocked or ignores the person, where the person is a guest, or in a channel shared with another organization; the person is told why, and your app hears nothing.
- A community’s rules for your app or one of its commands hold for its personal commands too, and a name the community already uses — a built-in, its own command or another app’s — keeps it.
Which workspaces an app is installed in, and what they allow it, is theirs to decide. The payloads above are all it is told: who acted, where, and what they chose or typed.
A Kemble Work workspace can allow access only from approved networks. While its owners have it on (with Apply to apps too, the default), every call with your app’s token for that workspace must come from one of those networks; any other answers 403 workspace.network_refused. Nothing else changes: the token stays valid, and the same call from an approved network succeeds.