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
54 lines (35 loc) · 1.1 KB
/
app.py
File metadata and controls
54 lines (35 loc) · 1.1 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
# ------------------------------------------------
# instead of slack_bolt in requirements.txt
import sys
sys.path.insert(1, "../..")
# ------------------------------------------------
import logging
logging.basicConfig(level=logging.DEBUG)
from slack_bolt import App
from slack_bolt.adapter.cherrypy import SlackRequestHandler
app = App()
@app.middleware # or app.use(log_request)
def log_request(logger, payload, next):
logger.debug(payload)
return next()
@app.command("/hello-bolt-python")
def hello_command(ack):
ack("Hi from CherryPy")
@app.event("app_mention")
def event_test(payload, say, logger):
logger.info(payload)
say("What's up?")
import cherrypy
handler = SlackRequestHandler(app)
class SlackApp(object):
@cherrypy.expose
@cherrypy.tools.slack_in()
def events(self, **kwargs):
return handler.handle()
if __name__ == "__main__":
cherrypy.config.update({"server.socket_port": 3000})
cherrypy.quickstart(SlackApp(), "/slack")
# pip install -r requirements.txt
# export SLACK_SIGNING_SECRET=***
# export SLACK_BOT_TOKEN=xoxb-***
# python app.py