Documentation
¶
Index ¶
- Constants
- Variables
- func CreateJSONPayload(config *Config, message string) interface{}
- type APIResponse
- type Config
- type MessagePayload
- type Service
- type Token
- func (token *Token) Authorization() string
- func (token *Token) GetPropValue() (string, error)
- func (token *Token) IsAPIToken() bool
- func (token *Token) SetFromProp(propValue string) error
- func (token *Token) String() string
- func (token Token) TypeIdentifier() string
- func (token *Token) UserInfo() *url.Userinfo
- func (token Token) WebhookURL() string
Constants ¶
const (
// Scheme is the identifying part of this service's configuration URL
Scheme = "slack"
)
Variables ¶
var ( // ErrorInvalidToken is returned whenever the specified token does not match any known formats ErrorInvalidToken = errors.New("invalid slack token format") // ErrorMismatchedTokenSeparators is returned if the token uses different separators between parts (of the recognized `/-,`) ErrorMismatchedTokenSeparators = errors.New("invalid webhook token format") )
Functions ¶
func CreateJSONPayload ¶
CreateJSONPayload compatible with the slack post message API
Types ¶
type APIResponse ¶ added in v0.5.0
type APIResponse struct { Ok bool `json:"ok"` Error string `json:"error"` Warning string `json:"warning"` MetaData struct { Warnings []string `json:"warnings"` } `json:"response_metadata"` }
APIResponse is the default generic response message sent from the API
type Config ¶
type Config struct { standard.EnumlessConfig BotName string `optional:"uses bot default" key:"botname,username" desc:"Bot name"` Icon string `` /* 126-byte string literal not displayed */ Token Token `desc:"API Bot token" url:"user,pass"` Color string `key:"color" optional:"default border color" desc:"Message left-hand border color"` Title string `key:"title" optional:"omitted" desc:"Prepended text above the message"` Channel string `url:"host" desc:"Channel to send messages to in Cxxxxxxxxxx format"` ThreadTS string `key:"thread_ts" optional:"" desc:"ts value of the parent message (to send message as reply in thread)"` }
Config for the slack service
func CreateConfigFromURL ¶
CreateConfigFromURL to use within the slack service
type MessagePayload ¶ added in v0.5.0
type MessagePayload struct { Text string `json:"text"` BotName string `json:"username,omitempty"` Blocks []block `json:"blocks,omitempty"` Attachments []attachment `json:"attachments,omitempty"` ThreadTS string `json:"thread_ts,omitempty"` Channel string `json:"channel,omitempty"` IconEmoji string `json:"icon_emoji,omitempty"` IconURL string `json:"icon_url,omitempty"` }
MessagePayload used within the Slack service
func (*MessagePayload) SetIcon ¶ added in v0.5.0
func (p *MessagePayload) SetIcon(icon string)
SetIcon sets the appropriate icon field in the payload based on whether the input is a URL or not
type Service ¶
Service sends notifications to a pre-configured channel or user
func (*Service) Initialize ¶
Initialize loads ServiceConfig from configURL and sets logger for this Service
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token is a Slack API token or a Slack webhook token
func ParseToken ¶
ParseToken parses and normalizes a token string
func (*Token) Authorization ¶ added in v0.5.0
Authorization returns the corresponding `Authorization` HTTP header value for the Token
func (*Token) GetPropValue ¶ added in v0.5.0
GetPropValue returns a deserializable string representation of the token (implementation of the types.ConfigProp interface)
func (*Token) IsAPIToken ¶ added in v0.5.0
IsAPIToken returns whether the identifier is set to anything else but the webhook identifier (`hook`)
func (*Token) SetFromProp ¶ added in v0.5.0
SetFromProp updates it's state according to the passed string (implementation of the types.ConfigProp interface)
func (Token) TypeIdentifier ¶ added in v0.5.0
TypeIdentifier returns the type identifier of the token
func (*Token) UserInfo ¶ added in v0.5.0
UserInfo returns a url.Userinfo struct populated from the token
func (Token) WebhookURL ¶ added in v0.5.0
WebhookURL returns the corresponding Webhook URL for the Token