-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrich_text.py
More file actions
321 lines (294 loc) · 8.7 KB
/
rich_text.py
File metadata and controls
321 lines (294 loc) · 8.7 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
from slack_sdk.models.blocks import RichTextBlock
from slack_sdk.models.blocks.block_elements import (
RichTextElementParts,
RichTextListElement,
RichTextPreformattedElement,
RichTextQuoteElement,
RichTextSectionElement,
)
def example01() -> list[RichTextBlock]:
"""
Displays formatted, structured representation of text.
https://docs.slack.dev/reference/block-kit/blocks/rich-text-block/
Four basic rich text section examples (basic, bold, italic, strikethrough).
"""
blocks = [
RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(
text="Hello there, I am a basic rich text block!"
)
]
)
]
),
RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Hello there, "),
RichTextElementParts.Text(
text="I am a bold rich text block!", style={"bold": True}
),
]
)
]
),
RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Hello there, "),
RichTextElementParts.Text(
text="I am an italic rich text block!",
style={"italic": True},
),
]
)
]
),
RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Hello there, "),
RichTextElementParts.Text(
text="I am a strikethrough rich text block!",
style={"strike": True},
),
]
)
]
),
]
return blocks
def example02() -> RichTextBlock:
"""
A rich text block with a bullet list.
"""
block = RichTextBlock(
block_id="block1",
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(
text="My favorite Slack features (in no particular order):"
)
]
),
RichTextListElement(
style="bullet",
indent=0,
border=1,
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Huddles")]
),
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Canvas")]
),
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Developing with Block Kit")
]
),
],
),
],
)
return block
def example03() -> RichTextBlock:
"""
A rich text block with a nested bullet list.
"""
block = RichTextBlock(
block_id="block1",
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Breakfast foods I enjoy:")]
),
RichTextListElement(
style="bullet",
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Hashbrowns")]
),
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Eggs")]
),
],
),
RichTextListElement(
style="bullet",
indent=1,
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Scrambled")]
),
RichTextSectionElement(
elements=[RichTextElementParts.Text(text="Over easy")]
),
],
),
RichTextListElement(
style="bullet",
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Pancakes, extra syrup")
]
)
],
),
],
)
return block
def example04() -> RichTextBlock:
"""
A rich text block with preformatted code.
"""
block = RichTextBlock(
elements=[
RichTextPreformattedElement(
border=0,
elements=[
RichTextElementParts.Text(
text='{\n "object": {\n "description": "this is an example of a json object"\n }\n}'
)
],
)
]
)
return block
def example05() -> RichTextBlock:
"""
A rich text block with a quote.
"""
block = RichTextBlock(
block_id="Vrzsu",
elements=[
RichTextQuoteElement(
elements=[
RichTextElementParts.Text(
text="What we need is good examples in our documentation."
)
]
),
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Yes - I completely agree, Luke!")
]
),
],
)
return block
def example06() -> RichTextBlock:
"""
A rich text block with a broadcast element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Broadcast(range="everyone")]
)
]
)
return block
def example07() -> RichTextBlock:
"""
A rich text block with a color element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Color(value="#F405B3")]
)
]
)
return block
def example08() -> RichTextBlock:
"""
A rich text block with a channel element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Channel(channel_id="C123ABC456")]
)
]
)
return block
def example09() -> RichTextBlock:
"""
A rich text block with a date element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Date(
timestamp=1720710212,
format="{date_num} at {time}",
fallback="timey",
)
]
)
]
)
return block
def example10() -> RichTextBlock:
"""
A rich text block with emoji elements.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Emoji(name="basketball"),
RichTextElementParts.Text(text=" "),
RichTextElementParts.Emoji(name="snowboarder"),
RichTextElementParts.Text(text=" "),
RichTextElementParts.Emoji(name="checkered_flag"),
]
)
]
)
return block
def example11() -> RichTextBlock:
"""
A rich text block with a link element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.Link(url="https://api.slack.com")]
)
]
)
return block
def example12() -> RichTextBlock:
"""
A rich text block with a user mention element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.User(user_id="U123ABC456")]
)
]
)
return block
def example13() -> RichTextBlock:
"""
A rich text block with a usergroup mention element.
"""
block = RichTextBlock(
elements=[
RichTextSectionElement(
elements=[RichTextElementParts.UserGroup(usergroup_id="G123ABC456")]
)
]
)
return block