slack

package
v0.6.9-cortex Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeChannelChannel = "channel"
	TypeChannelUser    = "user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	APIHost    string            `mapstructure:"api_host"`
	Retry      retry.Config      `mapstructure:"retry"`
	HTTPClient httpclient.Config `mapstructure:"http_client"`
}

AppConfig is a config loaded when siren is started

type Channel

type Channel struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg AppConfig, opts ...ClientOption) *Client

NewClient is a constructor to create slack client. this version uses go-slack client and this construction wraps the client.

func (*Client) ExchangeAuth

func (c *Client) ExchangeAuth(ctx context.Context, authCode, clientID, clientSecret string) (Credential, error)

ExchangeAuth submits client ID, client secret, and auth code and retrieve acces token and team name

func (*Client) GetWorkspaceChannels

func (c *Client) GetWorkspaceChannels(ctx context.Context, token secret.MaskableString) ([]Channel, error)

GetWorkspaceChannels fetches list of joined channel of a client

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, conf NotificationConfig, message Message) error

type ClientOption

type ClientOption func(*Client)

func ClientWithHTTPClient

func ClientWithHTTPClient(httpClient *httpclient.Client) ClientOption

ClientWithHTTPClient assigns custom http client when creating a slack client

func ClientWithRetrier

func ClientWithRetrier(runner retry.Runner) ClientOption

ClientWithRetrier wraps client call with retrier

type Credential

type Credential struct {
	AccessToken secret.MaskableString
	TeamName    string
}

type Encryptor

type Encryptor interface {
	Encrypt(str secret.MaskableString) (secret.MaskableString, error)
	Decrypt(str secret.MaskableString) (secret.MaskableString, error)
}

type GoSlackCaller

type GoSlackCaller interface {
	GetConversationsForUserContext(ctx context.Context, params *goslack.GetConversationsForUserParameters) (channels []goslack.Channel, nextCursor string, err error)
	GetUserByEmailContext(ctx context.Context, email string) (*goslack.User, error)
	SendMessageContext(ctx context.Context, channel string, options ...goslack.MsgOption) (string, string, string, error)
}

type Message

type Message struct {
	Channel     string              `yaml:"channel,omitempty" json:"channel,omitempty"  mapstructure:"channel"`
	Text        string              `yaml:"text,omitempty" json:"text,omitempty"  mapstructure:"text"`
	Username    string              `yaml:"username,omitempty" json:"username,omitempty"  mapstructure:"username"`
	IconEmoji   string              `yaml:"icon_emoji,omitempty" json:"icon_emoji,omitempty" mapstructure:"icon_emoji"`
	IconURL     string              `yaml:"icon_url,omitempty" json:"icon_url,omitempty"  mapstructure:"icon_url"`
	LinkNames   bool                `yaml:"link_names,omitempty" json:"link_names,omitempty"  mapstructure:"link_names"`
	Attachments []MessageAttachment `yaml:"attachments,omitempty" json:"attachments,omitempty" mapstructure:"attachments"`
}

TODO support block-kit messages

func (Message) BuildGoSlackMessageOptions

func (m Message) BuildGoSlackMessageOptions() ([]goslack.MsgOption, error)

type MessageAttachment

type MessageAttachment map[string]any

func (MessageAttachment) ToGoSlack

func (ma MessageAttachment) ToGoSlack() (*goslack.Attachment, error)

type NotificationConfig

type NotificationConfig struct {
	ReceiverConfig     `mapstructure:",squash"`
	SubscriptionConfig `mapstructure:",squash"`
}

NotificationConfig has all configs needed to send notification

func (*NotificationConfig) AsMap

func (c *NotificationConfig) AsMap() map[string]any

func (*NotificationConfig) Validate

func (c *NotificationConfig) Validate() error

Validate validates whether notification config contains required fields or not channel_name is not mandatory because in NotifyToReceiver flow, channel_name is being passed from the request (not from the config)

type PluginService

type PluginService struct {
	base.UnimplementedService
	// contains filtered or unexported fields
}

PluginService is a plugin service layer for slack

func NewPluginService

func NewPluginService(cfg AppConfig, cryptoClient Encryptor, opts ...ServiceOption) *PluginService

NewPluginService returns slack plugin service struct. This service implement [receiver.Resolver] and notification.Notifier interface.

func (*PluginService) BuildData

func (s *PluginService) BuildData(ctx context.Context, configurations map[string]any) (map[string]any, error)

BuildData populates receiver data field based on config

func (*PluginService) GetSystemDefaultTemplate

func (s *PluginService) GetSystemDefaultTemplate() string

func (*PluginService) PostHookDBTransformConfigs

func (s *PluginService) PostHookDBTransformConfigs(ctx context.Context, configurations map[string]any) (map[string]any, error)

PostHookTransformConfigs do transformation in post-hook service lifecycle

func (*PluginService) PostHookQueueTransformConfigs

func (s *PluginService) PostHookQueueTransformConfigs(ctx context.Context, notificationConfigMap map[string]any) (map[string]any, error)

func (*PluginService) PreHookDBTransformConfigs

func (s *PluginService) PreHookDBTransformConfigs(ctx context.Context, configurations map[string]any) (map[string]any, error)

func (*PluginService) PreHookQueueTransformConfigs

func (s *PluginService) PreHookQueueTransformConfigs(ctx context.Context, notificationConfigMap map[string]any) (map[string]any, error)

func (*PluginService) Send

func (s *PluginService) Send(ctx context.Context, notificationMessage notification.Message) (bool, error)

type ReceiverConfig

type ReceiverConfig struct {
	Token     secret.MaskableString `json:"token" mapstructure:"token"`
	Workspace string                `json:"workspace" mapstructure:"workspace"`
}

ReceiverConfig is a stored config for a slack receiver

func (*ReceiverConfig) AsMap

func (c *ReceiverConfig) AsMap() map[string]any

func (*ReceiverConfig) Validate

func (c *ReceiverConfig) Validate() error

type ReceiverData

type ReceiverData struct {
	Channels string `json:"channels" mapstructure:"channels"`
}

ReceiverData is a stored data for a slack receiver

func (*ReceiverData) AsMap

func (c *ReceiverData) AsMap() map[string]any

type ServiceOption

type ServiceOption func(*PluginService)

func WithHTTPClient

func WithHTTPClient(httpClient *httpclient.Client) ServiceOption

WithHTTPClient assigns custom http client when creating a slack service

func WithRetrier

func WithRetrier(runner retry.Runner) ServiceOption

WithRetrier wraps client call with retrier

func WithSlackClient

func WithSlackClient(client SlackCaller) ServiceOption

type SlackCaller

type SlackCaller interface {
	ExchangeAuth(ctx context.Context, authCode, clientID, clientSecret string) (Credential, error)
	GetWorkspaceChannels(ctx context.Context, token secret.MaskableString) ([]Channel, error)
	Notify(ctx context.Context, conf NotificationConfig, message Message) error
}

type SlackCredentialConfig

type SlackCredentialConfig struct {
	ClientID     string `mapstructure:"client_id"`
	ClientSecret string `mapstructure:"client_secret"`
	AuthCode     string `mapstructure:"auth_code"`
}

SlackCredentialConfig is config that needs to be passed when a new slack receiver is being added

func (*SlackCredentialConfig) Validate

func (c *SlackCredentialConfig) Validate() error

type SubscriptionConfig

type SubscriptionConfig struct {
	ChannelName string `json:"channel_name" mapstructure:"channel_name"`
	ChannelType string `json:"channel_type" mapstructure:"channel_type"`
}

SubscriptionConfig is a stored config for a subscription of a slack receiver

func (*SubscriptionConfig) AsMap

func (c *SubscriptionConfig) AsMap() map[string]any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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