Skip to content

Commit 6590c26

Browse files
LotadTechseratch
andauthored
Adding Handling views on close documentation (#792)
Co-authored-by: Kazuhiro Sera <[email protected]>
1 parent 856ae8a commit 6590c26

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/_basic/listening_modals.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@ def handle_submission(ack, body):
2626
Similarly, there are options for [displaying errors](https://api.slack.com/surfaces/modals/using#displaying_errors) in response to view submissions.
2727
Read more about view submissions in our <a href="https://api.slack.com/surfaces/modals/using#handling_submissions">API documentation</a>.
2828

29+
---
30+
31+
##### Handling views on close
32+
33+
When listening for `view_closed` requests, you must pass `callback_id` and add a `notify_on_close` property to the view during creation. See below for an example of this:
34+
35+
See the <a href="https://api.slack.com/surfaces/modals/using#modal_cancellations">API documentation</a> for more information about view_closed.
36+
37+
```python
38+
39+
client.views_open(
40+
trigger_id=body.get("trigger_id"),
41+
view={
42+
"type": "modal",
43+
"callback_id": "modal-id", # Used when calling view_closed
44+
"title": {
45+
"type": "plain_text",
46+
"text": "Modal title"
47+
},
48+
"blocks": [],
49+
"close": {
50+
"type": "plain_text",
51+
"text": "Cancel"
52+
},
53+
"notify_on_close": True, # This attribute is required
54+
}
55+
)
56+
57+
# Handle a view_closed request
58+
@app.view_closed("modal-id")
59+
def handle_view_closed(ack, body, logger):
60+
ack()
61+
logger.info(body)
62+
```
63+
2964
</div>
3065

3166
<div>

0 commit comments

Comments
 (0)