Skip to content

Commit b989cc5

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: Docs for Slack options field() method
2 parents 30a49fe + 7bfd2ef commit b989cc5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
16.9 KB
Loading

notifier/chatters.rst

+38
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,44 @@ to add some interactive options called `Block elements`_::
9797

9898
$chatter->send($chatMessage);
9999

100+
Adding Fields and Values to a Slack Message
101+
-------------------------------------------
102+
103+
To add fields and values to your message you can use the
104+
:method:`SlackSectionBlock::field() <Symfony\\Component\\Notifier\\Bridge\\Slack\\Block\\SlackSectionBlock::field>` method::
105+
106+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
107+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
108+
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
109+
use Symfony\Component\Notifier\Message\ChatMessage;
110+
111+
$chatMessage = new ChatMessage('Symfony Feature');
112+
113+
$options = (new SlackOptions())
114+
->block((new SlackSectionBlock())->text('My message'))
115+
->block(new SlackDividerBlock())
116+
->block(
117+
(new SlackSectionBlock())
118+
->field('*Max Rating*')
119+
->field('5.0')
120+
->field('*Min Rating*')
121+
->field('1.0')
122+
);
123+
124+
// Add the custom options to the chat message and send the message
125+
$chatMessage->options($options);
126+
127+
$chatter->send($chatMessage);
128+
129+
The result will be something like:
130+
131+
.. image:: /_images/notifier/slack/field-method.png
132+
:align: center
133+
134+
.. versionadded:: 5.1
135+
136+
The `field()` method was introduced in Symfony 5.1.
137+
100138
Adding Interactions to a Discord Message
101139
----------------------------------------
102140

0 commit comments

Comments
 (0)