| 1 | package slackscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 6 | |
| 7 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 8 | "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 9 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 10 | ) |
| 11 | |
| 12 | // Config for the slack service. |
| 13 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config# struct { |
| 14 | standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/.EnumlessConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#EnumlessConfig. |
| 15 | |
| 16 | BotNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#BotName. string `desc:"Bot name" key:"botname,username" optional:"uses bot default"` |
| 17 | Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Icon. string `desc:"Use emoji or URL as icon (based on presence of http(s):// prefix)" key:"icon,icon_emoji,icon_url" optional:"" default:""` |
| 18 | Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Token. Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Token# `desc:"API Bot token" url:"user,pass"` |
| 19 | Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Color. string `desc:"Message left-hand border color" key:"color" optional:"default border color"` |
| 20 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Title. string `desc:"Prepended text above the message" key:"title" optional:"omitted"` |
| 21 | Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Channel. string `desc:"Channel to send messages to in Cxxxxxxxxxx format" url:"host"` |
| 22 | ThreadTSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#ThreadTS. string `desc:"ts value of the parent message (to send message as reply in thread)" key:"thread_ts" optional:""` |
| 23 | } |
| 24 | |
| 25 | const ( |
| 26 | // Scheme is the identifying part of this service's configuration URL. |
| 27 | Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Scheme. = "slack" |
| 28 | ) |
| 29 | |
| 30 | // GetURL returns a URL representation of it's current field values. |
| 31 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 32 | resolver := formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(c) |
| 33 | |
| 34 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#getURL().(&resolver) |
| 35 | } |
| 36 | |
| 37 | // SetURL updates a ServiceConfig from a URL representation of it's field values. |
| 38 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#SetURL().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 39 | resolver := formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(c) |
| 40 | |
| 41 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#setURL().(&resolver, serviceURL) |
| 42 | } |
| 43 | |
| 44 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#getURL().(resolver typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ConfigQueryResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#) *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 45 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 46 | Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.: c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Token..UserInfoscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Token#UserInfo().(), |
| 47 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Channel., |
| 48 | Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Scheme., |
| 49 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: false, |
| 50 | RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery.: formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.BuildQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/BuildQuery().(resolver), |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#setURL().(resolver typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ConfigQueryResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#, serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 55 | var token string |
| 56 | |
| 57 | if len(serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.) > 1 { |
| 58 | // Reading legacy config URL format |
| 59 | token = serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() + serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path. |
| 60 | c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Channel. = "webhook" |
| 61 | c.BotNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#BotName. = serviceURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().() |
| 62 | } else { |
| 63 | token = serviceURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Stringscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#String().() |
| 64 | c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Channel. = serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() |
| 65 | } |
| 66 | |
| 67 | if serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() != "slack://[email protected]" { |
| 68 | if err := c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Token..SetFromPropscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Token#SetFromProp().(token); err != nil { |
| 69 | return err |
| 70 | } |
| 71 | } else { |
| 72 | c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#Token..rawscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Token#raw. = token // Set raw token without validation |
| 73 | } |
| 74 | |
| 75 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 76 | if err := resolver.Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#Set.(key, vals[0]); err != nil { |
| 77 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting query parameter %q to %q: %w", key, vals[0], err) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | // CreateConfigFromURL to use within the slack service. |
| 85 | func CreateConfigFromURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/CreateConfigFromURL().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) (*Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#, error) { |
| 86 | config := Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#{} |
| 87 | err := config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/slack`/Config#SetURL().(serviceURL) |
| 88 | |
| 89 | return &config, err |
| 90 | } |