8000 minor #49782 [Notifier] Add bridge documentation (MrYamous) · melya/symfony@b9348f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit b9348f8

Browse files
committed
minor symfony#49782 [Notifier] Add bridge documentation (MrYamous)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Notifier] Add bridge documentation | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | [From a doc issue](symfony/symfony-docs#17289) | License | MIT | Doc PR | From [Fabien's comment](symfony/symfony-docs#17289 (comment)) on doc issue, move Notifier Bridge documentation to their Readme Commits ------- 8d2a02d [Notifier] Add bridge documentation
2 parents 5eb54cf + 8d2a02d commit b9348f8

File tree

4 files changed

+337
-0
lines changed

4 files changed

+337
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,58 @@ where:
1414
- `TOKEN` the secure token of the webhook (returned for Incoming Webhooks)
1515
- `ID` the id of the webhook
1616

17+
Adding Interactions to a Message
18+
--------------------------------
19+
20+
With a Discord message, you can use the `DiscordOptions` class to add some
21+
interactive options called Embed `elements`.
22+
23+
```php
24+
use Symfony\Component\Notifier\Bridge\Discord\DiscordOptions;
25+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordEmbed;
26+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject;
27+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFooterEmbedObject;
28+
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordMediaEmbedObject;
29+
use Symfony\Component\Notifier\Message\ChatMessage;
30+
31+
$chatMessage = new ChatMessage('');
32+
33+
// Create Discord Embed
34+
$discordOptions = (new DiscordOptions())
35+
->username('connor bot')
36+
->addEmbed((new DiscordEmbed())
37+
->color(2021216)
38+
->title('New song added!')
39+
->thumbnail((new DiscordMediaEmbedObject())
40+
->url('https://i.scdn.co/image/ab67616d0000b2735eb27502aa5cb1b4c9db426b'))
41+
->addField((new DiscordFieldEmbedObject())
42+
->name('Track')
43+
->value('[Common Ground](https://open.spotify.com/track/36TYfGWUhIRlVjM8TxGUK6)')
44+
->inline(true)
45+
)
46+
->addField((new DiscordFieldEmbedObject())
47+
->name('Artist')
48+
->value('Alasdair Fraser')
49+
->inline(true)
50+
)
51+
->addField((new DiscordFieldEmbedObject())
52+
->name('Album')
53+
->value('Dawn Dance')
54+
->inline(true)
55+
)
56+
->footer((new DiscordFooterEmbedObject())
57+
->text('Added ...')
58+
->iconUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Spotify_logo_without_text.svg/200px-Spotify_logo_without_text.svg.png')
59+
)
60+
)
61+
;
62+
63+
// Add the custom options to the chat message and send the message
64+
$chatMessage->options($discordOptions);
65+
66+
$chatter->send($chatMessage);
67+
```
68+
1769
Resources
1870
---------
1971

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,87 @@ MICROSOFT_TEAMS_DSN=microsoftteams://default/PATH
1414
where:
1515
- `PATH` has the following format: `webhookb2/{uuid}@{uuid}/IncomingWebhook/{id}/{uuid}`
1616

17+
Adding text to a Message
18+
------------------------
19+
20+
With a Microsoft Teams, you can use the `ChatMessage` class::
21+
22+
```php
23+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransport;
24+
use Symfony\Component\Notifier\Message\ChatMessage;
25+
26+
$chatMessage = (new ChatMessage('Contribute To Symfony'))->transport('microsoftteams');
27+
$chatter->send($chatMessage);
28+
```
29+
30+
Adding Interactions to a Message
31+
--------------------------------
32+
33+
With a Microsoft Teams Message, you can use the `MicrosoftTeamsOptions` class
34+
to add [MessageCard options](https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference).
35+
36+
```php
37+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\ActionCard;
38+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\HttpPostAction;
39+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input\DateInput;
40+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input\TextInput;
41+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsOptions;
42+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransport;
43+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Section\Field\Fact;
44+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Section\Section;
45+
use Symfony\Component\Notifier\Message\ChatMessage;
46+
47+
$chatMessage = new ChatMessage('');
48+
49+
// Action elements
50+
$input = new TextInput();
51+
$input->id('input_title');
52+
$input->isMultiline(true)->maxLength(5)->title('In a few words, why would you like to participate?');
53+
54+
$inputDate = new DateInput();
55+
$inputDate->title('Proposed date')->id('input_date');
56+
57+
// Create Microsoft Teams MessageCard
58+
$microsoftTeamsOptions = (new MicrosoftTeamsOptions())
59+
->title('Symfony Online Meeting')
60+
->text('Symfony Online Meeting are the events where the best developers meet to share experiences...')
61+
->summary('Summary')
62+
->themeColor('#F4D35E')
63+
->section((new Section())
64+
->title('Talk about Symfony 5.3 - would you like to join? Please give a shout!')
65+
->fact((new Fact())
66+
->name('Presenter')
67+
->value('Fabien Potencier')
68+
)
69+
->fact((new Fact())
70+
->name('Speaker')
71+
->value('Patricia Smith')
72+
)
73+
->fact((new Fact())
74+
->name('Duration')
75+
->value('90 min')
76+
)
77+
->fact((new Fact())
78+
->name('Date')
79+
->value('TBA')
80+
)
81+
)
82+
->action((new ActionCard())
83+
->name('ActionCard')
84+
->input($input)
85+
->input($inputDate)
86+
->action((new HttpPostAction())
87+
->name('Add comment')
88+
->target('http://target')
89+
)
90+
)
91+
;
92+
93+
// Add the custom options to the chat message and send the message
94+
$chatMessage->options($microsoftTeamsOptions);
95+
$chatter->send($chatMessage);
96+
```
97+
1798
Resources
1899
---------
19100

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

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,177 @@ SLACK_DSN=slack://xoxb-......@default?channel=#my-channel-name
2626
SLACK_DSN=slack://xoxb-......@default?channel=fabien
2727
```
2828

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+
29200
Resources
30201
---------
31202

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@ where:
1414
- `TOKEN` is your Telegram token
1515
- `CHAT_ID` is your Telegram chat id
1616

17+
Adding Interactions to a Message
18+
--------------------------------
19+
20+
With a Telegram message, you can use the `TelegramOptions` class to add
21+
[message options](https://core.telegram.org/bots/api).
22+
23+
```php
24+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\InlineKeyboardButton;
25+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\InlineKeyboardMarkup;
26+
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
27+
use Symfony\Component\Notifier\Message\ChatMessage;
28+
29+
$chatMessage = new ChatMessage('');
30+
31+
// Create Telegram options
32+
$telegramOptions = (new TelegramOptions())
33+
->chatId('@symfonynotifierdev')
34+
->parseMode('MarkdownV2')
35+
->disableWebPagePreview(true)
36+
->disableNotification(true)
37+
->replyMarkup((new InlineKeyboardMarkup())
38+
->inlineKeyboard([
39+
(new InlineKeyboardButton('Visit symfony.com'))
40+
->url('https://symfony.com/'),
41+
])
42+
);
43+
44+
// Add the custom options to the chat message and send the message
45+
$chatMessage->options($telegramOptions);
46+
47+
$chatter->send($chatMessage);
48+
```
49+
1750
Resources
1851
---------
1952

0 commit comments

Comments
 (0)
0