channels

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelTypeCallback = "callback" // send message to callback url
	ChannelTypeDingtalk = "dingtalk" // send message to Dingtalk url
	ChannelTypeFlock    = "flock"    // send message to Flock
	ChannelTypePrint    = "print"    // write message to writer
	ChannelTypeSlack    = "slack"    // send message to Slack
	ChannelTypeTelegram = "telegram" // send message to Telegram
)
View Source
const (
	// PrintWriterStdout writes output to stdout
	PrintWriterStdout = "stdout"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel interface {
	// NewEventProcessContext builds a new copy of data to process for an event,
	// for example, NewEventProcessContext returns []chatID in Telegram channel,
	// if any error occurs and the processing is retried,
	// the channel can know which chatIDs have already been noticed successfully.
	NewEventProcessContext(e *event.Event) *EventProcessContext

	// Handle handles an event
	Handle(ctx *EventProcessContext) error
}

Channel is interface of a channel

type ChannelCallback

type ChannelCallback struct {
	Client      *http.Client
	Method      string
	URL         string
	UseTemplate bool
	TmplAdded   *template.Template
	TmplDeleted *template.Template
	TmplUpdated *template.Template
}

ChannelCallback is the callback channel

func NewChannelCallback

func NewChannelCallback(config *ChannelCallbackConfig) (*ChannelCallback, error)

NewChannelCallback creates callback channel

func (*ChannelCallback) Handle

func (c *ChannelCallback) Handle(ctx *EventProcessContext) error

Handle implements Channel

func (*ChannelCallback) NewEventProcessContext

func (c *ChannelCallback) NewEventProcessContext(e *event.Event) *EventProcessContext

NewEventProcessContext implements Channel

type ChannelCallbackConfig

type ChannelCallbackConfig struct {
	Method          string
	URL             string
	Proxy           string
	UseTemplate     bool
	AddedTemplate   string
	DeletedTemplate string
	UpdatedTemplate string
}

ChannelCallbackConfig is config for ChannelCallback

type ChannelDingtalk

type ChannelDingtalk struct {
	Client      *http.Client
	WebhookURL  string
	AtMobiles   []string
	AtAll       bool
	TmplAdded   *template.Template
	TmplDeleted *template.Template
	TmplUpdated *template.Template
}

ChannelDingtalk is the callback channel

func NewChannelDingtalk

func NewChannelDingtalk(config *ChannelDingtalkConfig) (*ChannelDingtalk, error)

NewChannelDingtalk creates callback channel

func (*ChannelDingtalk) Handle

func (c *ChannelDingtalk) Handle(ctx *EventProcessContext) error

Handle implements Channel

func (*ChannelDingtalk) NewEventProcessContext

func (c *ChannelDingtalk) NewEventProcessContext(e *event.Event) *EventProcessContext

NewEventProcessContext implements Channel

type ChannelDingtalkConfig

type ChannelDingtalkConfig struct {
	WebhookURL      string
	Proxy           string
	AtMobiles       []string
	AtAll           bool
	AddedTemplate   string
	DeletedTemplate string
	UpdatedTemplate string
}

ChannelDingtalkConfig is config for ChannelDingtalk

type ChannelFlock

type ChannelFlock struct {
	Client      *http.Client
	URL         string
	TmplTitle   *template.Template
	TmplAdded   *template.Template
	TmplDeleted *template.Template
	TmplUpdated *template.Template
}

ChannelFlock is the callback channel

func NewChannelFlock

func NewChannelFlock(config *ChannelFlockConfig) (*ChannelFlock, error)

NewChannelFlock creates callback channel

func (*ChannelFlock) Handle

func (c *ChannelFlock) Handle(ctx *EventProcessContext) error

Handle implements Channel

func (*ChannelFlock) NewEventProcessContext

func (c *ChannelFlock) NewEventProcessContext(e *event.Event) *EventProcessContext

NewEventProcessContext implements Channel

type ChannelFlockConfig

type ChannelFlockConfig struct {
	URL             string
	Proxy           string
	TitleTemplate   string
	AddedTemplate   string
	DeletedTemplate string
	UpdatedTemplate string
}

ChannelFlockConfig is config for ChannelFlock

type ChannelMap

type ChannelMap map[ChannelName]Channel

ChannelMap maps from ChannelName to Channel

type ChannelName

type ChannelName string

ChannelName is name of channel

type ChannelPrint

type ChannelPrint struct {
	Writer      io.Writer
	IsStdout    bool
	UseTemplate bool
	TmplAdded   *template.Template
	TmplDeleted *template.Template
	TmplUpdated *template.Template
}

ChannelPrint is the channel to print event to writer

func NewChannelPrint

func NewChannelPrint(config *ChannelPrintConfig) (*ChannelPrint, error)

NewChannelPrint creates print channel

func (*ChannelPrint) Handle

func (c *ChannelPrint) Handle(ctx *EventProcessContext) error

Handle implements Channel

func (*ChannelPrint) NewEventProcessContext

func (c *ChannelPrint) NewEventProcessContext(e *event.Event) *EventProcessContext

NewEventProcessContext implements Channel

type ChannelPrintConfig

type ChannelPrintConfig struct {
	Writer          string
	UseTemplate     bool
	AddedTemplate   string
	DeletedTemplate string
	UpdatedTemplate string
}

ChannelPrintConfig is config for ChannelPrint

type ChannelSlack

type ChannelSlack struct {
	Client      *slack.Client // TODO: add Slack app support (not only webhooks)
	WebhookURL  string
	TmplTitle   *template.Template
	TmplAdded   *template.Template
	TmplDeleted *template.Template
	TmplUpdated *template.Template
}

ChannelSlack is the callback channel

func NewChannelSlack

func NewChannelSlack(config *ChannelSlackConfig) (*ChannelSlack, error)

NewChannelSlack creates callback channel

func (*ChannelSlack) Handle

func (c *ChannelSlack) Handle(ctx *EventProcessContext) error

Handle implements Channel ref: https://api.slack.com/apps

func (*ChannelSlack) NewEventProcessContext

func (c *ChannelSlack) NewEventProcessContext(e *event.Event) *EventProcessContext

NewEventProcessContext implements Channel

type ChannelSlackConfig

type ChannelSlackConfig struct {
	Token           string
	Proxy           string
	WebhookURL      string
	TitleTemplate   string
	AddedTemplate   string
	DeletedTemplate string
	UpdatedTemplate string
}

ChannelSlackConfig is config for ChannelSlack

type ChannelTelegram

type ChannelTelegram struct {
	Client      *http.Client
	Token       string
	ChatIDs     []string
	TmplAdded   *template.Template
	TmplDeleted *template.Template
	TmplUpdated *template.Template
}

ChannelTelegram is the Telegram channel

func NewChannelTelegram

func NewChannelTelegram(config *ChannelTelegramConfig) (*ChannelTelegram, error)

NewChannelTelegram creates new Telegram channel

func (*ChannelTelegram) Handle

func (c *ChannelTelegram) Handle(ctx *EventProcessContext) error

Handle implements Channel

func (*ChannelTelegram) NewEventProcessContext

func (c *ChannelTelegram) NewEventProcessContext(e *event.Event) *EventProcessContext

NewEventProcessContext implements Channel

type ChannelTelegramConfig

type ChannelTelegramConfig struct {
	Token           string
	ChatIDs         []string
	Proxy           string
	AddedTemplate   string
	DeletedTemplate string
	UpdatedTemplate string
}

ChannelTelegramConfig is config for ChannelTelegram

type ChannelType

type ChannelType string

ChannelType is type of channel

type DingtalkMessage

type DingtalkMessage struct {
	At      DingtalkMessageAt   `json:"at"`
	Text    DingtalkMessageText `json:"text"`
	Msgtype string              `json:"msgtype"`
}

DingtalkMessage represents a Dingtalk message ref: https://developers.dingtalk.com/document/app/custom-robot-access

type DingtalkMessageAt

type DingtalkMessageAt struct {
	AtMobiles []string `json:"atMobiles"`
	AtUserIds []string `json:"atUserIds"`
	IsAtAll   bool     `json:"isAtAll"`
}

DingtalkMessageAt represents a Dingtalk message at (@) info

type DingtalkMessageText

type DingtalkMessageText struct {
	Content string `json:"content"`
}

DingtalkMessageText represents a Dingtalk message text

type EventProcessContext

type EventProcessContext struct {
	Event *event.Event

	// Data is the context data used by a channel during processing an event,
	// for example, Telegram channel stores []chatID in Data,
	// chatID are deleted from the slice once message send successfully,
	// if any error occurs and the processing is retried,
	// it can know which chatIDs have already been noticed successfully.
	Data interface{}
}

EventProcessContext is the context of an event processing within a channel

type FlockMessage

type FlockMessage struct {
	Notification string                   `json:"notification"`
	Text         string                   `json:"text"`
	Attachments  []FlockMessageAttachment `json:"attachments"`
}

FlockMessage represents a flock message ref: https://docs.flock.com/display/flockos/Message

type FlockMessageAttachment

type FlockMessageAttachment struct {
	Title string `json:"title"`
	Color string `json:"color"`
}

FlockMessageAttachment represents a flock message attachment ref: https://docs.flock.com/display/flockos/Attachment

type TelegramMessage

type TelegramMessage struct {
	ChatID string `json:"chat_id"`
	Text   string `json:"text"`
}

TelegramMessage represents a Telegram message

Jump to

Keyboard shortcuts

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