notify

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	TELEGRAM = "telegram"
	DISCORD  = "discord"
	WEBHOOK  = "webhook"
	SMTP     = "smtp"
)
View Source
const (
	/**
		Gmail SMTP Server
	**/
	SMTPServer = "smtp.gmail.com"
)

Variables

This section is empty.

Functions

func GetTgBot

func GetTgBot(ctx context.Context, option TgBotOption) *tgbotapi.BotAPI

GetTgBot get an instance of tgBot

func SendMessageDiscord

func SendMessageDiscord(ctx context.Context, discordClient DiscordClient, message string) error

SendMessageDiscord send msg to discord

func SendMessageSMTP

func SendMessageSMTP(ctx context.Context, sender *Sender, message string)

SendMessageSMTP send msg to SMTP

func SendMessageTG

func SendMessageTG(ctx context.Context, bot *tgbotapi.BotAPI, id int64, message string) error

SendMessageTG send msg to telegram

func SendMessageWebHook added in v0.4.2

func SendMessageWebHook(ctx context.Context, webhookClient WebHookClient, message string) error

SendMessageWebHook send msg to webhook

Types

type Author

type Author struct {
	Name    string `json:"name,omitempty"`
	URL     string `json:"url,omitempty"`
	IconURL string `json:"icon_url,omitempty"`
}

Author ...

type DiscordClient

type DiscordClient interface {
	// PostMessage ...
	PostMessage(ctx context.Context, message string) error
}

func NewDiscordClient

func NewDiscordClient(options DiscordClientOptions) (DiscordClient, error)

NewDiscordClient create an instance of discord client

type DiscordClientOptions

type DiscordClientOptions struct {

	// ServerHook url to use
	ServerHook string

	HttpClient *http.Client
}

DiscordClientOptions ...

type Embed

type Embed struct {
	Author      Author `json:"author,omitempty"`
	Title       string `json:"title,omitempty"`
	URL         string `json:"url,omitempty"`
	Description string `json:"description,omitempty"`
	Color       int64  `json:"color,omitempty"`
}

Embed object that define the structure of our msg

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

type Notifier

type Notifier interface {
	SendNotification(ctx context.Context, data interface{}) error
}

Notifier ...

type PayloadWebHook added in v0.4.2

type PayloadWebHook struct {
	Username string `json:"username,omitempty"`
	Content  string `json:"content,omitempty"`
	Message  string `json:"message,omitempty"`
}

func (*PayloadWebHook) ToReader added in v0.4.2

func (p *PayloadWebHook) ToReader() *strings.Reader

type PayloadWebHookDiscord

type PayloadWebHookDiscord struct {
	Username  string  `json:"username,omitempty"`
	AvatarURL string  `json:"avatar_url,omitempty"`
	Content   string  `json:"content,omitempty"`
	Embeds    []Embed `json:"embeds,omitempty"`
}

PayloadWebHookDiscord general payload to make request to discord Hook

func (*PayloadWebHookDiscord) ToReader

func (p *PayloadWebHookDiscord) ToReader() *strings.Reader

type Sender

type Sender struct {
	// User ...
	User string
	// Password
	Password string
}

Sender object it`s used to send SMTP request

func NewSender

func NewSender(Username, Password string) Sender

NewSender constructor

func (Sender) SendMail

func (sender Sender) SendMail(ctx context.Context, Dest []string, Subject, bodyMessage string)

SendMail send mail to an array of dst

func (Sender) WriteEmail

func (sender Sender) WriteEmail(dest []string, contentType, subject, bodyMessage string) string

WriteEmail an email

func (*Sender) WriteHTMLEmail

func (sender *Sender) WriteHTMLEmail(dest []string, subject, bodyMessage string) string

WriteHTMLEmail ...

func (*Sender) WritePlainEmail

func (sender *Sender) WritePlainEmail(dest []string, subject, bodyMessage string) string

WritePlainEmail ...

type TgBotOption

type TgBotOption struct {
	Debug bool
	Token string
}

TgBotOption object options for telegram service

type WebHookClient added in v0.4.2

type WebHookClient interface {
	// PostMessage ...
	PostMessage(ctx context.Context, message string) error
}

func NewWebHookClient added in v0.4.2

func NewWebHookClient(options WebHookClientOptions) (WebHookClient, error)

type WebHookClientOptions added in v0.4.2

type WebHookClientOptions struct {

	// ServerHook url to use
	ServerHook string

	HttpClient *http.Client
}

Jump to

Keyboard shortcuts

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