VOOZH about

URL: https://deepwiki.com/hypervel/notifications/6.4-legacy-slack-attachments

⇱ Legacy Slack Attachments | hypervel/notifications | DeepWiki


Loading...
Menu

Legacy Slack Attachments

Purpose and Scope

This document describes the legacy attachment-based format for Slack messages, implemented through the SlackAttachment and SlackAttachmentField classes. This format predates Slack's modern Block Kit framework and is maintained for backwards compatibility with existing integrations.

For modern Slack message construction using Block Kit components, see Slack Block Kit. For an overview of Slack messaging capabilities, see Slack Messages.

Important: Slack has deprecated the attachment format in favor of Block Kit. New integrations should use Block Kit (documented in 6.5) instead. This legacy format is provided for maintaining existing implementations.


Attachment Architecture

The legacy attachment system consists of three core classes that work together to create rich message content:


Diagram: Attachment Class Hierarchy

The SlackMessage class maintains an array of SlackAttachment objects, each of which can contain multiple SlackAttachmentField objects. Attachments are added using a closure-based fluent interface.

Sources: src/Messages/SlackMessage.php1-219 src/Messages/SlackAttachment.php1-284 src/Messages/SlackAttachmentField.php1-66


SlackAttachment Properties

The SlackAttachment class provides a comprehensive set of properties for structuring rich message content:

PropertyTypeDescriptionMethod
title?stringPrimary heading texttitle(string, ?string)
url?stringURL for title linkSet via title()
pretext?stringText above the attachmentpretext(string)
content?stringMain text contentcontent(string)
fallback?stringPlain-text summaryfallback(string)
color?stringLeft border colorcolor(string)
fieldsarrayArray of field objectsfield(), fields(array)
markdownarrayFields with markdownmarkdown(array)
imageUrl?stringFull-size imageimage(string)
thumbUrl?stringThumbnail imagethumb(string)
actionsarrayButton actionsaction(string, string, string)
authorName?stringAuthor display nameauthor(string, ?string, ?string)
authorLink?stringAuthor profile URLSet via author()
authorIcon?stringAuthor avatar URLSet via author()
footer?stringFooter textfooter(string)
footerIcon?stringFooter icon URLfooterIcon(string)
timestampintUnix timestamptimestamp(DateInterval|DateTimeInterface|int)
callbackIdstringInteractive callback IDcallbackId(string)

Sources: src/Messages/SlackAttachment.php16-105


Adding Attachments to Messages

Attachments are added to SlackMessage instances using the attachment() method, which accepts a closure that receives a SlackAttachment instance:


Diagram: Attachment Creation Flow

The SlackMessage::attachment() method creates a new SlackAttachment object, passes it to the provided closure for configuration, and appends it to the internal attachments array.

Sources: src/Messages/SlackMessage.php153-160 src/Messages/SlackAttachment.php160-175


Basic Structure Components

Title and Content

The attachment title serves as the primary heading and can optionally include a hyperlink:


Diagram: Title Configuration

The title() method sets both the title text and an optional URL in a single call. The pretext() method adds text that appears above the attachment, while content() sets the main body text.

Sources: src/Messages/SlackAttachment.php109-115 src/Messages/SlackAttachment.php120-125 src/Messages/SlackAttachment.php130-135

Fallback Text

The fallback property provides a plain-text alternative for clients that don't support rich attachments:

MethodPurpose
fallback(string)Sets plain-text summary displayed in notifications and unfurls

Sources: src/Messages/SlackAttachment.php140-145

Color Coding

The color() method sets the vertical border color on the left side of the attachment. This accepts hex color codes, named colors, or the special values good, warning, and danger:


Diagram: Color Options

Sources: src/Messages/SlackAttachment.php150-155


Fields

Fields organize information into structured key-value pairs that can be displayed side-by-side or stacked:

Field Structure

The SlackAttachmentField class has three properties:

PropertyTypeDefaultDescription
title?stringnullField label
content?stringnullField value
shortbooltrueDisplay side-by-side if true

Sources: src/Messages/SlackAttachmentField.php12-22

Adding Fields

Fields can be added to attachments using two approaches:


Diagram: Field Addition Methods

The closure approach provides full control over field properties including the short flag, while the simple approach creates a basic key-value mapping.

Sources: src/Messages/SlackAttachment.php160-175

Field Display Control

The long() method on SlackAttachmentField forces the field to display at full width rather than side-by-side:


Diagram: Field Width Control

Sources: src/Messages/SlackAttachmentField.php47-52

Markdown Support

The markdown() method specifies which fields should be parsed for Markdown formatting:


Diagram: Markdown Configuration

Common field names for markdown parsing: pretext, text, fields.

Sources: src/Messages/SlackAttachment.php190-195


Visual Elements

Images

Attachments support two types of images:

MethodPropertyDisplay
image(string)imageUrlFull-size image displayed within attachment
thumb(string)thumbUrlSmall thumbnail on the right side

Sources: src/Messages/SlackAttachment.php200-205 src/Messages/SlackAttachment.php210-215

Actions (Buttons)

The action() method adds interactive buttons below the attachment:


Diagram: Action Button Structure

Each action creates a button with the specified text and URL. The style parameter controls the button's visual appearance.

Sources: src/Messages/SlackAttachment.php220-230


Metadata Components

Author Information

The author() method sets the author metadata displayed at the top of the attachment:


Diagram: Author Properties

All three properties are set in a single method call. The link makes the author name clickable, and the icon displays a small avatar.

Sources: src/Messages/SlackAttachment.php235-242

Footer

Footer components appear at the bottom of the attachment:

MethodPropertyPurpose
footer(string)footerFooter text content
footerIcon(string)footerIconSmall icon URL displayed next to footer

Sources: src/Messages/SlackAttachment.php247-252 src/Messages/SlackAttachment.php257-262

Timestamp

The timestamp() method accepts multiple time formats using the InteractsWithTime trait:


Diagram: Timestamp Conversion

The availableAt() method from the InteractsWithTime trait normalizes all input formats to a Unix timestamp.

Sources: src/Messages/SlackAttachment.php267-272 src/Messages/SlackAttachment.php14

Callback ID

The callbackId() method sets an identifier for interactive message callbacks:

PropertyDefaultPurpose
callbackId''Identifies the attachment in interactive responses

Sources: src/Messages/SlackAttachment.php104 src/Messages/SlackAttachment.php277-282


Complete Usage Example

The following diagram illustrates a complete attachment construction pattern:


Diagram: Complete Attachment Construction Sequence

This sequence demonstrates the typical pattern for constructing a rich attachment with title, colored border, multiple fields (including one long field), markdown support, metadata, and an action button.

Sources: src/Messages/SlackMessage.php153-160 src/Messages/SlackAttachment.php109-282 src/Messages/SlackAttachmentField.php27-52


SlackAttachmentField Array Serialization

The SlackAttachmentField::toArray() method converts the field object into the array format expected by Slack's API:


Diagram: Field Serialization

Note that the content property is serialized as value in the output array to match Slack's API expectations.

Sources: src/Messages/SlackAttachmentField.php57-64


Integration with SlackMessage

The SlackMessage class stores attachments and provides the entry point for adding them:


Diagram: SlackMessage Attachment Storage

The attachments property is a simple array that accumulates all added attachments. Each call to attachment() creates a new SlackAttachment instance, configures it via the closure, and appends it.

Sources: src/Messages/SlackMessage.php59 src/Messages/SlackMessage.php153-160


Migration to Block Kit

Applications using legacy attachments should plan migration to Block Kit for several reasons:

ConsiderationLegacy AttachmentsBlock Kit
StatusDeprecated by SlackCurrent standard
InteractivityLimited (buttons only)Full interactive components
Layout ControlFixed structureFlexible composition
MaintenanceCompatibility modeActive development
DocumentationSlack API reference onlyBlock Kit documentation available

The Block Kit system is documented in page 6.5, including block types (6.5.2) and interactive elements (6.5.3).

Sources: src/Messages/SlackAttachment.php1-284 (legacy implementation), 6.5 (modern replacement)