Skip to content

Commit 300fe7c

Browse files
Add ASGI adapter (#780)
1 parent 929008e commit 300fe7c

File tree

23 files changed

+1033
-3
lines changed

23 files changed

+1033
-3
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ jobs:
7878
# Falcon supports Python 3.11 since its v3.1.1
7979
pip install "falcon>=3.1.1,<4"
8080
pytest tests/adapter_tests_async/
81+
- name: Run tests for HTTP Mode adapters (Asgi)
82+
run: |
83+
# Requires async test dependencies
84+
pytest tests/adapter_tests/asgi/

examples/asgi/app.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from slack_bolt import App
2+
from slack_bolt.adapter.asgi import SlackRequestHandler
3+
4+
app = App()
5+
6+
7+
@app.event("app_mention")
8+
def handle_app_mentions(body, say, logger):
9+
logger.info(body)
10+
say("What's up?")
11+
12+
13+
api = SlackRequestHandler(app)
14+
15+
# pip install -r requirements.txt
16+
# export SLACK_SIGNING_SECRET=***
17+
# export SLACK_BOT_TOKEN=xoxb-***
18+
# uvicorn app:api --reload --port 3000 --log-level debug
19+
# ngrok http 3000

examples/asgi/async_app.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from slack_bolt.async_app import AsyncApp
2+
from slack_bolt.adapter.asgi.async_handler import AsyncSlackRequestHandler
3+
4+
app = AsyncApp()
5+
6+
7+
@app.event("app_mention")
8+
async def handle_app_mentions(body, say, logger):
9+
logger.info(body)
10+
await say("What's up?")
11+
12+
13+
api = AsyncSlackRequestHandler(app)
14+
15+
# pip install -r requirements.txt
16+
# export SLACK_SIGNING_SECRET=***
17+
# export SLACK_BOT_TOKEN=xoxb-***
18+
# uvicorn async_app:api --reload --port 3000 --log-level debug
19+
# ngrok http 3000

examples/asgi/async_oauth_app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from slack_bolt.async_app import AsyncApp
2+
from slack_bolt.adapter.asgi.async_handler import AsyncSlackRequestHandler
3+
4+
app = AsyncApp()
5+
6+
7+
@app.event("app_mention")
8+
async def handle_app_mentions(body, say, logger):
9+
logger.info(body)
10+
await say("What's up?")
11+
12+
api = AsyncSlackRequestHandler(app)
13+
14+
# pip install -r requirements.txt
15+
16+
# # -- OAuth flow -- #
17+
# export SLACK_SIGNING_SECRET=***
18+
# export SLACK_CLIENT_ID=111.111
19+
# export SLACK_CLIENT_SECRET=***
20+
# export SLACK_SCOPES=app_mentions:read,channels:history,im:history,chat:write
21+
22+
# uvicorn async_oauth_app:api --reload --port 3000 --log-level debug

examples/asgi/oauth_app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from slack_bolt import App
2+
from slack_bolt.adapter.asgi import SlackRequestHandler
3+
4+
app = App()
5+
6+
7+
@app.event("app_mention")
8+
def handle_app_mentions(body, say, logger):
9+
logger.info(body)
10+
say("What's up?")
11+
12+
13+
api = SlackRequestHandler(app)
14+
15+
# pip install -r requirements.txt
16+
17+
# # -- OAuth flow -- #
18+
# export SLACK_SIGNING_SECRET=***
19+
# export SLACK_CLIENT_ID=111.111
20+
# export SLACK_CLIENT_SECRET=***
21+
# export SLACK_SCOPES=app_mentions:read,channels:history,im:history,chat:write
22+
23+
# uvicorn oauth_app:api --reload --port 3000 --log-level debug

examples/asgi/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
uvicorn<1
2+
aiohttp>=3,<4

examples/docker/asgi/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# docker build . -t your-repo/hello-bolt
3+
#
4+
FROM python:3.11-alpine3.17 as builder
5+
COPY requirements.txt /build/
6+
WORKDIR /build/
7+
RUN pip install -U pip && pip install -r requirements.txt
8+
9+
FROM python:3.11-alpine3.17 as app
10+
WORKDIR /app/
11+
COPY --from=builder /usr/local/bin/ /usr/local/bin/
12+
COPY --from=builder /usr/local/lib/ /usr/local/lib/
13+
COPY main.py /app/
14+
ENTRYPOINT uvicorn main:asgi_app --port $PORT --workers 1
15+
16+
#
17+
# docker run -e SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET -e SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN -e PORT=3000 -p 3000:3000 -it your-repo/hello-bolt
18+
#

examples/docker/asgi/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import logging
2+
from slack_bolt import App
3+
from slack_bolt.adapter.asgi import SlackRequestHandler
4+
5+
logging.basicConfig(level=logging.DEBUG)
6+
app = App()
7+
8+
9+
@app.event("app_mention")
10+
def handle_app_mentions(body, say, logger):
11+
logger.info(body)
12+
say("What's up?")
13+
14+
15+
asgi_app = SlackRequestHandler(app)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
slack_bolt
2+
uvicorn<1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .builtin import SlackRequestHandler
2+
3+
__all__ = ["SlackRequestHandler"]

0 commit comments

Comments
 (0)