@@ -135,6 +135,46 @@ The result will be something like:
135
135
136
136
The `field() ` method was introduced in Symfony 5.1.
137
137
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
+
138
178
Sending a Slack Message as a reply
139
179
-------------------------------------------
140
180
0 commit comments