Closed thomaspoignant closed 3 weeks ago
I am applying to this issue via OnlyDust platform.
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.
Here’s how I would tackle this issue:
Analyze the existing Slack notifier implementation:
Implement a Discord notifier:
POST
to /channels/{channel.id}/messages
) to send messages.Integrate the new Discord notifier:
Test the Discord notifier:
Completion Criteria:
I am applying to this issue via OnlyDust platform.
hello @ i'm an experienced frontend developer and a blockchain developer i would love to work on this issue Pleasee kindly assign :)
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!
Please is there any chance I could be assigned this issue
Could I take over this issue?
I’d like to resolve this.
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.
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.
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
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
May I pick this up?
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.