nikoksr/notify

Discord Webhooks

gaurishhs opened this issue · 4 comments

Is your feature request related to a problem? Please describe.

Discord already has Webhooks for notifications, It makes no sense to use gateway (bot sessions) to send notifications

Describe the solution you'd like

Instead of using discordgo Use simple HTTP post requests to post to a discord webhook

Describe alternatives you've considered

Shoutrrr uses discord webhooks https://containrrr.dev/shoutrrr/0.7/services/discord/

Additional context

I'm willing to make a PR for this.
Discord Webhook Documentation

Hi @gaurishhs, we appreciate your input and I agree, the addition of webhooks does make a lot of sense! I don't agree however with your statement It makes no sense to use gateway (bot sessions) to send notifications. I don't see how it would hurt the project to offer this as a potential way of communication. Maybe somebody wants to use a write-only bot. Maybe somebody's existing infrastructure is build around bots and this allows Notify to integrate naturally into the existing system.

For plain notifications you're absolutely right that webhooks are the more suitable solution, which is why I'd like to include them. We won't however remove the support for Discord bots.

How do you feel about adding a DiscordWebhook service to the discord service directory? This would allow us something along the lines of the following usage:

Using a Discord Bot:

// Keep the existing constructor function to avoid a breaking change
discordBot, _ := discord.New()

// Add a bot constructor alias for explicity and consistency
discordBot, _ = discord.NewBot()

Using a Discord Webhook:

// Initialize a new service with a single Discord webhook
singleDiscordWebhook := discord.NewWebhook("https://some-url.here")

// Initialize a new service with multiple webhooks
multiDiscordWebhooks := discord.NewWebhook("https://some-url.here", "https://and-another-url.here")

If you do decide to add this to the library, please take a look at our internal HTTP service and use it for your implementation. A great usage example can be seen in #516.

We'd greatly appreciate your contribution. Let me know if there's anything I can help you with!

Ah yes, I'm sorry. I was just taking a first look at this library (thanks for this its really useful) and after taking a look at the http service i don't think so theres a need for seperate function since this will increase the size. I made the webhook thing functional by utilising the Discord Webhook API and the http service with a custom BuildPayload function

@gaurishhs that's great to hear! Did the HTTP servce work well for you?

I'm still inclined of adding this to the library as it reuses existing code, meaning no additional logic we have to maintain and at the same time makes the library or the discord service in particular more accessible.

Yes, It worked for me