Cairn Developers

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 },
        },
      ],
    },
  })
})
FieldContents
typeAlways modal
titleplain_text, up to 24 characters
submit / closeplain_text, up to 24 characters. submit is required when the modal has an input
blocksUp to 100 blocks: the card blocks plus input
private_metadataUp to 3000 characters, returned as-is on submission
callback_idUp 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_length and options. Submissions that fail are not delivered; the member sees the input errors
  • A static_select value is { "type": "static_select", "selected_option": { ... } }, and null for an optional field left empty
  • Only one of several simultaneous submissions from the same modal is delivered
  • A trigger_id is included, so you can open another modal after responding

Responding to a submission

Within 3 seconds, return one of:

ResponseResult
Empty 200Closes 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. errors that name only block_ids absent from the current modal are treated as an invalid response
  • An unreadable (non-JSON) response or an invalid view keeps 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 errors gets a new cairn.interaction_id

views.update

  • Pass the view_id and a new view. With a hash, the view is only replaced if it is still that version (otherwise hash_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, return response_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.push and stacked modals (push replaces)
  • view_closed when a modal is dismissed (notify_on_close)
  • Delivering button and select actions (block_actions) from inside a modal
  • confirm on a static_select inside an input, and the markdown block