Blocks
Blocks are the top-level visual building units of a Slack message. A Message is a list of blocks, rendered top-to-bottom in Slack.
For a side-by-side gallery of every block type with code, JSON, and Slack screenshots, see Using Blocks.
For the elements that go inside blocks (buttons, menus, date pickers, etc.) see Elements.
Slack reference: https://api.slack.com/reference/block-kit/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
|
list[Element] | None
|
a list of Elements (up to a maximum of 25). |
None
|
block_id
|
str | None
|
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
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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack actions block payload.
Currently raises NotImplementedError because round-tripping
depends on parsing nested elements; Element.from_dict will land
in Phase 7.4b.
Source code in slackblocks/blocks.py
212 213 214 215 216 217 218 219 220 221 222 223 | |
Block
Basis block containing attributes and behaviour common to all blocks. N.B: Block is an abstract class and cannot be sent directly.
Source code in slackblocks/blocks.py
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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack block payload back into the appropriate Block subclass.
Reads data["type"] and dispatches to the matching subclass's
from_dict.
Throws
MissingRequiredError: if data["type"] is absent.
TypeMismatchError: if data["type"] is not a recognised
block type.
NotImplementedError: when the block type is recognised but its
round-trip parser depends on a part of the API that is not
yet implemented (currently: RichTextBlock and any block
containing elements -- see Phase 7.4b and 7.4c).
Source code in slackblocks/blocks.py
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 | |
ContextBlock
A ContextBlock displays contextul message info, including both images and text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
list[Element | CompositionObject] | None
|
a list of |
None
|
block_id
|
str | None
|
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
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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack context block payload.
Text elements within the block are parsed back to Text; image
elements raise NotImplementedError because Element.from_dict
has not yet shipped (Phase 7.4b).
Source code in slackblocks/blocks.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
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
|
str | None
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Source code in slackblocks/blocks.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
from_dict
classmethod
from_dict(data)
Parse a Slack divider block payload.
Source code in slackblocks/blocks.py
295 296 297 298 | |
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
|
str | None
|
you can use this field to provide a deterministic identifier for the block. |
None
|
source
|
str
|
always "remote" as per the Slack API (may change in the future). |
'remote'
|
Source code in slackblocks/blocks.py
301 302 303 304 305 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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack file block payload.
Source code in slackblocks/blocks.py
331 332 333 334 335 336 337 338 339 340 | |
HeaderBlock
A Header Block is a plain-text block that displays in a larger, bold font.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | Text
|
the text that will be rendered as a heading. |
required |
block_id
|
str | None
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Source code in slackblocks/blocks.py
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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack header block payload.
Source code in slackblocks/blocks.py
362 363 364 365 366 367 | |
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
|
str | None
|
alternative text for accessibility purposes and when the image fails to load. |
' '
|
title
|
Text | str | None
|
an optional text title to be presented with the image. |
None
|
block_id
|
str | None
|
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
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 404 405 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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack image block payload.
Source code in slackblocks/blocks.py
422 423 424 425 426 427 428 429 430 431 432 433 | |
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
|
str | None
|
you can use this field to provide a deterministic identifier for the block. |
None
|
hint
|
TextLike | None
|
an optional additional guide on what input the user should provide. |
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
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 489 490 491 492 493 494 495 496 497 498 | |
from_dict
classmethod
from_dict(data)
Parse a Slack input block payload.
Currently raises NotImplementedError because the nested
element requires Element.from_dict, which lands in Phase 7.4b.
Source code in slackblocks/blocks.py
488 489 490 491 492 493 494 495 496 497 498 | |
MarkdownBlock
Displays formatted Markdown text. Unlike the mrkdwn text style used in
SectionBlock,
MarkdownBlock uses GitHub-flavored Markdown for richer formatting,
including features like tables and code blocks. Added to Slack in 2024
for AI / agentic app outputs.
See: https://api.slack.com/reference/block-kit/blocks#markdown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the Markdown-formatted text to display (1-12000 characters). |
required |
block_id
|
str | None
|
you can use this field to provide a deterministic identifier for the block. |
None
|
Throws
LengthError: if text is empty or longer than 12000 characters.
Source code in slackblocks/blocks.py
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 | |
from_dict
classmethod
from_dict(data)
Parse a Slack markdown block payload.
Source code in slackblocks/blocks.py
536 537 538 539 540 541 | |
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
|
RichTextObject | list[RichTextObject]
|
a single rich text element or a list of those elements. |
required |
block_id
|
str | None
|
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
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 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
from_dict
classmethod
from_dict(data)
Parse a Slack rich_text block payload.
Currently raises NotImplementedError because the rich-text
object hierarchy has a deeply nested element graph; round-tripping
is deferred to Phase 7.4c.
Source code in slackblocks/blocks.py
584 585 586 587 588 589 590 591 592 593 594 595 | |
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
|
TextLike | None
|
text to include in the block. Can be a string or |
None
|
block_id
|
str | None
|
you can use this field to provide a deterministic identifier for the block. |
None
|
fields
|
TextLike | list[TextLike] | None
|
a list of text objects. One of either |
None
|
accessory
|
Element | None
|
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
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
from_dict
classmethod
from_dict(data)
Parse a Slack section block payload.
Round-trips text and fields. Raises NotImplementedError
if an accessory is present, because the accessory is an
Element and Element.from_dict is not yet implemented
(Phase 7.4b).
Source code in slackblocks/blocks.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
TableBlock
A TableBlock displays data in a table format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[list[RawText | RichTextObject]]
|
a list of lists of |
required |
column_settings
|
list[ColumnSettings] | None
|
a list of |
None
|
block_id
|
str | None
|
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
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
_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
754 755 756 757 758 759 760 761 762 763 764 765 | |
from_dict
classmethod
from_dict(data)
Parse a Slack table block payload.
Currently raises NotImplementedError because table cells may
contain rich-text objects whose round-trip parser is deferred to
Phase 7.4c.
Source code in slackblocks/blocks.py
767 768 769 770 771 772 773 774 775 776 777 778 | |
VideoBlock
Embeds a video. Used to display video content inside a Slack message, modal, or App Home tab.
See: https://api.slack.com/reference/block-kit/blocks#video.
Note: Slack restricts which domains may be embedded. The server-side
whitelist (e.g. YouTube, Vimeo) is enforced by Slack on receipt of the
payload, not by this library; supplying an unsupported URL will result
in a Slack API error rather than an InvalidUsageError at construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alt_text
|
str
|
a plain-text summary of the video, used for accessibility and notifications (max 200 chars). |
required |
thumbnail_url
|
str
|
a URL pointing to the preview image shown before playback. Must be HTTPS in production usage. |
required |
title
|
TextLike
|
the title shown above the video player (plain text, max 200
chars). A |
required |
video_url
|
str
|
the URL of the video to embed. Must point to a Slack-supported provider (see Slack's documentation). |
required |
author_name
|
str | None
|
optional author name shown beneath the video (max 50 chars). |
None
|
block_id
|
str | None
|
an optional deterministic identifier for the block. |
None
|
description
|
TextLike | None
|
optional plain-text description below the video
(max 200 chars). A |
None
|
provider_icon_url
|
str | None
|
an optional URL to the provider's icon. |
None
|
provider_name
|
str | None
|
an optional provider name shown alongside the icon (max 50 chars). |
None
|
title_url
|
str | None
|
an optional URL to link the title to. |
None
|
Throws
LengthError: if any length-constrained string exceeds its limit.
Source code in slackblocks/blocks.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
from_dict
classmethod
from_dict(data)
Parse a Slack video block payload.
Source code in slackblocks/blocks.py
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |