Skip to content

Commit 9400384

Browse files
committed
feature #13558 Add Discord notifier (mpiot)
This PR was squashed before being merged into the 5.x branch. Discussion ---------- Add Discord notifier Add documentation about Discord notifier integration from symfony/symfony#36475 Commits ------- c630bcb Add Discord notifier
2 parents 8b30190 + c630bcb commit 9400384

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

notifier.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ integration with these chat services:
140140
========== ================================ ===========================================================================
141141
Service Package DSN
142142
========== ================================ ===========================================================================
143+
Discord ``symfony/discord-notifier`` ``discord://TOKEN@default?webhook_id=ID``
143144
GoogleChat ``symfony/google-chat-notifier`` ``googlechat://ACCESS_KEY:ACCESS_TOKEN@default/SPACE?threadKey=THREAD_KEY``
144145
LinkedIn ``symfony/linked-in-notifier`` ``linkedin://TOKEN:USER_ID@default``
145146
Mattermost ``symfony/mattermost-notifier`` ``mattermost://TOKEN@ENDPOINT?channel=CHANNEL``
@@ -157,7 +158,7 @@ Zulip ``symfony/zulip-notifier`` ``zulip://EMAIL:APIKEY@ENDPOINT?ch
157158

158159
.. versionadded:: 5.2
159160

160-
The GoogleChat, LinkedIn and Zulip integrations were introduced in Symfony 5.2.
161+
The GoogleChat, LinkedIn, Zulip and Discord integrations were introduced in Symfony 5.2.
161162

162163
Chatters are configured using the ``chatter_transports`` setting:
163164

notifier/chatters.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,56 @@ some interactive options called `Block elements`_::
9999
$chatter->send($chatMessage);
100100

101101
.. _`Block elements`: https://api.slack.com/reference/block-kit/block-elements
102+
103+
Adding Interactions to a Discord Message
104+
--------------------------------------
105+
106+
With a Discord message, you can use the
107+
:class:`Symfony\\Component\\Notifier\\Bridge\\Discord\\DiscordOptions` to add
108+
some interactive options called `Embed elements`_::
109+
110+
use Symfony\Component\Notifier\Bridge\Discord\Block\DiscordEmbed;
111+
use Symfony\Component\Notifier\Bridge\Discord\Block\DiscordFieldEmbedObject;
112+
use Symfony\Component\Notifier\Bridge\Discord\Block\DiscordFooterEmbedObject;
113+
use Symfony\Component\Notifier\Bridge\Discord\Block\DiscordMediaEmbedObject;
114+
use Symfony\Component\Notifier\Bridge\Discord\DiscordOptions;
115+
use Symfony\Component\Notifier\Message\ChatMessage;
116+
117+
$chatMessage = new ChatMessage('');
118+
119+
// Create Discord Embed
120+
$discordOptions = (new DiscordOptions())
121+
->username('connor bot')
122+
->addEmbed((new DiscordEmbed())
123+
->color(2021216)
124+
->title('New song added!')
125+
->thumbnail((new DiscordMediaEmbedObject())
126+
->url('https://i.scdn.co/image/ab67616d0000b2735eb27502aa5cb1b4c9db426b'))
127+
->addField((new DiscordFieldEmbedObject())
128+
->name('Track')
129+
->value('[Common Ground](https://open.spotify.com/track/36TYfGWUhIRlVjM8TxGUK6)')
130+
->inline(true)
131+
)
132+
->addField((new DiscordFieldEmbedObject())
133+
->name('Artist')
134+
->value('Alasdair Fraser')
135+
->inline(true)
136+
)
137+
->addField((new DiscordFieldEmbedObject())
138+
->name('Album')
139+
->value('Dawn Dance')
140+
->inline(true)
141+
)
142+
->footer((new DiscordFooterEmbedObject())
143+
->text('Added ...')
144+
->iconUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Spotify_logo_without_text.svg/200px-Spotify_logo_without_text.svg.png')
145+
)
146+
)
147+
;
148+
149+
// Add the custom options to the chat message and send the message
150+
$chatMessage->options($discordOptions);
151+
152+
$chatter->send($chatMessage);
153+
154+
.. _`Embed elements`: https://discord.com/developers/docs/resources/webhook

0 commit comments

Comments
 (0)