forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_oauth_app.py
More file actions
55 lines (37 loc) · 1.41 KB
/
async_oauth_app.py
File metadata and controls
55 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# ------------------------------------------------
# instead of slack_bolt in requirements.txt
import sys
sys.path.insert(1, "../..")
# ------------------------------------------------
from slack_bolt.async_app import AsyncApp
from slack_bolt.adapter.starlette.async_handler import AsyncSlackRequestHandler
app = AsyncApp()
app_handler = AsyncSlackRequestHandler(app)
@app.event("app_mention")
async def handle_app_mentions(body, say, logger):
logger.info(body)
await say("What's up?")
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.routing import Route
async def endpoint(req: Request):
return await app_handler.handle(req)
async def install(req: Request):
return await app_handler.handle(req)
async def oauth_redirect(req: Request):
return await app_handler.handle(req)
api = Starlette(
debug=True,
routes=[
Route("/slack/events", endpoint=endpoint, methods=["POST"]),
Route("/slack/install", endpoint=install, methods=["GET"]),
Route("/slack/oauth_redirect", endpoint=oauth_redirect, methods=["GET"]),
],
)
# pip install -r requirements.txt
# # -- OAuth flow -- #
# export SLACK_SIGNING_SECRET=***
# export SLACK_CLIENT_ID=111.111
# export SLACK_CLIENT_SECRET=***
# export SLACK_SCOPES=app_mentions:read,channels:history,im:history,chat:write
# uvicorn async_oauth_app:api --reload --port 3000 --log-level debug