diff --git a/log/slack.go b/log/slack.go index db35be5..ad47da2 100644 --- a/log/slack.go +++ b/log/slack.go @@ -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 { @@ -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) } } diff --git a/notification/slack/slack.go b/notification/slack/slack.go index 97111ab..defedfa 100644 --- a/notification/slack/slack.go +++ b/notification/slack/slack.go @@ -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" @@ -29,7 +30,7 @@ func New(token string, enabled bool) *Client { func getChannel(channel string) string { if channel == "" { - return defaultChannel + return DefaultChannel } return channel } diff --git a/notification/slack/slack_test.go b/notification/slack/slack_test.go index a3a760a..d6e9322 100644 --- a/notification/slack/slack_test.go +++ b/notification/slack/slack_test.go @@ -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, ),