Skip to content

Commit 07ff0d8

Browse files
committed
Closes #14694 by documenting the SlackHeaderBlock class
1 parent cc63cc1 commit 07ff0d8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
9.9 KB
Loading

notifier/chatters.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,46 @@ The result will be something like:
135135

136136
The `field()` method was introduced in Symfony 5.1.
137137

138+
Adding a header to a Slack Message
139+
-------------------------------------------
140+
141+
To add a header to your message you can use the
142+
:class:`Symfony\\Component\\Notifier\\Bridge\\Slack\\Block\\SlackHeaderBlock` class::
143+
144+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
145+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackHeaderBlock;
146+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
147+
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
148+
use Symfony\Component\Notifier\Message\ChatMessage;
149+
150+
$chatMessage = new ChatMessage('Symfony Feature');
151+
152+
$options = (new SlackOptions())
153+
->block((new SlackHeaderBlock('My Header')))
154+
->block((new SlackSectionBlock())->text('My message'))
155+
->block(new SlackDividerBlock())
156+
->block(
157+
(new SlackSectionBlock())
158+
->field('*Max Rating*')
159+
->field('5.0')
160+
->field('*Min Rating*')
161+
->field('1.0')
162+
);
163+
164+
// Add the custom options to the chat message and send the message
165+
$chatMessage->options($options);
166+
167+
$chatter->send($chatMessage);
168+
169+
The result will be something like:
170+
171+
.. image:: /_images/notifier/slack/slack-header.png
172+
:align: center
173+
174+
.. versionadded:: 5.3
175+
176+
The `SlackHeaderBlock` class was introduced in Symfony 5.3.
177+
138178
Sending a Slack Message as a reply
139179
-------------------------------------------
140180

0 commit comments

Comments
 (0)