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

Slack: add properties for overriding channel and emoji #173

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions docs/services/slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ Shoutrrr URL:

--8<-- "docs/services/slack/config.md"

!!! info "Color format"
!!! info "Some properties require URL encoding"
The format for the `Color` prop follows the [slack docs](https://api.slack.com/reference/messaging/attachments#fields)
but `#` needs to be escaped as `%23` when passed in a URL.
So <span style="background:#ff8000;width:.9em;height:.9em;display:inline-block;vertical-align:middle"></span><code>#ff8000</code> would be `%23ff8000` etc.


The same applies to the `Channel` property when prefixing with `#` (not required).
## Examples

!!! example
All fields set:
```uri
slack://ShoutrrrBot@T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX?color=good&title=Great+News
```
slack://ShoutrrrBot@T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX?channel=non-default-chan&color=good&emoji=sunny&title=Great+News
```
2 changes: 2 additions & 0 deletions pkg/services/slack/slack_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Config struct {
Token []string `desc:"Webhook token parts" url:"host,path1,path2"`
Color string `key:"color" optional:"" desc:"Message left-hand border color"`
Title string `key:"title" optional:"" desc:"Prepended text above the message"`
Channel string `key:"channel" optional:"" desc:"Overridden channel name (e.g. shoutrrr) or ID (e.g. C8UJ12P4P)"`
Emoji string `key:"emoji" optional:"" desc:"Overridden emoji name (with or without colons) from the Slack workspace"`
}

// GetURL returns a URL representation of it's current field values
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/slack/slack_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const (
TokenBMissing ErrorMessage = "second part of the API token is missing"
// TokenCMissing from the service URL
TokenCMissing ErrorMessage = "third part of the API token is missing."
// TokenAMalformed inthe service URL
// TokenAMalformed in the service URL
TokenAMalformed ErrorMessage = "first part of the API token is malformed"
// TokenBMalformed inthe service URL
// TokenBMalformed in the service URL
TokenBMalformed ErrorMessage = "second part of the API token is malformed"
// TokenCMalformed inthe service URL
// TokenCMalformed in the service URL
TokenCMalformed ErrorMessage = "third part of the API token is malformed"
// NotEnoughArguments provided in the service URL
NotEnoughArguments ErrorMessage = "the apiURL does not include enough arguments"
Expand Down
4 changes: 4 additions & 0 deletions pkg/services/slack/slack_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
type JSON struct {
Text string `json:"text"`
BotName string `json:"username,omitempty"`
Channel string `json:"channel,omitempty"`
Emoji string `json:"icon_emoji,omitempty"`
Blocks []block `json:"blocks,omitempty"`
Attachments []attachment `json:"attachments,omitempty"`
}
Expand Down Expand Up @@ -54,6 +56,8 @@ func CreateJSONPayload(config *Config, message string) ([]byte, error) {
JSON{
Text: config.Title,
BotName: config.BotName,
Channel: config.Channel,
Emoji: config.Emoji,
Attachments: atts,
})
}
2 changes: 1 addition & 1 deletion pkg/services/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var _ = Describe("the slack service", func() {
Describe("the slack config", func() {
When("parsing the configuration URL", func() {
It("should be identical after de-/serialization", func() {
testURL := "slack://testbot@AAAAAAAAA/BBBBBBBBB/123456789123456789123456?color=3f00fe&title=Test+title"
testURL := "slack://testbot@AAAAAAAAA/BBBBBBBBB/123456789123456789123456?channel=foo&color=3f00fe&emoji=sunny&title=Test+title"

url, err := url.Parse(testURL)
Expect(err).NotTo(HaveOccurred(), "parsing")
Expand Down