Skip to content

Commit

Permalink
Add ability to configure channel, username, icon emoji/url in slack n…
Browse files Browse the repository at this point in the history
…otification (#2975)

* Add ability to configure channel, username, icon emoji/url in slack cfg

* Update slack.yaml

---------

Co-authored-by: Thibault "bui" Koechlin <[email protected]>
Co-authored-by: Thibault "bui" Koechlin <[email protected]>
  • Loading branch information
3 people authored May 10, 2024
1 parent defa076 commit 14dc26b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmd/notification-slack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ import (
)

type PluginConfig struct {
Name string `yaml:"name"`
Webhook string `yaml:"webhook"`
LogLevel *string `yaml:"log_level"`
Name string `yaml:"name"`
Webhook string `yaml:"webhook"`
Channel string `yaml:"channel"`
Username string `yaml:"username"`
IconEmoji string `yaml:"icon_emoji"`
IconURL string `yaml:"icon_url"`
LogLevel *string `yaml:"log_level"`
}
type Notify struct {
ConfigByName map[string]PluginConfig
Expand All @@ -43,8 +47,12 @@ func (n *Notify) Notify(ctx context.Context, notification *protobufs.Notificatio
logger.Info(fmt.Sprintf("found notify signal for %s config", notification.Name))
logger.Debug(fmt.Sprintf("posting to %s webhook, message %s", cfg.Webhook, notification.Text))

err := slack.PostWebhookContext(ctx, n.ConfigByName[notification.Name].Webhook, &slack.WebhookMessage{
Text: notification.Text,
err := slack.PostWebhookContext(ctx, cfg.Webhook, &slack.WebhookMessage{
Text: notification.Text,
Channel: cfg.Channel,
Username: cfg.Username,
IconEmoji: cfg.IconEmoji,
IconURL: cfg.IconURL,
})
if err != nil {
logger.Error(err.Error())
Expand Down
6 changes: 6 additions & 0 deletions cmd/notification-slack/slack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ format: |
webhook: <WEBHOOK_URL>

# API request data as defined by the Slack webhook API.
#channel: <CHANNEL_NAME>
#username: <USERNAME>
#icon_emoji: <ICON_EMOJI>
#icon_url: <ICON_URL>

---

# type: slack
Expand Down

0 comments on commit 14dc26b

Please sign in to comment.