Skip to content

Commit

Permalink
feat(notifications): add
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielHAlba committed Aug 18, 2022
1 parent f34ac90 commit 2de13e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions log/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package log
import "github.com/agflow/tools/notification/slack"

// NewSlackHook returns a hook for slack
func NewSlackHook(token string) Hook {
func NewSlackHook(token, channel string) Hook {
return func(info MetaInfo) error {
var color string
switch info.Lvl {
Expand All @@ -16,6 +16,6 @@ func NewSlackHook(token string) Hook {
}
msg := info.Msg + "\n"
slackCli := slack.New(token, true)
return slackCli.SendWithColor("feed-worker", msg, color)
return slackCli.SendWithColor(channel, msg, color)
}
}
5 changes: 3 additions & 2 deletions notification/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

const (
defaultChannel = "test-notifications"
// DefaultChannel is slack's default channel to send notifications
DefaultChannel = "test-notifications"
// ColorGood is slack's color "good"
ColorGood = "good"
// ColorWarning is slack's color "warning"
Expand All @@ -29,7 +30,7 @@ func New(token string, enabled bool) *Client {

func getChannel(channel string) string {
if channel == "" {
return defaultChannel
return DefaultChannel
}
return channel
}
Expand Down
4 changes: 2 additions & 2 deletions notification/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

func TestSend(t *testing.T) {
slackCli := New("xoxb-2314993037-3480243399810-eKklHxCNGvH7E3dnGaknRpZL", true)
require.Nil(t, slackCli.Send(defaultChannel, "this is a test notification"))
require.Nil(t, slackCli.Send(DefaultChannel, "this is a test notification"))
require.Nil(t, slackCli.SendWithColor(
defaultChannel,
DefaultChannel,
"this is a test notification with a color",
ColorGood,
),
Expand Down

0 comments on commit 2de13e3

Please sign in to comment.