@@ -26,6 +26,177 @@ SLACK_DSN=slack://xoxb-......@default?channel=#my-channel-name
26
26
SLACK_DSN=slack://xoxb-......@default?channel=fabien
27
27
```
28
28
29
+ Adding Interactions to a Message
30
+ --------------------------------
31
+
32
+ With a Slack message, you can use the ` SlackOptions ` class to add some
33
+ interactive options called [ Block elements] ( https://api.slack.com/reference/block-kit/block-elements ) .
34
+
35
+ ``` php
36
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackActionsBlock;
37
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
38
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackImageBlockElement;
39
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
40
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
41
+ use Symfony\Component\Notifier\Message\ChatMessage;
42
+
43
+ $chatMessage = new ChatMessage('Contribute To Symfony');
44
+
45
+ // Create Slack Actions Block and add some buttons
46
+ $contributeToSymfonyBlocks = (new SlackActionsBlock())
47
+ ->button(
48
+ 'Improve Documentation',
49
+ 'https://symfony.com/doc/current/contributing/documentation/standards.html',
50
+ 'primary'
51
+ )
52
+ ->button(
53
+ 'Report bugs',
54
+ 'https://symfony.com/doc/current/contributing/code/bugs.html',
55
+ 'danger'
56
+ );
57
+
58
+ $slackOptions = (new SlackOptions())
59
+ ->block((new SlackSectionBlock())
60
+ ->text('The Symfony Community')
61
+ ->accessory(
62
+ new SlackImageBlockElement(
63
+ 'https://symfony.com/favicons/apple-touch-icon.png',
64
+ 'Symfony'
65
+ )
66
+ )
67
+ )
68
+ ->block(new SlackDividerBlock())
69
+ ->block($contributeToSymfonyBlocks);
70
+
71
+ // Add the custom options to the chat message and send the message
72
+ $chatMessage->options($slackOptions);
73
+
74
+ $chatter->send($chatMessage);
75
+ ```
76
+
77
+ Adding Fields and Values to a Message
78
+ -------------------------------------
79
+
80
+ To add fields and values to your message you can use the ` field() ` method.
81
+
82
+ ``` php
83
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
84
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
85
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
86
+ use Symfony\Component\Notifier\Message\ChatMessage;
87
+
88
+ $chatMessage = new ChatMessage('Symfony Feature');
89
+
90
+ $options = (new SlackOptions())
91
+ ->block((new SlackSectionBlock())->text('My message'))
92
+ ->block(new SlackDividerBlock())
93
+ ->block(
94
+ (new SlackSectionBlock())
95
+ ->field('*Max Rating*')
96
+ ->field('5.0')
97
+ ->field('*Min Rating*')
98
+ ->field('1.0')
99
+ );
100
+
101
+ // Add the custom options to the chat message and send the message
102
+ $chatMessage->options($options);
103
+
104
+ $chatter->send($chatMessage);
105
+ ```
106
+
107
+ Adding a Header to a Message
108
+ ----------------------------
109
+
110
+ To add a header to your message use the ` SlackHeaderBlock ` class.
111
+
112
+ ``` php
113
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
114
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackHeaderBlock;
115
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
116
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
117
+ use Symfony\Component\Notifier\Message\ChatMessage;
118
+
119
+ $chatMessage = new ChatMessage('Symfony Feature');
120
+
121
+ $options = (new SlackOptions())
122
+ ->block((new SlackHeaderBlock('My Header')))
123
+ ->block((new SlackSectionBlock())->text('My message'))
124
+ ->block(new SlackDividerBlock())
125
+ ->block(
126
+ (new SlackSectionBlock())
127
+ ->field('*Max Rating*')
128
+ ->field('5.0')
129
+ ->field('*Min Rating*')
130
+ ->field('1.0')
131
+ );
132
+
133
+ // Add the custom options to the chat message and send the message
134
+ $chatMessage->options($options);
135
+
136
+ $chatter->send($chatMessage);
137
+ ```
138
+
139
+ Adding a Footer to a Message
140
+ ----------------------------
141
+
142
+ To add a header to your message use the ` SlackContextBlock ` class.
143
+
144
+ ``` php
145
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackContextBlock;
146
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
147
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
148
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
149
+ use Symfony\Component\Notifier\Message\ChatMessage;
150
+
151
+ $chatMessage = new ChatMessage('Symfony Feature');
152
+
153
+ $contextBlock = (new SlackContextBlock())
154
+ ->text('My Context')
155
+ ->image('https://symfony.com/logos/symfony_white_03.png', 'Symfony Logo')
156
+ ;
157
+
158
+ $options = (new SlackOptions())
159
+ ->block((new SlackSectionBlock())->text('My message'))
160
+ ->block(new SlackDividerBlock())
161
+ ->block(
162
+ (new SlackSectionBlock())
163
+ ->field('*Max Rating*')
164
+ ->field('5.0')
165
+ ->field('*Min Rating*')
166
+ ->field('1.0')
167
+ )
168
+ ->block($contextBlock)
169
+ ;
170
+
171
+ // Add the custom options to the chat message and send the message
172
+ $chatMessage->options($options);
173
+
174
+ $chatter->send($chatMessage);
175
+ ```
176
+
177
+ Sending a Message as a Reply
178
+ ----------------------------
179
+
180
+ To send your slack message as a reply in a thread use the ` threadTs() ` method.
181
+
182
+ ``` php
183
+ use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
184
+ use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
185
+ use Symfony\Component\Notifier\Message\ChatMessage;
186
+
187
+ $chatMessage = new ChatMessage('Symfony Feature');
188
+
189
+ $options = (new SlackOptions())
190
+ ->block((new SlackSectionBlock())->text('My reply'))
191
+ ->threadTs('1621592155.003100')
192
+ ;
193
+
194
+ // Add the custom options to the chat message and send the message
195
+ $chatMessage->options($options);
196
+
197
+ $chatter->send($chatMessage);
198
+ ```
199
+
29
200
Resources
30
201
---------
31
202
0 commit comments