Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 3 commits into from

Conversation

mpiot
Copy link
Contributor

@mpiot mpiot commented Apr 17, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#13558

Add a basic Discord notifier via webhook (https://discordapp.com/developers/docs/resources/webhook).

Capture d’écran de 2020-04-17 15-27-42

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)

Capture d’écran de 2020-04-17 15-27-54

At the moment it's not implemented yet in this PR, 2 possibilities:

  • the embed type by default (never the simple type)
  • add a DiscordConfigurationMessage object to enable the embed format ? (only on ChatMessage, not Notification)

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.

@nicolas-grekas nicolas-grekas added this to the next milestone Apr 18, 2020
@walva
Copy link
Contributor

walva commented Apr 19, 2020

@mpiot I'm willing to help! Is there something I can do? I'm currently trying to test your new feature.

@mpiot
Copy link
Contributor Author

mpiot commented Apr 19, 2020

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.

@noniagriconomie
Copy link
Contributor

Iirc there is a slack bridge, maybe do a « replication » of this bridge ?
As both are similar in main points

@mpiot
Copy link
Contributor Author

mpiot commented Apr 23, 2020

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 ?

@fabpot
Copy link
Member

fabpot commented Aug 10, 2020

@mpiot Can you submit a PR on symfony/recipes (you can have a look at other notifier bridge recipes to get some inspiration)?

@mpiot
Copy link
Contributor Author

mpiot commented Aug 10, 2020

@fabpot I look at this (changes and recipe) in few days (hollidays).
@skmedix Thanks, They've change URLs :( I'll fix it with the rest.

@fabpot
Copy link
Member

fabpot commented Sep 1, 2020

@mpiot Friendly ping :)

@mpiot mpiot force-pushed the discord-logger-handler branch 4 times, most recently from 32c3fd6 to d9a4000 Compare September 1, 2020 16:58
@mpiot
Copy link
Contributor Author

mpiot commented Sep 1, 2020

@fabpot Done for changes on this PR and open symfony/recipes#816

@mpiot mpiot force-pushed the discord-logger-handler branch from d9a4000 to bc0b9a5 Compare September 1, 2020 17:15

throw new TransportException(sprintf('Unable to post the Discord message: "%s" (%s).', $result['message'], $result['code']), $response);
}
}
Copy link
Member

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).

Copy link
Contributor Author

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... :/

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Sep 13, 2020

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.

@fabpot fabpot closed this Sep 13, 2020
@connorhu
Copy link
Contributor

I will finish the work on this PR.

@mpiot
Copy link
Contributor Author

mpiot commented Sep 13, 2020

@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: Cannot dump definition because of invalid class name ('chatter.transport_factory'). (#37298).

It appear the #38175 fix that. Probbaly why I can't test my PR.

@mpiot
Copy link
Contributor Author

mpiot commented Sep 13, 2020

@fabpot @connorhu By applying the patch #38175, I've can test my PR and it works well.

@connorhu
Copy link
Contributor

connorhu commented Sep 13, 2020

I finished the support of rich type webhook. Result of the spotify example:
image

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);

@mpiot
Copy link
Contributor Author

mpiot commented Sep 14, 2020

@connorhu Great job ;)
I think since this PR is closed, you can open a new one, if you want you can link this new one on:

Doc PR: symfony/symfony-docs#13558 (if you have the same organization, rename the channel by webhook id for example, I can do that)
Recipe PR: symfony/recipes#816

Both of this PRs should work, and maybe add a part in the documentation about the rich type ?

@fabpot
Copy link
Member

fabpot commented Sep 25, 2020

@connorhu Do you want to open a new PR?

@mpiot
Copy link
Contributor Author

mpiot commented Sep 25, 2020

@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:

@connorhu
Copy link
Contributor

@fabpot Yes I will create a new PR, but first I need to create some tests for the new classes.

@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@mpiot
Copy link
Contributor Author

mpiot commented Oct 5, 2020

@connorhu do you need some help for tests and open the new PR ? The 5.2 is really close.

@connorhu
Copy link
Contributor

@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.

fabpot added a commit that referenced this pull request Oct 12, 2020
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
OskarStark added a commit to symfony/symfony-docs that referenced this pull request Oct 23, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants