• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..01-Jul-2019-

__init__.pyH A D01-Jul-20193.5 KiB11795

actions.pyH A D01-Jul-201910.5 KiB299237

attachments.pyH A D01-Jul-201914.9 KiB343305

blocks.pyH A D01-Jul-20196.8 KiB209166

dialog_elements.pyH A D01-Jul-201913.9 KiB428356

dialogs.pyH A D01-Jul-201916 KiB452404

elements.pyH A D01-Jul-201919.5 KiB552461

interactions.pyH A D01-Jul-20194.4 KiB140113

messages.pyH A D01-Jul-20192.4 KiB7159

objects.pyH A D01-Jul-201914.7 KiB424342

readme.mdH A D01-Jul-20191.9 KiB5033

readme.md

1# Using the Slack object classes
2
3## Composing Messages
4
5Messages are built up out of blocks and legacy attachments. Blocks are composed of the base Block classes in `blocks.py`, which themselves are composed of elements (`elements.py`) which are either atomic or contain common sub-objects (`objects.py`).
6
7For example: A simple block template, containing a header, some fields, and an actions block at the bottom would be built up as follows:
8
9```python
10from slack.web.client import WebClient
11from slack.web.classes import messages, blocks, elements
12
13client = WebClient(token="abc")
14
15fields = blocks.SectionBlock(fields=["*Type:*\nComputer", "*Reason:*\nAll vowel keys aren't working"])
16
17approve_button = elements.ButtonElement(text="Approve", action_id="approval", value="order_123", style="primary")
18deny_button = elements.ButtonElement(text="Deny", action_id="denial", value="order_123", style="danger")
19
20buttons = [approve_button, deny_button]
21
22actions = blocks.ActionsBlock(elements=buttons)
23
24work_order_message = messages.Message(text="You have a new request", blocks=[fields, actions])
25
26client.chat_postMessage(channel="C12345", **work_order_message.to_dict())
27```
28
29## Composing Dialogs
30Dialogs can be built using a helper 'builder' class, to simplify keeping track of required fields.
31
32```python
33from slack.web.client import WebClient
34from slack.web.classes import dialogs
35
36builder = (
37    dialogs.DialogBuilder()
38        .title("My Cool Dialog")
39        .callback_id("myCoolDialog")
40        .state({'value': 123, 'key': "something"})
41        .conversation_selector(name="target", label="Choose Target")
42        .text_area(name="message", label="Message", hint="Enter a message", max_length=500)
43        .text_field(name="signature", label="Signature", optional=True, max_length=50)
44)
45
46client = WebClient(token="abc")
47
48client.dialog_open(dialog=builder.to_dict(), trigger_id="123458.12355")
49```
50