|
7 | 7 |
|
8 | 8 | import logging |
9 | 9 | from slack_bolt import App |
10 | | -from slack_bolt.adapter.aws_lambda import SlackRequestHandler |
| 10 | +from slack_bolt.adapter.aws_lambda import SlackRequestHandler, LambdaS3OAuthFlow |
11 | 11 |
|
12 | 12 | logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) |
13 | | -app = App(process_before_response=True) |
14 | 13 |
|
| 14 | +app = App( |
| 15 | + process_before_response=True, |
| 16 | + oauth_flow=LambdaS3OAuthFlow(), |
| 17 | +) |
15 | 18 |
|
16 | | -@app.command("/bolt-py-proto") |
| 19 | + |
| 20 | +@app.shortcut("bolt-python-on-aws-lambda") |
17 | 21 | def command_handler(logger, payload, client, ack): |
18 | 22 | res = client.views_open( |
19 | 23 | trigger_id=payload["trigger_id"], |
@@ -55,11 +59,37 @@ def view_submission(ack, payload, logger): |
55 | 59 | return ack() |
56 | 60 |
|
57 | 61 |
|
| 62 | +@app.event("app_mention") |
| 63 | +def handle_app_mentions(payload, say, logger): |
| 64 | + logger.info(payload) |
| 65 | + say("What's up?") |
| 66 | + |
| 67 | +slack_handler = SlackRequestHandler(app=app) |
| 68 | + |
| 69 | + |
58 | 70 | def handler(event, context): |
59 | | - return SlackRequestHandler(app).handle(event, context) |
| 71 | + return slack_handler.handle(event, context) |
| 72 | + |
| 73 | +# export SLACK_SIGNING_SECRET=*** |
| 74 | +# export SLACK_BOT_TOKEN=xoxb-*** |
60 | 75 |
|
| 76 | +# rm -rf src |
| 77 | +# cp -pr ../../src src |
| 78 | +# pip install python-lambda |
| 79 | +# lambda deploy --config-file aws_lambda_config.yaml --requirements requirements.txt |
| 80 | + |
| 81 | +# # -- OAuth flow -- # |
61 | 82 | # export SLACK_SIGNING_SECRET=*** |
62 | 83 | # export SLACK_BOT_TOKEN=xoxb-*** |
| 84 | +# export SLACK_CLIENT_ID=111.111 |
| 85 | +# export SLACK_CLIENT_SECRET=*** |
| 86 | +# export SLACK_SCOPES=app_mentions:read,channels:history,im:history,chat:write |
| 87 | + |
| 88 | +# AWS IAM Role: bolt_python_s3_storage |
| 89 | +# - AmazonS3FullAccess |
| 90 | +# - AWSLambdaBasicExecutionRole |
| 91 | + |
| 92 | +# rm -rf src |
63 | 93 | # cp -pr ../../src src |
64 | 94 | # pip install python-lambda |
65 | 95 | # lambda deploy --config-file aws_lambda_config.yaml --requirements requirements.txt |
0 commit comments