11import logging
2- import time
32
43from chalice import Chalice , Response
4+
55from slack_bolt import App
66from slack_bolt .adapter .aws_lambda .chalice_handler import ChaliceSlackRequestHandler
77
88# process_before_response must be True when running on FaaS
9- bolt_app = App (process_before_response = True )
9+ bolt_app = App (
10+ process_before_response = True ,
11+ authorization_test_enabled = False ,
12+ )
1013
1114
1215@bolt_app .event ("app_mention" )
@@ -15,6 +18,11 @@ def handle_app_mentions(payload, say, logger):
1518 say ("What's up? I'm a Chalice app :wave:" )
1619
1720
21+ @bolt_app .command ("/hello-bolt-python-chalice" )
22+ def respond_to_slack_within_3_seconds (ack ):
23+ ack ("Thanks!" )
24+
25+
1826ChaliceSlackRequestHandler .clear_all_log_handlers ()
1927logging .basicConfig (format = "%(asctime)s %(message)s" , level = logging .DEBUG )
2028
@@ -23,23 +31,6 @@ def handle_app_mentions(payload, say, logger):
2331slack_handler = ChaliceSlackRequestHandler (app = bolt_app , chalice = app )
2432
2533
26- def respond_to_slack_within_3_seconds (ack ):
27- # This method is for synchronous communication with the Slack API server
28- ack ("Thanks!" )
29-
30-
31- def can_be_long (say ):
32- # This can be executed in a thread, asyncio's Future, a new AWS lambda function
33- # ack() is not allowed here
34- time .sleep (5 )
35- say ("I'm done!" )
36-
37-
38- bolt_app .command ("/hello-bolt-python-chalice" )(
39- ack = respond_to_slack_within_3_seconds , subsequent = [can_be_long ],
40- )
41-
42-
4334@app .route (
4435 "/slack/events" ,
4536 methods = ["POST" ],
@@ -49,11 +40,22 @@ def events() -> Response:
4940 return slack_handler .handle (app .current_request )
5041
5142
43+ @app .route ("/slack/install" , methods = ["GET" ])
44+ def install () -> Response :
45+ return slack_handler .handle (app .current_request )
46+
47+
48+ @app .route ("/slack/oauth_redirect" , methods = ["GET" ])
49+ def oauth_redirect () -> Response :
50+ return slack_handler .handle (app .current_request )
51+
52+
5253# configure aws credentials properly
5354# pip install -r requirements.txt
54- # edit .chalice/config.json
55- # rm -rf vendor/latest_slack_bolt && cp -pr ../../src vendor/latest_slack_bolt
55+ # cp -p .chalice/config.json.simple .chalice/config.json
56+ # # edit .chalice/config.json
57+ # rm -rf vendor/slack_* && cp -pr ../../src/* vendor/
5658# chalice deploy
5759
58- # for local dev
60+ # # for local dev
5961# chalice local --stage dev --port 3000
0 commit comments