Blocks
Blocks are a series of container components that can be combined to create rich and interactive messages.
See: https://api.slack.com/reference/block-kit/blocks.
ActionsBlock
A Block
that is used to hold interactive elements (normally for users to interface with).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements |
Optional[List[Element]]
|
a list of Elements (up to a maximum of 25). |
None
|
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Throws
InvalidUsageError: if any of the items in elements
are invalid.
Source code in slackblocks/blocks.py
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 |
|
ContextBlock
A ContextBlock
displays contextul message info, including both images and text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements |
Optional[List[Union[Element, CompositionObject]]]
|
a list of |
None
|
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Throws
InvalidUsageError: when items in elements
are not Text
or Image
or exceed 10 items.
Source code in slackblocks/blocks.py
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 |
|
DividerBlock
A content divider, like an <hr>
in HTML, to split up different blocks inside of
a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Source code in slackblocks/blocks.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
FileBlock
Displays a remote file (e.g. a PDF).
For details on how remote files are exposed to Slack, see https://api.slack.com/messaging/files#adding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
external_id |
str
|
the ID assigned to the remote file when it was added to Slack. |
required |
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
required |
source |
str
|
always "remote" as per the Slack API (may change in the future). |
'remote'
|
Source code in slackblocks/blocks.py
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 |
|
HeaderBlock
A Header Block is a plain-text block that displays in a larger, bold font.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
Union[str, Text]
|
the text that will be rendered as a heading. |
required |
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Source code in slackblocks/blocks.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
ImageBlock
An Image Block contains a single graphic, accessed by URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_url |
str
|
the URL pointing to the image file you want to display. |
required |
alt_text |
Optional[str]
|
alternative text for accessibility purposes and when the image fails to load. |
' '
|
title |
Optional[Union[Text, str]]
|
an optional text title to be presented with the image. |
None
|
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Throws
InvalidUsageError: when one or more of the provided args fails validation.
Source code in slackblocks/blocks.py
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 |
|
InputBlock
A block that collects information from users - it can hold a plain-text input element, a checkbox element, a radio button element, a select menu element, a multi-select menu element, or a datepicker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label |
TextLike
|
the name which identifies the input field. |
required |
element |
Element
|
an interactive Element (e.g. a text field). |
required |
dispatch_action |
bool
|
whether the Element
should trigger the sending of a |
False
|
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
hint |
Optional[TextLike]
|
an optional additional guide on what input the user should prodive. |
None
|
optional |
bool
|
whether this input field may be empty when the user submits e.g. the modal. |
False
|
Throws
InvalidUsageError: when any of the provided arguments fail validation.
Source code in slackblocks/blocks.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
RichTextBlock
A RichTextBlock is used to provide easier rich text formatting
than standard markdown text (e.g. in a
SectionBlock
)
and access to text formatting features not available in traditional
markdown (e.g. strikethrough). See the various rich text elements
you can include here.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements |
Union[RichTextObject, List[RichTextObject]]
|
a single rich text element or a list of those elements. |
required |
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Throws
InvalidUsageError: if the elements in elements
are not valid rich
text elements.
Source code in slackblocks/blocks.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
SectionBlock
A section is one of the most flexible blocks available - it can be used as a simple text block, or with any of the available block elements.
Section blocks can also optionally be given an "accessory," which is typically one of the interactive Elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
Optional[TextLike]
|
text to include in the block. Can be a string or |
None
|
block_id |
Optional[str]
|
you can use this field to provide a deterministic identifier for the block. |
None
|
fields |
Optional[Union[TextLike, List[TextLike]]]
|
a list of text objects. One of either |
None
|
accessory |
Optional[Element]
|
an optional Element object
that will take a secondary place in the block (after or to the side of |
None
|
Throws
InvalidUsageError: if any of the provided arguments fail validation checks.
Source code in slackblocks/blocks.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|