Skip to content

Commit 0c89120

Browse files
committed
minor symfony#57271 [Notifier] [Slack] Add README examples about button block element and emoji/verbatim options (cvergne)
This PR was merged into the 7.2 branch. Discussion ---------- [Notifier] [Slack] Add README examples about button block element and emoji/verbatim options | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony-docs#19929 | License | MIT This PR is just a followup of my previously merged PR symfony#54737. Following the merge, [an issue was created about documentation](symfony/symfony-docs#19929), but each Notifier Bridge documentation is directly in README of each bridge so here it is :) Commits ------- 1a52e87 [Notifier] [Slack] Add README examples about button block element and emoji/verbatim options to section block
2 parents d45e6d6 + 1a52e87 commit 0c89120

File tree

1 file changed

+68
-0
lines changed
  • src/Symfony/Component/Notifier/Bridge/Slack

1 file changed

+68
-0
lines changed

src/Symfony/Component/Notifier/Bridge/Slack/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ $chatMessage->options($slackOptions);
7474
$chatter->send($chatMessage);
7575
```
7676

77+
Alternatively, a single button can be added to a section using the `accessory()` method and the `SlackButtonBlockElement` class.
78+
79+
```php
80+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackButtonBlockElement;
81+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
82+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
83+
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
84+
use Symfony\Component\Notifier\Message\ChatMessage;
85+
86+
$chatMessage = new ChatMessage('Contribute To Symfony');
87+
88+
$slackOptions = (new SlackOptions())
89+
->block((new SlackSectionBlock())
90+
->text('Symfony Framework')
91+
->accessory(
92+
new SlackButtonBlockElement(
93+
'Report bugs',
94+
'https://symfony.com/doc/current/contributing/code/bugs.html',
95+
'danger'
96+
)
97+
)
98+
)
99+
->block(new SlackDividerBlock())
100+
->block((new SlackSectionBlock())
101+
->text('Symfony Documentation')
102+
->accessory(
103+
new SlackButtonBlockElement(
104+
'Improve Documentation',
105+
'https://symfony.com/doc/current/contributing/documentation/standards.html',
106+
'primary'
107+
)
108+
)
109+
);
110+
111+
// Add the custom options to the chat message and send the message
112+
$chatMessage->options($slackOptions);
113+
114+
$chatter->send($chatMessage);
115+
```
116+
77117
Adding Fields and Values to a Message
78118
-------------------------------------
79119

@@ -104,6 +144,34 @@ $chatMessage->options($options);
104144
$chatter->send($chatMessage);
105145
```
106146

147+
Define text objects properties
148+
------------------------------
149+
150+
[Text objects properties](https://api.slack.com/reference/block-kit/composition-objects#text) can be set on any `text()` or `field()` method :
151+
152+
```php
153+
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
154+
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
155+
use Symfony\Component\Notifier\Message\ChatMessage;
156+
157+
$chatMessage = new ChatMessage('Slack Notifier');
158+
159+
$options = (new SlackOptions())
160+
->block(
161+
(new SlackSectionBlock())
162+
->field('My **Markdown** content with clickable URL : symfony.com') // Markdown content (default)
163+
->field('*Plain text content*', markdown: false) // Plain text content
164+
->field('Not clickable URL : symfony.com', verbatim: true) // Only for markdown content
165+
->field('Thumbs up emoji code is :thumbsup: ', emoji: false) // Only for plain text content
166+
);
167+
168+
// Add the custom options to the chat message and send the message
169+
$chatMessage->options($options);
170+
171+
$chatter->send($chatMessage);
172+
```
173+
174+
107175
Adding a Header to a Message
108176
----------------------------
109177

0 commit comments

Comments
 (0)