thomaspoignant / go-feature-flag

GO Feature Flag is a simple, complete and lightweight self-hosted feature flag solution 100% Open Source. 🎛️
https://gofeatureflag.org/
MIT License
1.49k stars 148 forks source link

(feature) Discord Notifier #2564

Closed thomaspoignant closed 3 weeks ago

thomaspoignant commented 1 month ago

Requirements

As of Today GO Feature Flag is able to notify difference sources when a flag is changing (see relay proxy configuration and go module).

Slack is supported since a lot of companies are using it, but some teams prefer to use Discord instead.

To support discord we can implement a new notifier using the Discord API to send the message of flag change inside a teams channel.

A good inspiration to build this is to follow what is done for the slack notifier integration: https://github.com/thomaspoignant/go-feature-flag/tree/main/notifier/slacknotifier.

JosueBrenes commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm Josué Brenes and I'll be working on issue. I'm Dojo Coding member.

I estimate this will take 5 day to complete.

How I plan on tackling this issue

Here’s how I would tackle this issue:

  1. Analyze the existing Slack notifier implementation:

    • I will review the current Slack notifier code provided in the repository here to understand how it interacts with the Slack API and handles flag changes.
    • This will serve as a baseline for implementing the Discord notifier.
  2. Implement a Discord notifier:

    • I will use the Discord API to create a new notifier that sends flag change messages to a Discord channel. This will require:
      • Setting up a Discord bot with the appropriate permissions to send messages to a specific channel.
      • Using the Discord API’s HTTP requests (POST to /channels/{channel.id}/messages) to send messages.
      • Configuring the notifier to format the messages similarly to the Slack notifier (include relevant details such as flag name, old value, new value, and the timestamp).
  3. Integrate the new Discord notifier:

    • I will ensure that the new Discord notifier integrates seamlessly with the existing GO Feature Flag system, following the structure and patterns used for other notifiers (like the Slack notifier).
    • This includes updating any configuration files or relay proxy settings to support the new notifier option.
  4. Test the Discord notifier:

    • I will create unit and integration tests to verify that the Discord notifier works as expected. This will include:
      • Sending test flag change events to a Discord channel and validating that the message is correctly formatted and delivered.
      • Checking edge cases, such as connection failures or invalid channel IDs, to ensure proper error handling.
  5. Completion Criteria:

    • The issue will be resolved when the Discord notifier is fully functional and sends flag change messages to Discord channels.
    • The implementation will follow the structure of the Slack notifier and will include sufficient tests to verify its functionality.
martinvibes commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

hello @ i'm an experienced frontend developer and a blockchain developer i would love to work on this issue Pleasee kindly assign :)

bigherc18 commented 3 weeks ago

Hello! I'm an experienced Software Engineer with over 5 years of experience. Although I'm primarily using Python right now, I've written and loved working with Go in the past, and I'd love the chance to get back to it.

I looked into Go Feature Flag and the Open Feature standard, and they really resonated with me—I'd be more than happy to contribute!

Regarding the issue, I'll begin by reviewing how the Slack notifier is written, then check the Discord API documentation, and jump right into implementing it!

Kaminar-i commented 3 weeks ago

Please is there any chance I could be assigned this issue

pheobeayo commented 3 weeks ago

Could I take over this issue?

sasasamaes commented 3 weeks ago

I’d like to resolve this.

  1. Familiarize Yourself with the Existing Slack Notifier

    • Review the existing Slack Notifier code in the GO Feature Flag repository: Slack Notifier Implementation. • This will give you insight into the structure and process used to notify Slack about feature flag changes.

  2. Create a Discord Notifier Structure

    • In the notifier directory, create a new folder called discordnotifier. • Inside this folder, create a Go file for the notifier (e.g., discord_notifier.go) where the core logic for sending notifications to Discord will live.

  3. Define the Discord Notifier Structure

    • Define a struct to represent the DiscordNotifier. It should include necessary fields like the webhook URL (since Discord notifications usually require a webhook URL to send messages). package discordnotifier

import ( "net/http" "bytes" "encoding/json" "log" )

type DiscordNotifier struct { WebhookURL string json:"webhook_url" }

4. Implement the Notification Logic

    •   Implement the function to send a message to a Discord channel using the Discord Webhook API.
    •   Refer to the Slack Notifier’s logic, but adjust it to fit Discord’s payload structure.

func (dn *DiscordNotifier) NotifyChange(flagName string, oldValue, newValue interface{}) error { message := map[string]string{ "content": "Flag change detected: " + flagName + "\nOld Value: " + fmt.Sprint(oldValue) + "\nNew Value: " + fmt.Sprint(newValue), } jsonData, err := json.Marshal(message) if err != nil { return err }

req, err := http.NewRequest("POST", dn.WebhookURL, bytes.NewBuffer(jsonData))
if err != nil {
    return err
}
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
    log.Println("Failed to send Discord notification:", resp.Status)
    return fmt.Errorf("discord notification failed with status code %d", resp.StatusCode)
}

return nil

}

5. Add Configuration for the Discord Notifier

    •   Update the configuration file or setup to accept discord_notifier as an option.
    •   Ensure that users can specify the Discord webhook URL in the configuration.

6. Test the Discord Notifier

    •   Write tests to ensure that the notifier functions correctly. Use mock HTTP servers to simulate the Discord API responses.

func TestNotifyChange(t *testing.T) { // Mock server setup and test cases }



7. Documentation and Usage Instructions

    •   Update the documentation to include instructions on configuring the Discord notifier. Provide examples on how users can add this notifier to their configuration.

ETA: 2 Days
SoarinSkySagar commented 3 weeks ago

Can I start working on this? I'll start by reviewing how the Slack notifier has been implemented, then go through the discord api and determine an approach. I'll follow a similar approach as the slack notifier, then after implementing it I'll check it thoroughly for any errors and bugs and make sure it is working.

ETA: 2 Days

0xdevcollins commented 3 weeks ago

May I pick this up?