Skip to content
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

Discord notifications #735

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
New notification sender for Discord webhooks
  • Loading branch information
hotpheex committed Aug 9, 2023
commit 52af7e9650be3dd8221f7817c58ea0c0c7752383
33 changes: 23 additions & 10 deletions extension/notification/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ type Config struct {
}

func init() {
log.Error("RUNNING")
log.Info(0)
notification.RegisterSender("discord", &sender{})
}

func (s *sender) Configure(config *notification.Config) (bool, error) {
log.Info(1)
// Get configuration
var httpConfig Config

Expand All @@ -42,7 +43,6 @@ func (s *sender) Configure(config *notification.Config) (bool, error) {
} else {
return false, nil
}

// Validate endpoint URL.
if httpConfig.Endpoint == "" {
return false, nil
Expand All @@ -62,23 +62,36 @@ func (s *sender) Configure(config *notification.Config) (bool, error) {
"name": "discord",
"endpoint": s.endpoint,
}).Info("extension.notification.discord: sender configured")

log.Info(2)
return true, nil
}

// type notificationEnvelope struct {
// types.EventNotification
// }

type DiscordMessage struct {
Content string `json:"content"`
Username string `json:"username"`
Username string `json:"username"`
Content string `json:"content"`
Embeds []Embed `json:"embeds"`
}

type Embed struct {
Title string `json:"title"`
Description string `json:"description"`
Footer Footer `json:"footer"`
}

type Footer struct {
Text string `json:"text"`
}

func (s *sender) Send(event types.EventNotification) error {
discordMessage := DiscordMessage{
Content: fmt.Sprintf("**%s**\n%s", event.Name, event.Message),
Username: "Keel",
Embeds: []Embed{
{
Title: fmt.Sprintf("%s: %s", event.Type.String(), event.Name),
Description: event.Message,
Footer: Footer{Text: event.Level.String()},
},
},
}

jsonMessage, err := json.Marshal(discordMessage)
Expand Down
1 change: 0 additions & 1 deletion extension/notification/discord/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestDiscordWebhookRequest(t *testing.T) {
}

t.Log(bodyStr)

}

// create test server with handler
Expand Down