forked from h-takeyeah/boushi2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (59 loc) · 1.88 KB
/
main.py
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
68
69
70
71
72
73
74
75
import os
from typing import Any, Dict, Optional
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from slack_bolt.context.ack import Ack
from slack_bolt.context.respond import Respond
from slack_bolt.error import BoltError
import light_sensor
#import logging
# logging.basicConfig(level=logging.DEBUG) # debug mode
app = App(token=os.environ.get('SLACK_BOT_TOKEN'))
@app.command('/boushitsu')
def respond_to_boushitsu(ack: Ack, respond: Respond, command: Optional[Dict[str, Any]]) -> None:
'''respond to `/boushitsu`
respond() calls `chat.postEphemeral`
https://slack.dev/bolt-python/concepts#commands
https://api.slack.com/interactivity/slash-commands
'''
ack() # acknowledge
# print(command)
text = ''
if light_sensor.is_open():
text = 'boushitsu status: *open* :heavy_check_mark:'
else:
text = 'boushitsu status: *closed* :zzz:'
msg = {
'text': 'from boushitsu',
'blocks': [
{
'type': 'section',
'text': {
'type': 'mrkdwn',
'text': text
},
'accessory': {
'type': 'button',
'text': {
'type': 'plain_text',
'text': 'Dismiss'
},
'action_id': 'dismiss'
}
}
]
}
respond(msg) # send an ephemeral message
@app.block_action('dismiss')
def handle_dismiss_action(ack: Ack, respond: Respond) -> None:
ack()
respond(delete_original=True)
if __name__ == '__main__':
try:
light_sensor.setup_gpio()
handler = SocketModeHandler(app, os.environ.get('SLACK_APP_TOKEN'))
handler.start()
except KeyboardInterrupt:
pass
finally:
light_sensor.cleanup()