class SlackMessage implements Arrayable

Traits

Properties

protected string|null $channel

The channel to send the message on.

protected string|null $text

The text content of the message.

protected array<mixed[]|BlockContract> $blocks

The message's blocks.

protected string|null $icon

The user emoji icon for the message.

protected string|null $image

The user image icon for the message.

protected EventMetadata|null $metaData

The JSON metadata for the message.

protected bool|null $mrkdwn

Indicates if you want the message to parse markdown or not.

$unfurlLinks

Indicates if you want a preview of links inlined in the message.

protected bool|null $unfurlMedia

Indicates if you want a preview of links to media inlined in the message.

protected string|null $username

The username to send the message as.

protected string|null $threadTs

Unique, per-channel, timestamp for each message. If provided, send message as a thread reply to this message.

protected bool|null $broadcastReply

If sending message as reply to thread, whether to 'broadcast' a reference to the thread reply to the parent conversation.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

to(string $channel)

Set the Slack channel the message should be sent to.

text(string $text)

Set the fallback and notification text of the Slack message.

actionsBlock(Closure $callback)

Add a new Actions block to the message.

contextBlock(Closure $callback)

Add a new Context block to the message.

dividerBlock()

Add a new Divider block to the message.

headerBlock(string $text, Closure|null $callback = null)

Add a new Header block to the message.

imageBlock(string $url, Closure|string|null $altText = null, Closure|null $callback = null)

Add a new Image block to the message.

sectionBlock(Closure $callback)

Add a new Section block to the message.

emoji(string $emoji)

Set a custom image icon the message should use.

image(string $image)

Set a custom image icon the message should use.

metadata(string $eventType, array $payload = [])

Set the metadata the message should include.

disableMarkdownParsing()

Disable Slack's markup parsing.

unfurlLinks(bool $unfurlLinks = true)

Unfurl links for rich display.

unfurlMedia(bool $unfurlMedia = true)

Unfurl media for rich display.

username(string $username)

Set the user name for the Slack bot.

threadTimestamp(string|null $threadTimestamp)

Set the thread timestamp (message ID) to send as reply to thread.

broadcastReply(bool|null $broadcastReply = true)

Only applicable if threadTimestamp is set. Broadcasts a reference to the threaded reply to the parent conversation.

usingBlockKitTemplate(string $template)

Specify a raw Block Kit Builder JSON payload for the message.

array
toArray()

Get the instance as an array.

string
toBlockKitBuilderUrl()

Get the Block Kit URL for the message.

never
dd(bool $raw = false)

Dump the payload or its Slack Block Kit Builder URL.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 90
SlackMessage to(string $channel)

Set the Slack channel the message should be sent to.

Parameters

string $channel

Return Value

SlackMessage

at line 100
SlackMessage text(string $text)

Set the fallback and notification text of the Slack message.

Parameters

string $text

Return Value

SlackMessage

at line 110
SlackMessage actionsBlock(Closure $callback)

Add a new Actions block to the message.

Parameters

Closure $callback

Return Value

SlackMessage

at line 122
SlackMessage contextBlock(Closure $callback)

Add a new Context block to the message.

Parameters

Closure $callback

Return Value

SlackMessage

at line 134
SlackMessage dividerBlock()

Add a new Divider block to the message.

Return Value

SlackMessage

at line 144
SlackMessage headerBlock(string $text, Closure|null $callback = null)

Add a new Header block to the message.

Parameters

string $text
Closure|null $callback

Return Value

SlackMessage

at line 154
SlackMessage imageBlock(string $url, Closure|string|null $altText = null, Closure|null $callback = null)

Add a new Image block to the message.

Parameters

string $url
Closure|string|null $altText
Closure|null $callback

Return Value

SlackMessage

at line 173
SlackMessage sectionBlock(Closure $callback)

Add a new Section block to the message.

Parameters

Closure $callback

Return Value

SlackMessage

at line 185
SlackMessage emoji(string $emoji)

Set a custom image icon the message should use.

Parameters

string $emoji

Return Value

SlackMessage

at line 196
SlackMessage image(string $image)

Set a custom image icon the message should use.

Parameters

string $image

Return Value

SlackMessage

at line 207
SlackMessage metadata(string $eventType, array $payload = [])

Set the metadata the message should include.

Parameters

string $eventType
array $payload

Return Value

SlackMessage

at line 217
SlackMessage disableMarkdownParsing()

Disable Slack's markup parsing.

Return Value

SlackMessage

Unfurl links for rich display.

Parameters

bool $unfurlLinks

Return Value

SlackMessage

at line 237
SlackMessage unfurlMedia(bool $unfurlMedia = true)

Unfurl media for rich display.

Parameters

bool $unfurlMedia

Return Value

SlackMessage

at line 247
SlackMessage username(string $username)

Set the user name for the Slack bot.

Parameters

string $username

Return Value

SlackMessage

at line 257
SlackMessage threadTimestamp(string|null $threadTimestamp)

Set the thread timestamp (message ID) to send as reply to thread.

Parameters

string|null $threadTimestamp

Return Value

SlackMessage

at line 267
SlackMessage broadcastReply(bool|null $broadcastReply = true)

Only applicable if threadTimestamp is set. Broadcasts a reference to the threaded reply to the parent conversation.

Parameters

bool|null $broadcastReply

Return Value

SlackMessage

at line 280
SlackMessage usingBlockKitTemplate(string $template)

Specify a raw Block Kit Builder JSON payload for the message.

Parameters

string $template

Return Value

SlackMessage

Exceptions

JsonException
LogicException

at line 296
array toArray()

Get the instance as an array.

Return Value

array

at line 330
string toBlockKitBuilderUrl()

Get the Block Kit URL for the message.

Return Value

string

Exceptions

JsonException

at line 343
never dd(bool $raw = false)

Dump the payload or its Slack Block Kit Builder URL.

Parameters

bool $raw

Return Value

never