VOOZH about

URL: https://deepwiki.com/hypervel/notifications/6.5.2-block-types

⇱ Block Types | hypervel/notifications | DeepWiki


Loading...
Menu

Block Types

Purpose and Scope

This page documents the six concrete block types available in Slack's Block Kit implementation within the hypervel/notifications package. Blocks are the visual components that compose a Slack message layout. Each block type serves a specific purpose and has distinct validation rules.

For information about the contract interfaces these blocks implement, see Block Kit Contracts. For the elements and composites used within blocks (such as TextObject, ButtonElement), see Elements and Composites. For overall Slack message construction, see Slack Messages.


Block Type Architecture

All block types implement the BlockContract interface and reside in the src/Slack/BlockKit/Blocks/ namespace. Each block type corresponds to a specific Slack Block Kit layout component and serializes to JSON via the toArray() method.


Sources: src/Slack/BlockKit/Blocks/ActionsBlock.php14 src/Slack/BlockKit/Blocks/ContextBlock.php15 src/Slack/BlockKit/Blocks/DividerBlock.php10 src/Slack/BlockKit/Blocks/HeaderBlock.php12 src/Slack/BlockKit/Blocks/ImageBlock.php12 src/Slack/BlockKit/Blocks/SectionBlock.php14


Common Block Properties

Block Identifier

All block types support an optional blockId property set via the id() method. This identifier is used by Slack to track interaction sources and must not exceed 255 characters.

Block TypeHas id() MethodValidation
ActionsBlockYesMax 255 characters
ContextBlockYesMax 255 characters
DividerBlockYesMax 255 characters
HeaderBlockYesMax 255 characters
ImageBlockYesMax 255 characters
SectionBlockYesMax 255 characters

Sources: src/Slack/BlockKit/Blocks/ActionsBlock.php37-42 src/Slack/BlockKit/Blocks/ContextBlock.php38-43 src/Slack/BlockKit/Blocks/DividerBlock.php24-29 src/Slack/BlockKit/Blocks/HeaderBlock.php45-50 src/Slack/BlockKit/Blocks/ImageBlock.php60-65 src/Slack/BlockKit/Blocks/SectionBlock.php53-58

Serialization

All blocks implement the Arrayable contract through their toArray() method, which validates constraints and produces the JSON-compatible array structure expected by Slack's API.


ActionsBlock

The ActionsBlock contains interactive elements such as buttons, select menus, overflow menus, or date pickers. It enables user interaction within the message.

Properties

  • elements (ElementContract[]): Array of interactive element objects
  • blockId (?string): Optional unique identifier

Constraints



























ConstraintValueException Type
Minimum elements1LogicException
Maximum elements25LogicException
block_id max length255 charactersInvalidArgumentException

Methods

  • button(string $text): ButtonElement - Adds a button element to the block and returns it for further configuration

Output Structure


Sources: src/Slack/BlockKit/Blocks/ActionsBlock.php14-80


ContextBlock

The ContextBlock displays contextual information using images and text objects in a compact format, typically used for metadata or supplementary details.

Properties

  • elements (ElementContract[]): Array of image elements and text objects
  • blockId (?string): Optional unique identifier

Constraints

ConstraintValueException Type
Minimum elements1LogicException
Maximum elements10LogicException
block_id max length255 charactersInvalidArgumentException

Methods

  • image(string $imageUrl, ?string $altText = null): ImageElement - Adds an image element
  • text(string $text): TextObject - Adds a text object

Output Structure


Sources: src/Slack/BlockKit/Blocks/ContextBlock.php15-91


DividerBlock

The DividerBlock renders a visual separator line, used to segment content within a message. This is the simplest block type with no configurable content.

Properties

  • blockId (?string): Optional unique identifier

Constraints

ConstraintValueException Type
block_id max length255 charactersInvalidArgumentException

Methods

The DividerBlock has no content-specific methods beyond id().

Output Structure


Sources: src/Slack/BlockKit/Blocks/DividerBlock.php10-48


HeaderBlock

The HeaderBlock displays large, prominent text at the top of a message or section, similar to an H1 heading.

Properties

  • text (PlainTextOnlyTextObject): The header text (plain text only)
  • blockId (?string): Optional unique identifier

Constructor


The constructor creates a PlainTextOnlyTextObject with a 150 character limit and applies an optional callback for further configuration.

Constraints

ConstraintValueException Type
text max length150 charactersEnforced by PlainTextOnlyTextObject
block_id max length255 charactersInvalidArgumentException

Output Structure


Sources: src/Slack/BlockKit/Blocks/HeaderBlock.php12-70


ImageBlock

The ImageBlock displays an image with optional title and alt text. This is distinct from the ImageElement used within other blocks.

Properties

  • url (string): The image URL (max 3000 characters)
  • altText (?string): Plain-text image description (max 2000 characters, required)
  • title (?PlainTextOnlyTextObject): Optional title (max 2000 characters)
  • blockId (?string): Optional unique identifier

Constructor


Constructor validates URL length immediately. Alt text can be set in constructor or via alt() method.

Constraints

ConstraintValueException Type
url max length3000 charactersInvalidArgumentException
altText max length2000 charactersInvalidArgumentException
altText requiredMust be setLogicException
title max length2000 charactersEnforced by PlainTextOnlyTextObject
block_id max length255 charactersInvalidArgumentException

Methods

  • alt(string $altText): static - Sets or updates the alt text
  • title(string $title): PlainTextOnlyTextObject - Sets the title and returns the text object for further configuration

Output Structure


Sources: src/Slack/BlockKit/Blocks/ImageBlock.php12-115


SectionBlock

The SectionBlock is the most versatile block type, supporting text content, fields in a two-column layout, and an optional accessory element (such as a button or image).

Properties

  • text (?TextObject): Main text content (max 3000 characters)
  • fields (TextObject[]): Array of text objects displayed in two columns (max 10 fields, 2000 chars each)
  • accessory (?ElementContract): Optional interactive element displayed alongside content
  • blockId (?string): Optional unique identifier

Constraints










































ConstraintValueException Type
text max length3000 charactersEnforced by TextObject
field max length2000 characters eachEnforced by TextObject
field minimum length1 characterEnforced by TextObject
Maximum fields10LogicException
Content requirementtext OR fields must be presentLogicException
block_id max length255 charactersInvalidArgumentException

Methods

  • text(string $text): TextObject - Sets the main text and returns the text object for further configuration
  • field(string $text): TextObject - Adds a field and returns the text object for configuration
  • accessory(ElementContract $element): static - Sets an accessory element (button, image, etc.)

Output Structure


Sources: src/Slack/BlockKit/Blocks/SectionBlock.php14-118


Block Type Validation Summary

The following table summarizes validation rules enforced across all block types during toArray() serialization:

Block TypeRequired FieldsOptional FieldsElement LimitsText Length Limits
ActionsBlockelements (1-25)block_id1-25 elementsblock_id: 255
ContextBlockelements (1-10)block_id1-10 elementsblock_id: 255
DividerBlocknoneblock_idn/ablock_id: 255
HeaderBlocktextblock_idn/atext: 150, block_id: 255
ImageBlockurl, altTextblock_id, titlen/aurl: 3000, altText: 2000, title: 2000, block_id: 255
SectionBlocktext OR fieldsblock_id, accessorymax 10 fieldstext: 3000, field: 2000, block_id: 255

Sources: src/Slack/BlockKit/Blocks/ActionsBlock.php58-79 src/Slack/BlockKit/Blocks/ContextBlock.php68-90 src/Slack/BlockKit/Blocks/DividerBlock.php34-47 src/Slack/BlockKit/Blocks/HeaderBlock.php55-69 src/Slack/BlockKit/Blocks/ImageBlock.php94-114 src/Slack/BlockKit/Blocks/SectionBlock.php93-117


Block Type Selection Guide

Choose the appropriate block type based on your content and interaction requirements:


Key Selection Criteria:

  • ActionsBlock: When users need to click buttons or interact with select menus
  • ContextBlock: For small text labels, timestamps, or icons (max 10 items)
  • DividerBlock: To visually separate sections of content
  • HeaderBlock: For prominent section titles (limited to 150 characters)
  • ImageBlock: For standalone images with alt text and optional title
  • SectionBlock: For primary text content, potentially with accessory elements

Sources: All block implementation files in src/Slack/BlockKit/Blocks/