lark

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 15 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 Action

type Action struct {
	Tag  string `json:"tag"`
	Text Text   `json:"text"`
	Type string `json:"type"`
	URL  string `json:"url"`
}

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 CardElement

type CardElement struct {
	Title   string   `json:"title,omitempty"`
	Pretext string   `json:"pretext,omitempty"`
	Text    string   `json:"text,omitempty"`
	Actions []Action `json:"actions,omitempty"`
}

func (CardElement) ToLark

func (ma CardElement) ToLark() (*CardElement, error)

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 lark client. this version uses lark v3 SDK.

func (*Client) GetWorkspaceChannels

func (c *Client) GetWorkspaceChannels(ctx context.Context, clientID, clientSecret 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 lark client

func ClientWithRetrier

func ClientWithRetrier(runner retry.Runner) ClientOption

ClientWithRetrier wraps client call with retrier

type Config

type Config struct {
	WideScreenMode bool `json:"wide_screen_mode"`
}

type Element

type Element struct {
	Tag     string   `json:"tag"`
	Text    Text     `json:"text,omitempty"`
	Actions []Action `json:"actions,omitempty"`
}

type Encryptor

type Encryptor interface {
	Encrypt(str secret.MaskableString) (secret.MaskableString, error)
	Decrypt(str secret.MaskableString) (secret.MaskableString, error)
}
type Header struct {
	Template string `json:"template"`
	Title    Text   `json:"title"`
}

type LarkCaller

type LarkCaller interface {
	GetWorkspaceChannels(ctx context.Context, clientID, clientSecret secret.MaskableString) ([]Channel, error)
	Notify(ctx context.Context, conf NotificationConfig, message Message) error
}

type LarkCredentialConfig

type LarkCredentialConfig struct {
	ClientID     string `mapstructure:"client_id"`
	ClientSecret string `mapstructure:"client_secret"`
}

LarkCredentialConfig is config that needs to be passed when a new lark receiver is being added

func (*LarkCredentialConfig) Validate

func (c *LarkCredentialConfig) Validate() error

type Message

type Message struct {
	Color     string        `yaml:"templatecolor,omitempty" json:"templatecolor,omitempty"  mapstructure:"templatecolor"`
	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"`
	Elements  []CardElement `yaml:"elements,omitempty" json:"attachments,omitempty" mapstructure:"elements"`
}

func (Message) BuildLarkMessage

func (m Message) BuildLarkMessage() (string, error)

type MessageCard

type MessageCard struct {
	Config   Config    `json:"config"`
	Elements []Element `json:"elements"`
	Header   Header    `json:"header"`
}

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 lark

func NewPluginService

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

NewPluginService returns lark 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, notificationConfigMap map[string]any) (map[string]any, error)

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, configurations 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 {
	ClientID     secret.MaskableString `mapstructure:"client_id"`
	ClientSecret secret.MaskableString `mapstructure:"client_secret"`
}

ReceiverConfig is a stored config for a lark 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 lark 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 lark service

func WithLarkClient

func WithLarkClient(client LarkCaller) ServiceOption

func WithRetrier

func WithRetrier(runner retry.Runner) ServiceOption

WithRetrier wraps client call with retrier

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 lark receiver

func (*SubscriptionConfig) AsMap

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

type Text

type Text struct {
	Content string `json:"content"`
	Tag     string `json:"tag"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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