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
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 | |
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
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 | |
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
198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
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
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 | |
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
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
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
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 | |
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
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 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
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
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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
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
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 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
TableBlock
A TableBlock displays data in a table format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
List[List[Union[RawText, RichTextObject]]]
|
a list of lists of |
required |
column_settings
|
Optional[List[ColumnSettings]]
|
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 rows are not RawText or RichTextObject objects.
InvalidUsageError: when the number of column_settings does not match the number of
columns in each row.
InvalidUsageError: when the number of rows is greater than 100.
InvalidUsageError: when the number of columns in a row is greater than 20.
InvalidUsageError: when the number of column_settings is greater than 20.
Source code in slackblocks/blocks.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
_resolve_cell
_resolve_cell(cell)
Resolve a table cell to its JSON representation.
RawText cells are resolved directly. RichTextObject cells are wrapped in a rich_text structure.
Source code in slackblocks/blocks.py
564 565 566 567 568 569 570 571 572 573 574 575 | |