You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Prints {'b': {'a': {'type': 'plain_text_input', 'value': 'Your Input'}}}
90
-
logger.info(body["view"]["state"]["values"])
84
+
logger.info(view["state"]["values"])
91
85
92
86
if__name__=="__main__":
93
87
app.start(3000) # POST http://localhost:3000/slack/events
@@ -104,6 +98,53 @@ python app.py
104
98
ngrok http 3000
105
99
```
106
100
101
+
## AsyncApp Setup
102
+
103
+
If you prefer building Slack apps using [asyncio](https://docs.python.org/3/library/asyncio.html), you can go with `AsyncApp` instead. You can use async/await style for everything in the app. To use `AsyncApp`, [AIOHTTP](https://docs.aiohttp.org/en/stable/) library is required for asynchronous Slack Web API calls and the default web server.
104
+
105
+
```bash
106
+
python -m venv env
107
+
source env/bin/activate
108
+
pip install slack_bolt aiohttp
109
+
```
110
+
111
+
Import `slack_bolt.async_app.AsyncApp` instead of `slack_bolt.App`. All middleware/listeners must be async functions. Inside the functions, all utility methods such as `ack`, `say`, and `respond` requires `await` keyword.
112
+
113
+
```python
114
+
from slack_bolt.async_app import AsyncApp
115
+
116
+
app = AsyncApp()
117
+
118
+
@app.event("app_mention")
119
+
asyncdefevent_test(body, say, logger):
120
+
logger.info(body)
121
+
await say("What's up?")
122
+
123
+
@app.command("/hello-bolt-python")
124
+
asyncdefcommand(ack, body, respond):
125
+
await ack()
126
+
await respond(f"Hi <@{body['user_id']}>!")
127
+
128
+
if__name__=="__main__":
129
+
app.start(3000)
130
+
```
131
+
132
+
Starting the app is exactly the same with the way using `slack_bolt.App`.
133
+
134
+
```bash
135
+
export SLACK_SIGNING_SECRET=***
136
+
export SLACK_BOT_TOKEN=xoxb-***
137
+
python app.py
138
+
139
+
# in another terminal
140
+
ngrok http 3000
141
+
```
142
+
143
+
If you want to use another async Web framework (e.g., Sanic, FastAPI, Starlette), take a look at the built-in adapters and their samples.
0 commit comments