Skip to content

Commit 9b718c9

Browse files
committed
Fix slackapi#36 simple sample app using Chalice doesn't work
1 parent 538c2fb commit 9b718c9

3 files changed

Lines changed: 29 additions & 30 deletions

File tree

samples/aws_chalice/app.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55
from slack_bolt import App
66
from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler
7-
from slack_bolt.adapter.aws_lambda.lambda_s3_oauth_flow import LambdaS3OAuthFlow
87

98
# process_before_response must be True when running on FaaS
109
bolt_app = App(
1110
process_before_response=True,
1211
authorization_test_enabled=False,
13-
oauth_flow=LambdaS3OAuthFlow(
14-
install_path="/api/slack/install",
15-
redirect_uri_path="/api/slack/oauth_redirect",
16-
),
1712
)
1813

1914

@@ -57,9 +52,10 @@ def oauth_redirect() -> Response:
5752

5853
# configure aws credentials properly
5954
# pip install -r requirements.txt
60-
# edit .chalice/config.json
55+
# cp -p .chalice/config.json.simple .chalice/config.json
56+
# # edit .chalice/config.json
6157
# rm -rf vendor/slack_* && cp -pr ../../src/* vendor/
6258
# chalice deploy
6359

64-
# for local dev
60+
# # for local dev
6561
# chalice local --stage dev --port 3000

samples/aws_chalice/oauth_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def oauth_redirect() -> Response:
5757

5858
# configure aws credentials properly
5959
# pip install -r requirements.txt
60-
# edit .chalice/config.json
60+
# cp -p .chalice/config.json.oauth .chalice/config.json
61+
# # edit .chalice/config.json
6162
# rm -rf vendor/latest_slack_bolt && cp -pr ../../src vendor/latest_slack_bolt
6263
# chalice deploy
6364

samples/aws_chalice/simple_app.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import logging
2-
import time
32

43
from chalice import Chalice, Response
4+
55
from slack_bolt import App
66
from 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+
1826
ChaliceSlackRequestHandler.clear_all_log_handlers()
1927
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG)
2028

@@ -23,23 +31,6 @@ def handle_app_mentions(payload, say, logger):
2331
slack_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

Comments
 (0)