Version: v0.7.1 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 13 Imported by: 1




View Source
const (
	// Scheme is the identifying part of this service's configuration URL
	Scheme = "slack"


View Source
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")


func CreateJSONPayload

func CreateJSONPayload(config *Config, message string) interface{}

CreateJSONPayload compatible with the slack post message API


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 {
	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

func CreateConfigFromURL(serviceURL *url.URL) (*Config, error)

CreateConfigFromURL to use within the slack service

func (*Config) GetURL

func (config *Config) GetURL() *url.URL

GetURL returns a URL representation of it's current field values

func (*Config) SetURL

func (config *Config) SetURL(url *url.URL) error

SetURL updates a ServiceConfig from a URL representation of it's field values

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

type Service struct {
	// contains filtered or unexported fields

Service sends notifications to a pre-configured channel or user

func (*Service) Initialize

func (service *Service) Initialize(configURL *url.URL, logger types.StdLogger) error

Initialize loads ServiceConfig from configURL and sets logger for this Service

func (*Service) Send

func (service *Service) Send(message string, params *types.Params) error

Send a notification message to Slack

type Token

type Token struct {
	// contains filtered or unexported fields

Token is a Slack API token or a Slack webhook token

func ParseToken

func ParseToken(str string) (*Token, error)

ParseToken parses and normalizes a token string

func (*Token) Authorization added in v0.5.0

func (token *Token) Authorization() string

Authorization returns the corresponding `Authorization` HTTP header value for the Token

func (*Token) GetPropValue added in v0.5.0

func (token *Token) GetPropValue() (string, error)

GetPropValue returns a deserializable string representation of the token (implementation of the types.ConfigProp interface)

func (*Token) IsAPIToken added in v0.5.0

func (token *Token) IsAPIToken() bool

IsAPIToken returns whether the identifier is set to anything else but the webhook identifier (`hook`)

func (*Token) SetFromProp added in v0.5.0

func (token *Token) SetFromProp(propValue string) error

SetFromProp updates it's state according to the passed string (implementation of the types.ConfigProp interface)

func (*Token) String

func (token *Token) String() string

String returns the token in normalized format with dashes (-) as separator

func (Token) TypeIdentifier added in v0.5.0

func (token Token) TypeIdentifier() string

TypeIdentifier returns the type identifier of the token

func (*Token) UserInfo added in v0.5.0

func (token *Token) UserInfo() *url.Userinfo

UserInfo returns a url.Userinfo struct populated from the token

func (Token) WebhookURL added in v0.5.0

func (token Token) WebhookURL() string

WebhookURL returns the corresponding Webhook URL for the Token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL