DEVELOPERS · PREVIEW
Modals
Your app opens an input form (a modal) with a trigger_id issued by a member’s action, and receives the submission as view_submission. Modals appear as dialogs on the web and desktop and as sheets on mobile.
This specification is a preview. External developers cannot register apps or issue bot tokens yet (only first-party apps run today). Details may change before registration opens.
Opening a modal
Pass a trigger_id and a view to views.open. A trigger_id can be used once and expires 6 seconds after it is issued.
app.command('/poll', async ({ ack, body, client }) => {
await ack()
await client.views.open({
trigger_id: body.trigger_id,
view: {
type: 'modal',
callback_id: 'create_poll',
title: { type: 'plain_text', text: 'New poll' },
submit: { type: 'plain_text', text: 'Post' },
private_metadata: body.channel_id,
blocks: [
{
type: 'input',
block_id: 'question',
label: { type: 'plain_text', text: 'Question' },
element: { type: 'plain_text_input', action_id: 'value', max_length: 200 },
},
],
},
})
})| Field | Contents |
|---|---|
type | Always modal |
title | plain_text, up to 24 characters |
submit / close | plain_text, up to 24 characters. submit is required when the modal has an input |
blocks | Up to 100 blocks: the card blocks plus input |
private_metadata | Up to 3000 characters, returned as-is on submission |
callback_id | Up to 255 characters |
The returned view has an id and a hash, used to replace it with views.update.
view_submission
When the member submits, Cairn sends the following as payload=<JSON> to your Request URL. Values are at view.state.values[block_id][action_id], as in Slack.
{
"type": "view_submission",
"team": { "id": "<workspace UUID>", "domain": "<slug>" },
"user": { "id": "<user UUID>", "name": "<display name>", "team_id": "<workspace UUID>" },
"api_app_id": "<app UUID>",
"token": "",
"trigger_id": "<one-time ID>",
"view": {
"type": "modal",
"id": "<view UUID>",
"hash": "<hash>",
"callback_id": "create_poll",
"private_metadata": "<channel UUID>",
"title": { ... }, "submit": { ... }, "blocks": [ ... ],
"state": {
"values": {
"question": { "value": { "type": "plain_text_input", "value": "Where shall we go?" } }
}
}
},
"cairn": { "interaction_id": "<UUID>", "channel_id": "<channel UUID>", "locale": "en" }
}- Before delivering, Cairn checks required fields,
min_length/max_lengthand options. Submissions that fail are not delivered; the member sees the input errors - A
static_selectvalue is{ "type": "static_select", "selected_option": { ... } }, andnullfor an optional field left empty - Only one of several simultaneous submissions from the same modal is delivered
- A
trigger_idis included, so you can open another modal after responding
Responding to a submission
Within 3 seconds, return one of:
| Response | Result |
|---|---|
| Empty 200 | Closes the modal |
{"response_action":"clear"} | Closes the modal |
{"response_action":"errors","errors":{...}} | Keeps the modal open and shows each message under the input whose block_id is the key |
{"response_action":"update","view":{...}} | Replaces the modal |
{"response_action":"push","view":{...}} | Replaces instead of stacking (same as update) |
app.view('create_poll', async ({ ack, view }) => {
const question = view.state.values.question.value.value
if (question.includes('?') === false) {
await ack({ response_action: 'errors', errors: { question: 'End the question with “?”' } })
return
}
await ack() // an empty 200 closes the modal
// do slow work such as posting after the ack
})- Error messages are limited to 300 characters.
errorsthat name onlyblock_ids absent from the current modal are treated as an invalid response - An unreadable (non-JSON) response or an invalid
viewkeeps the modal open and shows an error; the member’s input is kept - On a timeout or a non-2xx status the modal also stays open. If the member resubmits, it arrives with the same
cairn.interaction_id - A corrected submission after you returned
errorsgets a newcairn.interaction_id
views.update
- Pass the
view_idand a newview. With ahash, the view is only replaced if it is still that version (otherwisehash_conflict) - While a member’s submission is being delivered to your app you get
view_is_submitting; to replace the view in reply to a submission, returnresponse_action: update - A closed modal returns
not_found - A daily cleanup deletes modals that have not been updated for 30 days, even if still open. Modals with an active submission lease are excluded
Not yet supported in modals
views.pushand stacked modals (pushreplaces)view_closedwhen a modal is dismissed (notify_on_close)- Delivering button and select actions (block_actions) from inside a modal
confirmon astatic_selectinside an input, and themarkdownblock