forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (45 loc) · 1.68 KB
/
app.py
File metadata and controls
67 lines (45 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging
import time
from chalice import Chalice, Response
from slack_bolt import App
from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler
# process_before_response must be True when running on FaaS
bolt_app = App(process_before_response=True)
@bolt_app.event("app_mention")
def handle_app_mentions(body, say, logger):
logger.info(body)
say("What's up? I'm a Chalice app :wave:")
def respond_to_slack_within_3_seconds(ack):
ack("Accepted!")
def say_it(say):
time.sleep(5)
say("Done!")
bolt_app.command("/hello-bolt-python-chalice")(
ack=respond_to_slack_within_3_seconds, lazy=[say_it]
)
ChaliceSlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG)
# Don't change this variable name "app"
app = Chalice(app_name="bolt-python-chalice")
slack_handler = ChaliceSlackRequestHandler(app=bolt_app, chalice=app)
@app.route(
"/slack/events",
methods=["POST"],
content_types=["application/x-www-form-urlencoded", "application/json"],
)
def events() -> Response:
return slack_handler.handle(app.current_request)
@app.route("/slack/install", methods=["GET"])
def install() -> Response:
return slack_handler.handle(app.current_request)
@app.route("/slack/oauth_redirect", methods=["GET"])
def oauth_redirect() -> Response:
return slack_handler.handle(app.current_request)
# configure aws credentials properly
# pip install -r requirements.txt
# cp -p .chalice/config.json.simple .chalice/config.json
# # edit .chalice/config.json
# rm -rf vendor/slack_* && cp -pr ../../src/* vendor/
# chalice deploy
# # for local dev
# chalice local --stage dev --port 3000