@@ -135,6 +135,120 @@ 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
+
178
+ Adding a footer to a Slack Message
179
+ -------------------------------------------
180
+
181
+ To add a footer to your message you can use the
182
+ :class: `Symfony\\ Component\\ Notifier\\ Bridge\\ Slack\\ Block\\ SlackContextBlock ` class::
183
+
184
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackContextBlock;
185
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
186
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
187
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
188
+ use Symfony\Component\Notifier\Message\ChatMessage;
189
+
190
+ $chatMessage = new ChatMessage('Symfony Feature');
191
+
192
+ $contextBlock = (new SlackContextBlock())
193
+ ->text('My Context')
194
+ ->image('https://symfony.com/logos/symfony_white_03.png', 'Symfony Logo')
195
+ ;
196
+
197
+ $options = (new SlackOptions())
198
+ ->block((new SlackSectionBlock())->text('My message'))
199
+ ->block(new SlackDividerBlock())
200
+ ->block(
201
+ (new SlackSectionBlock())
202
+ ->field('*Max Rating*')
203
+ ->field('5.0')
204
+ ->field('*Min Rating*')
205
+ ->field('1.0')
206
+ )
207
+ ->block($contextBlock)
208
+ ;
209
+
210
+ $chatter->send($chatMessage);
211
+
212
+ The result will be something like:
213
+
214
+ .. image :: /_images/notifier/slack/slack-footer.png
215
+ :align: center
216
+
217
+ .. versionadded :: 5.3
218
+
219
+ The `SlackContextBlock ` class was introduced in Symfony 5.3.
220
+
221
+ Sending a Slack Message as a reply
222
+ -------------------------------------------
223
+
224
+ To send your slack message as a reply in a thread you can use the
225
+ :method: `SlackOptions::threadTs() <Symfony\\ Component\\ Notifier\\ Bridge\\ Slack\\ SlackOptions::threadTs> ` method::
226
+
227
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
228
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
229
+ use Symfony\Component\Notifier\Message\ChatMessage;
230
+
231
+ $chatMessage = new ChatMessage('Symfony Feature');
232
+
233
+ $options = (new SlackOptions())
234
+ ->block((new SlackSectionBlock())->text('My reply'))
235
+ ->threadTs('1621592155.003100')
236
+ ;
237
+
238
+ // Add the custom options to the chat message and send the message
239
+ $chatMessage->options($options);
240
+
241
+ $chatter->send($chatMessage);
242
+
243
+ The result will be something like:
244
+
245
+ .. image :: /_images/notifier/slack/message-reply.png
246
+ :align: center
247
+
248
+ .. versionadded :: 5.3
249
+
250
+ The `threadTs() ` method was introduced in Symfony 5.3.
251
+
138
252
Adding Interactions to a Discord Message
139
253
----------------------------------------
140
254
0 commit comments