Skip to content

Commit 489356a

Browse files
authored
fix(notifications): include icon in slack legacy url (#1303)
1 parent 08831f7 commit 489356a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/notifications/notifier_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ var _ = Describe("notifications", func() {
149149
color := notifications.ColorInt
150150
data := notifications.GetTemplateData(command)
151151
title := url.QueryEscape(data.Title)
152+
username := "containrrrbot"
153+
iconURL := "https://containrrr.dev/watchtower-sq180.png"
152154
expected := fmt.Sprintf("discord://%s@%s?color=0x%x&colordebug=0x0&colorerror=0x0&colorinfo=0x0&colorwarn=0x0&title=%s&username=watchtower", token, channel, color, title)
153155
buildArgs := func(url string) []string {
154156
return []string{
@@ -167,6 +169,27 @@ var _ = Describe("notifications", func() {
167169
hookURL := fmt.Sprintf("https://%s/api/webhooks/%s/%s/slack", "discordapp.com", channel, token)
168170
testURL(buildArgs(hookURL), expected, time.Duration(0))
169171
})
172+
When("icon URL and username are specified", func() {
173+
It("should return the expected URL", func() {
174+
hookURL := fmt.Sprintf("https://%s/api/webhooks/%s/%s/slack", "discord.com", channel, token)
175+
expectedOutput := fmt.Sprintf("discord://%s@%s?avatar=%s&color=0x%x&colordebug=0x0&colorerror=0x0&colorinfo=0x0&colorwarn=0x0&title=%s&username=%s", token, channel, url.QueryEscape(iconURL), color, title, username)
176+
expectedDelay := time.Duration(7) * time.Second
177+
args := []string{
178+
"--notifications",
179+
"slack",
180+
"--notification-slack-hook-url",
181+
hookURL,
182+
"--notification-slack-identifier",
183+
username,
184+
"--notification-slack-icon-url",
185+
iconURL,
186+
"--notifications-delay",
187+
fmt.Sprint(expectedDelay.Seconds()),
188+
}
189+
190+
testURL(args, expectedOutput, expectedDelay)
191+
})
192+
})
170193
})
171194
When("converting a slack service config into a shoutrrr url", func() {
172195
command := cmd.NewRootCommand()

pkg/notifications/slack.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func (s *slackTypeNotifier) GetURL(c *cobra.Command, title string) (string, erro
5656
SplitLines: true,
5757
Username: s.Username,
5858
}
59+
60+
if s.IconURL != "" {
61+
conf.Avatar = s.IconURL
62+
}
63+
5964
return conf.GetURL().String(), nil
6065
}
6166

0 commit comments

Comments
 (0)