-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
181 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logging | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
from slack_bolt.async_app import AsyncApp | ||
from slack_bolt.adapter.fastapi.async_handler import AsyncSlackRequestHandler | ||
|
||
app = AsyncApp() | ||
app_handler = AsyncSlackRequestHandler(app) | ||
|
||
|
||
@app.event("app_mention") | ||
async def handle_app_mentions(context, say, logger): | ||
logger.info(context) | ||
assert context.get("foo") == "FOO" | ||
await say("What's up?") | ||
|
||
|
||
@app.event("message") | ||
async def handle_message(): | ||
pass | ||
|
||
|
||
from fastapi import FastAPI, Request, Depends | ||
|
||
api = FastAPI() | ||
|
||
|
||
def get_foo(): | ||
yield "FOO" | ||
|
||
|
||
@api.post("/slack/events") | ||
async def endpoint(req: Request, foo: str = Depends(get_foo)): | ||
return await app_handler.handle(req, {"foo": foo}) | ||
|
||
|
||
# pip install -r requirements.txt | ||
# export SLACK_SIGNING_SECRET=*** | ||
# export SLACK_BOT_TOKEN=xoxb-*** | ||
# uvicorn async_app_custom_props:api --reload --port 3000 --log-level warning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters