-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier ] Add Discord notifier #36475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ba3b08c
to
7b2c4d1
Compare
src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php
Outdated
Show resolved
Hide resolved
@mpiot I'm willing to help! Is there something I can do? I'm currently trying to test your new feature. |
Hi @walva, actually I'm waiting some discussion about this implementation. In fact, actually I've implemented it very simply (the first image) and without any configuration. I think I will add a Configuration to set the bot name and bot image. A part to discuss is about the message format, in Discord Webhook api, we can sent a simple message as already done here, or as embeds (image 2) with a border, title, footer, description (the simplest possibility). Use it by default ? (border color with importance, title with notification subject, description with content). Maybe other ideas ? I don't know. |
Iirc there is a slack bridge, maybe do a « replication » of this bridge ? |
Yes there is a SlackBridge, but I don't know the Slack API, I think you want to speak about the Block part of the Slack Notifier ? |
src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.xml
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php
Outdated
Show resolved
Hide resolved
@mpiot Can you submit a PR on symfony/recipes (you can have a look at other notifier bridge recipes to get some inspiration)? |
src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php
Outdated
Show resolved
Hide resolved
@mpiot Friendly ping :) |
….php Co-Authored-By: Oskar Stark <[email protected]>
32c3fd6
to
d9a4000
Compare
@fabpot Done for changes on this PR and open symfony/recipes#816 |
d9a4000
to
bc0b9a5
Compare
|
||
throw new TransportException(sprintf('Unable to post the Discord message: "%s" (%s).', $result['message'], $result['code']), $response); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the return
statement... which makes me think that this should be tested before merging (at least manually).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes my bad... I've just replace the return statement :void to :SentMessage. I went too fast and didn't pay attention that it was necessary to add a corresponding return statement in the function... :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you still interested in finishing this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much time lately, I'll try to watch this when I'm free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the quick reply. I'm going to close then. Perhaps someone can take over to finish it.
Anyone willing to take over this one. I think most of the work is already done. Apart from my last comment, this should also be tested in real life to be sure it works well. |
I will finish the work on this PR. |
@connorhu Thanks, I was going to try to watch. But I keep you see it. At the moment I've just return a SentMessage response, without message because Discord just return a 204 No Content. But I can't test if it work. Because when I try to link my Updated symfony dev branch on an existant project (that do not implement the Discord code) I've an error: It appear the #38175 fix that. Probbaly why I can't test my PR. |
I finished the support of rich type webhook. Result of the spotify example: What's next? Example: $chatter = new Chatter($discordTransport);
$chatMessage = new ChatMessage('');
$discordOptions = (new DiscordOptions())
->username('connor bot')
->addEmbed((new DiscordEmbed())
->color(2021216)
->title('New song added!')
->thumbnail((new DiscordMediaEmbedObject())
->url('https://i.scdn.co/image/ab67616d0000b2735eb27502aa5cb1b4c9db426b'))
->addField((new DiscordFieldEmbedObject())
->name('Track')
->value('[Common Ground](https://open.spotify.com/track/36TYfGWUhIRlVjM8TxGUK6)')
->inline(true)
)
->addField((new DiscordFieldEmbedObject())
->name('Artist')
->value('Alasdair Fraser')
->inline(true)
)
->addField((new DiscordFieldEmbedObject())
->name('Album')
->value('Dawn Dance')
->inline(true)
)
->footer((new DiscordFooterEmbedObject())
->text('Added ...')
->iconUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Spotify_logo_without_text.svg/200px-Spotify_logo_without_text.svg.png')
)
)
;
$chatMessage->options($discordOptions);
$chatter->send($chatMessage); |
@connorhu Great job ;) Doc PR: symfony/symfony-docs#13558 (if you have the same organization, rename the channel by webhook id for example, I can do that) Both of this PRs should work, and maybe add a part in the documentation about the rich type ? |
@connorhu Do you want to open a new PR? |
@connorhu If you can’t, say it to me. I can create it, at the moment, I've updated doc and recipe to match with your changes: |
@fabpot Yes I will create a new PR, but first I need to create some tests for the new classes. |
@connorhu do you need some help for tests and open the new PR ? The 5.2 is really close. |
I'm done the rest of the work. Nobody tested the code except me, so it's really experimental. |
This PR was merged into the 5.x branch. Discussion ---------- [Notifier ] Add Discord notifier | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | symfony/symfony-docs#13558 It finish the PR #36475 Commits ------- b9b20d7 Added Discord bridge notifier embeds and test 14790d8 Add Discord bridge notifier
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
Add a basic Discord notifier via webhook (https://discordapp.com/developers/docs/resources/webhook).
Actually I've just a Message from the notification displayed (on the image the simple line: "My notification subject").
It's also possible to have an embed message (https://discordapp.com/developers/docs/resources/channel#embed-object) as exemple I've done one with a title (message subject), description (message content), and a color (on the importance)
At the moment it's not implemented yet in this PR, 2 possibilities:
In my case, I prefer embded by default, like Email notification (subject, content and border color).
We also can add a configuration file (only for ChatMessage) to the Bot name, bot image.