Skip to content

Commit

Permalink
add documentation how to listen to view_closed events slackapi#1010
Browse files Browse the repository at this point in the history
  • Loading branch information
TheManWhoStaresAtCode committed Nov 18, 2021
1 parent 3e8a0f9 commit 0aa228b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions docs/_basic/listening_modals.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
---
title: Listening for view submissions
title: Listening for view changes
lang: en
slug: view-submissions
order: 12
---

<div class="section-content">
If a <a href="https://api.slack.com/reference/block-kit/views">view payload</a> contains any input blocks, you must listen to `view_submission` requests to receive their values. To listen to `view_submission` requests, you can use the built-in `view()` method.

`view()` requires a `callback_id` of type `string` or `RegExp`.
If a <a href="https://api.slack.com/reference/block-kit/views">view payload</a> contains any input blocks, you must listen to `view_submission` requests to receive their values.
If the `notify_on_close` flag of a view is active, an respective event is sent when a view has been closed.
To listen to either a `view_submission` request or `view_closed` event, you can use the built-in `view()` method.

You can access the value of the input blocks by accessing the `state` object. `state` contains a values object that uses the `block_id` and unique `action_id` to store the input values.
`view()` requires a `callback_id` of type `string` or `RegExp` or a constraint object with properties `type` and `callback_id`.

---

##### Update views on submission

You can access the value of the input blocks by accessing the `state` object. `state` contains a values object that uses the `block_id` and unique `action_id` to store the input values.
To update a view in response to a `view_submission` request, you may pass a `response_action` of type `update` with a newly composed `view` to display in your acknowledgement.

```javascript
Expand Down Expand Up @@ -69,3 +71,23 @@ app.view('view_b', async ({ ack, body, view, client }) => {

});
```

---

##### handle view closed events

The built-in `view()` method can also handle `view_closed` events, which are sent when a <a href="https://api.slack.com/reference/block-kit/views">view payload</a> has the `notify_on_close` flag set.
The event contains the respective `callback_id` of the closed view.
Please note that you have to specify the `type: 'view_closed'` in the constraint object explicitly, since otherwise the handler is not triggered.

See the <a href="https://api.slack.com/surfaces/modals/using#modal_cancellations">API documentation</a> for more information about the view closed event.

```javascript
// Handle a view_canceled event
app.view({ type: 'view_closed', callback_id: 'view_b' }, async ({ ack, body, view, client }) => {
// Acknowledge the view_closed event
await ack();

// react on close event
});
```

0 comments on commit 0aa228b

Please sign in to comment.