]> git.cworth.org Git - turbot/blob - turbot/blocks.py
c037b03217f0ed117b823dc2141dfe03d05a6297
[turbot] / turbot / blocks.py
1 def divider_block():
2     return {
3         "type": "divider"
4     }
5
6 def text_block(body):
7     return {
8         "text": {
9             "type": "mrkdwn",
10             "text": body
11         }
12     }
13
14 def section_block(block):
15     return {
16         "type": "section",
17         **block
18     }
19
20 def actions_block(*elements):
21     return {
22         "type": "actions",
23         "elements": list(elements)
24     }
25
26 def button_block(label, name, extra=None):
27
28     block = {
29         "type": "button",
30         "text": {
31             "type": "plain_text",
32             "text": label,
33             "emoji": True
34         },
35         "value": name
36     }
37
38     if extra:
39         block['action_id'] = extra
40
41     return block
42
43 def accessory_block(main, accessory):
44     return {
45         **main,
46         "accessory": {
47             **accessory
48         }
49     }
50
51 def input_block(label, name, placeholder, optional=False):
52     return {
53         "type": "input",
54         "block_id": name,
55         "optional": optional,
56         "element": {
57             "type": "plain_text_input",
58             "action_id": name,
59             "placeholder": {
60                 "type": "plain_text",
61                 "text": placeholder,
62             }
63         },
64         "label": {
65             "type": "plain_text",
66             "text": label
67         }
68     }
69
70 def multi_select_block(label, name, placeholder, options, default=None):
71     return {
72         "type": "section",
73         "block_id": name,
74         "text": {
75             "type": "mrkdwn",
76             "text": "*{}*".format(label)
77         },
78         "accessory": {
79             "action_id": name,
80             "type": "multi_static_select",
81             "placeholder": {
82                 "type": "plain_text",
83                 "text": placeholder
84             },
85             "options": [
86                 {
87                     "text": {
88                         "type": "plain_text",
89                         "text": option
90                     },
91                     "value": option
92                 } for option in options
93             ]
94         }
95     }