1- # ------------------------------------------------
2- # instead of slack_bolt in requirements.txt
3- import sys
4-
5- sys .path .insert (1 , "latest_slack_bolt" )
6- # ------------------------------------------------
7-
81import logging
2+ import time
3+
94from chalice import Chalice , Response
5+
106from slack_bolt import App
117from slack_bolt .adapter .aws_lambda .chalice_handler import ChaliceSlackRequestHandler
8+ from slack_bolt .adapter .aws_lambda .lambda_s3_oauth_flow import LambdaS3OAuthFlow
129
1310# process_before_response must be True when running on FaaS
14- bolt_app = App (process_before_response = True )
11+ bolt_app = App (
12+ process_before_response = True ,
13+ authorization_test_enabled = False ,
14+ oauth_flow = LambdaS3OAuthFlow (
15+ install_path = "/api/slack/install" ,
16+ redirect_uri_path = "/api/slack/oauth_redirect" ,
17+ ),
18+ )
1519
1620
1721@bolt_app .event ("app_mention" )
@@ -20,22 +24,41 @@ def handle_app_mentions(payload, say, logger):
2024 say ("What's up? I'm a Chalice app :wave:" )
2125
2226
27+ @bolt_app .command ("/hello-bolt-python-chalice" )
28+ def respond_to_slack_within_3_seconds (ack ):
29+ ack ("Thanks!" )
30+
31+
2332ChaliceSlackRequestHandler .clear_all_log_handlers ()
2433logging .basicConfig (format = '%(asctime)s %(message)s' , level = logging .DEBUG )
2534
2635# Don't change this variable name "app"
2736app = Chalice (app_name = "bolt-python-chalice" )
28- slack_handler = ChaliceSlackRequestHandler (app = bolt_app )
37+ slack_handler = ChaliceSlackRequestHandler (app = bolt_app , chalice = app )
2938
3039
31- @app .route ("/slack/events" , methods = ["POST" ])
40+ @app .route (
41+ "/slack/events" ,
42+ methods = ["POST" ],
43+ content_types = ["application/x-www-form-urlencoded" , "application/json" ],
44+ )
3245def events () -> Response :
3346 return slack_handler .handle (app .current_request )
3447
48+
49+ @app .route ("/slack/install" , methods = ["GET" ])
50+ def install () -> Response :
51+ return slack_handler .handle (app .current_request )
52+
53+
54+ @app .route ("/slack/oauth_redirect" , methods = ["GET" ])
55+ def oauth_redirect () -> Response :
56+ return slack_handler .handle (app .current_request )
57+
3558# configure aws credentials properly
3659# pip install -r requirements.txt
3760# edit .chalice/config.json
38- # rm -rf vendor/latest_slack_bolt && cp -pr ../../src vendor/latest_slack_bolt
61+ # rm -rf vendor/slack_* && cp -pr ../../src/* vendor/
3962# chalice deploy
4063
4164# for local dev
0 commit comments