Skip to content

Commit fda705f

Browse files
Docs: reorganizes nav to match Bolt JS style (#1241)
1 parent 42af666 commit fda705f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+641
-825
lines changed

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Then grab the latest version of Node.
7171
nvm install node
7272
```
7373

74-
7574
If you are running this project locally for the first time, you'll need to install the packages with the following command:
7675

7776
```

docs/content/basic/action-listening.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

docs/content/basic/action-respond.md

Lines changed: 0 additions & 36 deletions
This file was deleted.
File renamed without changes.

docs/content/concepts/actions.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Listening & responding to actions
3+
lang: en
4+
slug: /concepts/actions
5+
---
6+
7+
Your app can listen and respond to user actions, like button clicks, and menu selects, using the `action` method.
8+
9+
## Listening to actions
10+
11+
Actions can be filtered on an `action_id` parameter of type `str` or `re.Pattern`. The `action_id` parameter acts as a unique identifier for interactive components on the Slack platform.
12+
13+
You'll notice in all `action()` examples, `ack()` is used. It is required to call the `ack()` function within an action listener to acknowledge that the request was received from Slack. This is discussed in the [acknowledging requests guide](/concepts/acknowledge).
14+
15+
Refer to [the module document](https://tools.slack.dev/bolt-python/api-docs/slack_bolt/kwargs_injection/args.html) to learn the available listener arguments.
16+
17+
```python
18+
# Your listener will be called every time a block element with the action_id "approve_button" is triggered
19+
@app.action("approve_button")
20+
def update_message(ack):
21+
ack()
22+
# Update the message to reflect the action
23+
```
24+
25+
### Listening to actions using a constraint object
26+
27+
You can use a constraints object to listen to `block_id`s and `action_id`s (or any combination of them). Constraints in the object can be of type `str` or `re.Pattern`.
28+
29+
```python
30+
# Your function will only be called when the action_id matches 'select_user' AND the block_id matches 'assign_ticket'
31+
@app.action({
32+
"block_id": "assign_ticket",
33+
"action_id": "select_user"
34+
})
35+
def update_message(ack, body, client):
36+
ack()
37+
38+
if "container" in body and "message_ts" in body["container"]:
39+
client.reactions_add(
40+
name="white_check_mark",
41+
channel=body["channel"]["id"],
42+
timestamp=body["container"]["message_ts"],
43+
)
44+
```
45+
46+
## Responding to actions
47+
48+
There are two main ways to respond to actions. The first (and most common) way is to use `say()`, which sends a message back to the conversation where the incoming request took place.
49+
50+
The second way to respond to actions is using `respond()`, which is a utility to use the `response_url` associated with the action.
51+
52+
Refer to [the module document](https://tools.slack.dev/bolt-python/api-docs/slack_bolt/kwargs_injection/args.html) to learn the available listener arguments.
53+
54+
```python
55+
# Your listener will be called every time an interactive component with the action_id “approve_button” is triggered
56+
@app.action("approve_button")
57+
def approve_request(ack, say):
58+
# Acknowledge action request
59+
ack()
60+
say("Request approved 👍")
61+
```
62+
63+
### Using `respond()` method
64+
65+
Since `respond()` is a utility for calling the `response_url`, it behaves in the same way. You can pass [all the message payload properties](https://api.slack.com/reference/messaging/payload) as keyword arguments along with optional properties like `response_type` (which has a value of `"in_channel"` or `"ephemeral"`), `replace_original`, `delete_original`, `unfurl_links`, and `unfurl_media`. With that, your app can send a new message payload that will be published back to the source of the original interaction.
66+
67+
```python
68+
# Listens to actions triggered with action_id of “user_select”
69+
@app.action("user_select")
70+
def select_user(ack, action, respond):
71+
ack()
72+
respond(f"You selected <@{action['selected_user']}>")
73+
```
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ lang: en
44
slug: /concepts/adapters
55
---
66

7+
Adapters are responsible for handling and parsing incoming requests from Slack to conform to [`BoltRequest`](https://github.com/slackapi/bolt-python/blob/main/slack_bolt/request/request.py), then dispatching those requests to your Bolt app.
78

8-
Adapters are responsible for handling and parsing incoming requests from Slack to conform to <a href="https://github.com/slackapi/bolt-python/blob/main/slack_bolt/request/request.py">`BoltRequest`</a>, then dispatching those requests to your Bolt app.
9-
10-
By default, Bolt will use the built-in <a href="https://docs.python.org/3/library/http.server.html">`HTTPServer`</a> adapter. While this is okay for local development, <b>it is not recommended for production</b>. Bolt for Python includes a collection of built-in adapters that can be imported and used with your app. The built-in adapters support a variety of popular Python frameworks including Flask, Django, and Starlette among others. Adapters support the use of any production-ready web server of your choice.
9+
By default, Bolt will use the built-in [`HTTPServer`](https://docs.python.org/3/library/http.server.html) adapter. While this is okay for local development, **it is not recommended for production**. Bolt for Python includes a collection of built-in adapters that can be imported and used with your app. The built-in adapters support a variety of popular Python frameworks including Flask, Django, and Starlette among others. Adapters support the use of any production-ready web server of your choice.
1110

1211
To use an adapter, you'll create an app with the framework of your choosing and import its corresponding adapter. Then you'll initialize the adapter instance and call its function that handles and parses incoming requests.
1312

14-
The full list adapters, as well as configuration and sample usage, can be found within the repository's <a href="https://github.com/slackapi/bolt-python/tree/main/examples">`examples` folder</a>.
15-
13+
The full list adapters, as well as configuration and sample usage, can be found within the repository's [`examples`](https://github.com/slackapi/bolt-python/tree/main/examples)
1614

1715
```python
1816
from slack_bolt import App
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ lang: en
44
slug: /concepts/app-home
55
---
66

7-
<a href="https://api.slack.com/surfaces/tabs/using">Home tabs</a> are customizable surfaces accessible via the sidebar and search that allow apps to display views on a per-user basis. After enabling App Home within your app configuration, home tabs can be published and updated by passing a `user_id` and <a href="https://api.slack.com/reference/block-kit/views">view payload</a> to the <a href="https://api.slack.com/methods/views.publish">`views.publish`</a> method.
7+
[Home tabs](https://api.slack.com/surfaces/tabs/using) are customizable surfaces accessible via the sidebar and search that allow apps to display views on a per-user basis. After enabling App Home within your app configuration, home tabs can be published and updated by passing a `user_id` and [view payload](https://api.slack.com/reference/block-kit/views) to the [`views.publish`](https://api.slack.com/methods/views.publish) method.
88

9-
You can subscribe to the <a href="https://api.slack.com/events/app_home_opened">`app_home_opened`</a> event to listen for when users open your App Home.
9+
You can subscribe to the [`app_home_opened`](https://api.slack.com/events/app_home_opened) event to listen for when users open your App Home.
1010

1111
Refer to [the module document](https://tools.slack.dev/bolt-python/api-docs/slack_bolt/kwargs_injection/args.html) to learn the available listener arguments.
1212
```python
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ def respond_to_user_messages(logger: logging.Logger, set_status: SetStatus, say:
277277
logger.exception(f"Failed to respond to an inquiry: {e}")
278278
say(f":warning: Sorry, something went wrong during processing your request (error: {e})")
279279

280-
281280
# Enable this assistant middleware in your Bolt app
282281
app.use(assistant)
283282
```
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ lang: en
44
slug: /concepts/async
55
---
66

7+
To use the async version of Bolt, you can import and initialize an `AsyncApp` instance (rather than `App`). `AsyncApp` relies on [AIOHTTP](https://docs.aiohttp.org) to make API requests, which means you'll need to install `aiohttp` (by adding to `requirements.txt` or running `pip install aiohttp`).
78

8-
To use the async version of Bolt, you can import and initialize an `AsyncApp` instance (rather than `App`). `AsyncApp` relies on <a href="https://docs.aiohttp.org/">AIOHTTP</a> to make API requests, which means you'll need to install `aiohttp` (by adding to `requirements.txt` or running `pip install aiohttp`).
9-
10-
Sample async projects can be found within the repository's <a href="https://github.com/slackapi/bolt-python/tree/main/examples">`examples` folder</a>.
11-
9+
Sample async projects can be found within the repository's [examples](https://github.com/slackapi/bolt-python/tree/main/examples) folder.
1210

1311
```python
1412
# Requirement: install aiohttp
@@ -28,12 +26,7 @@ if __name__ == "__main__":
2826
app.start(3000)
2927
```
3028

31-
<details>
32-
<summary>
33-
Using other frameworks
34-
</summary>
35-
36-
29+
## Using other frameworks
3730

3831
Internally `AsyncApp#start()` implements a [`AIOHTTP`](https://docs.aiohttp.org/) web server. If you prefer, you can use a framework other than `AIOHTTP` to handle incoming requests.
3932

@@ -48,7 +41,6 @@ pip install slack_bolt sanic uvicorn
4841
uvicorn async_app:api --reload --port 3000 --log-level debug
4942
```
5043

51-
5244
```python
5345
from slack_bolt.async_app import AsyncApp
5446
app = AsyncApp()
@@ -76,5 +68,4 @@ async def endpoint(req: Request):
7668

7769
if __name__ == "__main__":
7870
api.run(host="0.0.0.0", port=int(os.environ.get("PORT", 3000)))
79-
```
80-
</details>
71+
```

docs/content/basic/authenticating-oauth.md renamed to docs/content/concepts/authenticating-oauth.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ app = App(
3535
)
3636
```
3737

38-
<details>
39-
<summary>
40-
Customizing OAuth defaults
41-
</summary>
38+
## Customizing OAuth defaults
4239

4340
You can override the default OAuth using `oauth_settings`, which can be passed in during the initialization of App. You can override the following:
4441

@@ -90,6 +87,4 @@ app = App(
9087
callback_options=callback_options,
9188
),
9289
)
93-
```
94-
95-
</details>
90+
```

0 commit comments

Comments
 (0)