-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Di Wang <[email protected]>
- Loading branch information
Showing
13 changed files
with
123 additions
and
77 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from slack_bolt import App | ||
from slack_bolt.adapter.fastapi import SlackRequestHandler | ||
from slack_bolt.adapter.socket_mode import SocketModeHandler | ||
|
||
from app import config | ||
|
||
app = App( | ||
token=config.SLACK_BOT_TOKEN, | ||
signing_secret=config.SLACK_SIGNING_SECRET | ||
) | ||
|
||
slack_request_handler = SlackRequestHandler(app) | ||
|
||
slack_socket_model_handler = SocketModeHandler(app, config.SLACK_APP_TOKEN) | ||
|
||
|
||
def get_slack_request_handler() -> SlackRequestHandler: | ||
return slack_request_handler | ||
|
||
|
||
SlackRequestHandlerDep = Annotated[SlackRequestHandler, Depends(get_slack_request_handler)] | ||
|
||
@app.event("message") | ||
def handle_message_events(body, say, logger): | ||
logger.info(body) | ||
text = body.get('event', {}).get('text', '') | ||
if 'hello' in text.lower(): | ||
say("Hello there! :wave:") | ||
|
||
|
||
# Define an event listener for "app_mention" events | ||
@app.event("app_mention") | ||
def handle_app_mention_events(body, say, logger): | ||
logger.info(body) | ||
say("Hello SRE slackers! :blush:") |
Empty file.
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,10 @@ | ||
from fastapi import APIRouter, Request | ||
|
||
from app.dependencies.slack import SlackRequestHandlerDep | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/slack/events") | ||
async def slack_events(request: Request, handler: SlackRequestHandlerDep): | ||
return await handler.handle(request) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from app import config | ||
from app.dependencies.slack import slack_socket_model_handler | ||
|
||
|
||
def run(): | ||
if config.SLACK_APP_TOKEN: | ||
slack_socket_model_handler.start() | ||
else: | ||
print("SLACK_APP_TOKEN not found.") | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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