# Modals and App Home

> Open a modal for one person and read what they fill in. Draw your app’s Home tab for each person who opens it.

Source: https://slaiky.xyz/docs/modals

A modal is a window your app opens for one person, right after they did something: ran a command, clicked a button, used a shortcut. The Home tab is a page your app draws for each person, in its conversation with them. Both are views: blocks your app sends, shown to one person only.

## Open a modal

Call `views.open` with the `triggerId` of what the person just did, within 30 seconds. A trigger opens one modal. A used or expired one answers `invalid_trigger`. Opening a modal closes any modal the person had open, from any app.

*your app → Slaiky · `views.open`*

```json
{
  "triggerId": "1731240000.trigger.docs",
  "view": {
    "type": "modal",
    "title": "Daily update",
    "submit": "Post",
    "close": "Not now",
    "callbackId": "daily",
    "blocks": [
      { "type": "input", "blockId": "done", "label": "What did you finish?", "element": { "type": "plain_text_input", "actionId": "v", "multiline": true } },
      { "type": "input", "blockId": "mood", "label": "How is it going?", "optional": true, "element": { "type": "static_select", "actionId": "v", "options": [{ "text": "Smooth", "value": "smooth" }, { "text": "Blocked", "value": "blocked" }] } }
    ]
  }
}
```

*Slaiky → your app*

```json
{ "ok": true, "view": { "id": "7f3c0017-5a1e-4c2b-9d6f-1a2b3c4d5e10", "type": "modal", "title": "Daily update", "callbackId": "daily", "previousId": null, "hash": "1731240000.docs", "…": "…" } }
```

## The view

| Field | What it is |
| --- | --- |
| `type` | `"modal"` or `"home"` |
| `title` | The modal’s title, up to 24 characters. A modal needs one |
| `submit`, `close` | The labels of its two buttons, up to 24 characters. A modal with inputs needs `submit` |
| `blocks` | What it shows: the message blocks, plus inputs. Up to 50 |
| `callbackId` | Your name for it. It comes back with everything that happens to it |
| `privateMetadata` | A string for your app, [kept with the view](#keep-your-own-data-with-it) |
| `notifyOnClose` | `true` to hear when the person [closes it](#when-the-person-closes-it) |

The whole schema is on [Views](/docs/reference/blocks#views).

## Inputs

An `input` block has a `blockId`, a `label`, maybe a `hint`, `optional` when it may stay empty, and one `element`. Each `blockId` is used once per view.

| `element.type` | The person gives | It comes back as |
| --- | --- | --- |
| `plain_text_input` | Text (`multiline`, `minLength`, `maxLength`, `placeholder`, `initialValue`) | `value` |
| `static_select` | One of the `options` | `selectedOption` |
| `checkboxes` | Any of the `options` (`initialValues`) | `selectedOptions` |
| `datepicker` | A date (`initialDate`) | `selectedDate`, as `YYYY-MM-DD` |

Buttons and menus in a modal work as in messages: a click sends `block_actions` with the `view`, and a new `triggerId`.

## Stack and change

`views.push` puts a modal on top of the one your app has open. It takes a fresh `triggerId`: a click in the modal brings one. The person goes back with the arrow. Up to 3 can be open at once.

`views.update` changes an open view in place, by its `viewId`. Send its `hash` too: if the view changed since you read it, the call answers `hash_conflict` and changes nothing. Each change gives the view a new `hash`.

## When the person submits

Slaiky checks the inputs first: what isn’t optional is filled in, picks are among the options, dates are dates, text fits its lengths. The person fixes those before your app hears anything. Then it gets `view_submission`, with what they gave under `view.state.values`, by `blockId` and then `actionId`:

*Slaiky → your app · `view_submission`*

```json
{
  "type": "view_submission",
  "userId": "7f3c0008-5a1e-4c2b-9d6f-1a2b3c4d5e07",
  "view": {
    "id": "7f3c0017-5a1e-4c2b-9d6f-1a2b3c4d5e10",
    "callbackId": "daily",
    "privateMetadata": null,
    "hash": "1731240000.docs",
    "state": {
      "values": {
        "done": { "v": { "type": "plain_text_input", "value": "Shipped the export to CSV" } },
        "mood": { "v": { "type": "static_select", "selectedOption": { "text": "Smooth", "value": "smooth" } } }
      }
    }
  },
  "triggerId": "1731240000.trigger.docs",
  "responseUrl": "https://app.slaiky.xyz/api/apps/respond/docs-response-token"
}
```

*your app → Slaiky*

```json
{ "responseAction": "errors", "errors": { "done": "A few more words, please." } }
```

Answer within 3 seconds, in the body of your HTTP answer or the `payload` of your ack:

| You answer | The person sees |
| --- | --- |
| Nothing (an empty `2xx`, an ack without `payload`) | The modal closes |
| `responseAction: "errors"` with `errors`, text by `blockId` | Your words under each input. The modal stays open |
| `responseAction: "update"` with a `view` | This modal, changed |
| `responseAction: "push"` with a `view` | A new modal on top |
| `responseAction: "clear"` | Every modal closes |

An `update` or `push` needs a modal `view` that fits the schema; anything else is shown to the person as a view that can’t be shown. If your app doesn’t answer in time, the modal stays open and the person is told it didn’t answer. To post something after a submission, use its `responseUrl` ([Answer later](/docs/interactivity#answer-later)) or `chat.postMessage`.

## When the person closes it

With `notifyOnClose: true`, closing the modal sends your app `view_closed`, with the `view` and `isCleared`: `true` when every open modal closed at once. Field by field: [a modal closed](/docs/reference/payloads#a-modal-closed-view-closed).

Nobody waits on `view_closed`, so your app needn’t answer it: the person who closed the modal is never told it didn’t. In Socket Mode, acknowledge it like any envelope all the same.

## Keep your own data with it

`privateMetadata` is a string of up to 3000 characters that stays with the view: an id, a little JSON. It comes back in `view_submission`, `view_closed` and the clicks inside the view, and never reaches the person’s screen.

## App Home

Turn it on in the app’s page, **App Home → Home tab**, or with `features.app_home.home_tab_enabled` in a [manifest](/docs/manifests). Your app’s conversation with each person then has two tabs: **Home** and **Messages**.

When someone opens Home, your app gets `app_home_opened`, if it hears that event (**Events → Events it hears**). Draw their Home with `views.publish`:

*Slaiky → your app · `app_home_opened`*

```json
{ "type": "event_callback", "event": { "type": "app_home_opened", "userId": "7f3c0008-5a1e-4c2b-9d6f-1a2b3c4d5e07", "channelId": "7f3c0016-5a1e-4c2b-9d6f-1a2b3c4d5e0f", "tab": "home" }, "…": "…" }
```

*your app → Slaiky · `views.publish`*

```json
{
  "userId": "7f3c0008-5a1e-4c2b-9d6f-1a2b3c4d5e07",
  "view": { "type": "home", "blocks": [{ "type": "header", "text": "Hi there" }, { "type": "section", "text": "Your week, at a glance." }] }
}
```

Each person has their own Home. `views.publish` draws it for one `userId`, at any time, with no trigger; send the `hash` to avoid overwriting a newer one. A Home has no inputs, but its buttons and menus send `block_actions` with the `view` and a `triggerId`, so a click there can open a modal. With the Home tab off, `views.publish` is refused.

## The Messages tab

**Messages tab** (`messages_tab_enabled`, on unless you turn it off) is where people and your app talk. Turn on **Only the app writes** (`messages_tab_read_only_enabled`) and people read your app’s messages there but can’t reply.
