Skip to content

Commit c18e0d8

Browse files
committed
Fix Socket Mode document
1 parent 1c57dff commit c18e0d8

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

docs/_basic/socket_mode.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ order: 16
99
With the introduction of [Socket Mode](https://api.slack.com/apis/connections/socket), Bolt for Python introduced support in version `1.2.0`. With Socket Mode, instead of creating a server with endpoints that Slack sends payloads too, the app will instead connect to Slack via a WebSocket connection and receive data from Slack over the socket connection. Make sure to enable Socket Mode in your app configuration settings.
1010

1111
To use the Socket Mode, add `SLACK_APP_TOKEN` as an environment variable. You can get your App Token in your app configuration settings under the **Basic Information** section.
12+
13+
While we recommend using [the built-in Socket Mode adapter](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/builtin), there are a few other 3rd party library based implementations. Here is the list of available adapters.
14+
15+
|PyPI Project|Bolt Adapter|
16+
|-|-|
17+
|[slack_sdk](https://pypi.org/project/slack-sdk/)|[slack_bolt.adapter.socket_mode](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/builtin)|
18+
|[websocket_client](https://pypi.org/project/websocket_client/)|[slack_bolt.adapter.socket_mode.websocket_client](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/websocket_client)|
19+
|[aiohttp](https://pypi.org/project/aiohttp/) (asyncio-based)|[slack_bolt.adapter.socket_mode.aiohttp](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/aiohttp)|
20+
|[websockets](https://pypi.org/project/websockets/) (asyncio-based)|[slack_bolt.adapter.socket_mode.websockets](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/websockets)|
21+
1222
</div>
1323

1424
```python
@@ -19,30 +29,35 @@ from slack_bolt.adapter.socket_mode import SocketModeHandler
1929
# Install the Slack app and get xoxb- token in advance
2030
app = App(token=os.environ["SLACK_BOT_TOKEN"])
2131

32+
# Add middleware / listeners here
33+
2234
if __name__ == "__main__":
2335
# export SLACK_APP_TOKEN=xapp-***
2436
# export SLACK_BOT_TOKEN=xoxb-***
25-
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
37+
handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
38+
handler.start()
2639
```
2740

28-
While we recommend using [the built-in Socket Mode adapter](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/builtin), there are a few other 3rd party library based implementations. Here is the list of available adapters.
29-
30-
|PyPI Project|Bolt Adapter|
31-
|-|-|
32-
|[slack_sdk](https://pypi.org/project/slack-sdk/)|[slack_bolt.adapter.socket_mode](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/builtin)|
33-
|[websocket_client](https://pypi.org/project/websocket_client/)|[slack_bolt.adapter.socket_mode.websocket_client](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/websocket_client)|
34-
|[aiohttp](https://pypi.org/project/aiohttp/) (asyncio-based)|[slack_bolt.adapter.socket_mode.aiohttp](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/aiohttp)|
35-
|[websockets](https://pypi.org/project/websockets/) (asyncio-based)|[slack_bolt.adapter.socket_mode.websockets](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter/socket_mode/websockets)|
41+
<details class="secondary-wrapper">
42+
<summary markdown="0">
43+
<h4 class="secondary-header">Using Async</h4>
44+
</summary>
3645

46+
<div class="secondary-content" markdown="0">
3747
To use the asyncio-based adapters such as aiohttp, your app needs to be compatible with asyncio's async/await programming model. `AsyncSocketModeHandler` is available for running `AsyncApp` and its async middleware and listeners.
3848

49+
To learn how to use `AsyncApp`, checkout the [Using Async](https://slack.dev/bolt-python/concepts#async) document and relevant [examples](https://github.com/slackapi/bolt-python/tree/main/examples).
50+
</div>
51+
3952
```python
4053
from slack_bolt.app.async_app import AsyncApp
4154
# The default is the aiohttp based implementation
4255
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
4356

4457
app = AsyncApp(token=os.environ["SLACK_BOT_TOKEN"])
4558

59+
# Add middleware / listeners here
60+
4661
async def main():
4762
handler = AsyncSocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
4863
await handler.start_async()
@@ -52,4 +67,4 @@ if __name__ == "__main__":
5267
asyncio.run(main())
5368
```
5469

55-
To learn how to use `AsyncApp`, checkout the [Using Async](https://slack.dev/bolt-python/concepts#async) document and relevant [examples](https://github.com/slackapi/bolt-python/tree/main/examples).
70+
</details>

0 commit comments

Comments
 (0)