sending

package
v0.0.0-...-d086b3f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotifyDevChatOnFinish

func NotifyDevChatOnFinish(chatID int64) func(*SenderWithBots)

DefaultAfterFinishEachHook notifies about mailing finish to dev chat for each bot

func NotifyDevChatOnFinishEach

func NotifyDevChatOnFinishEach(chatID int64) func(*Mailing)

NotifyDevChatOnFinishEach notifies about mailing finish to dev chat for each bot

func NotifyDevChatOnStart

func NotifyDevChatOnStart(chatID int64) func(*SenderWithBots)

NotifyDevChatOnStart notifies about mailing start to dev chat

Types

type AdProvider

type AdProvider interface {
	GetScheduledAd(year, month, day int) (dto.ScheduledAd, error)
}

type BotsProvider

type BotsProvider interface {
	GetBots() ([]dto.Bot, error)
}

BotsProvider is created for fetching bots which will send mailing

type ChatsProvider

type ChatsProvider interface {
	GetChatsForBot(botID int) ([]dto.Chat, error)
}

type DataFetcher

type DataFetcher interface {
	ChatsProvider
	AdProvider
}

type Mailing

type Mailing struct {
	Statistics  dto.Statistics `json:"statistics"`
	ServiceChat dto.Chat

	// Hooks
	AfterStart  func(*Mailing) `json:"-"`
	AfterFinish func(*Mailing) `json:"-"`

	Bot     *tb.Bot         `json:"-"`       // telegram client
	Chats   []dto.Chat      `json:"chats"`   // list of chats to send post
	Retries []dto.Chat      `json:"retries"` // list of chats which did not recieve the post due to rate limits
	Post    dto.ScheduledAd `json:"post"`    // the post to send
	// contains filtered or unexported fields
}

func New

func New(bot dto.Bot, chatsFetcher ChatsProvider, adFetcher AdProvider, svcChat dto.Chat) (*Mailing, error)

New returns new instance of mailing

One instance works for one bot. The function sets up telegram client, fetches the ad post and list of chats, and uploads media to telegram cloud if needed.

func (*Mailing) SetAfterFinishHook

func (m *Mailing) SetAfterFinishHook(f func(*Mailing)) *Mailing

SetAfterFinishHook sets the function which will be executed after mailing finish

func (*Mailing) SetAfterStartHook

func (m *Mailing) SetAfterStartHook(f func(*Mailing)) *Mailing

SetAfterStartHook sets the function which will be executed after mailing start

func (*Mailing) Start

func (m *Mailing) Start(stop chan struct{})

Start starts sending post to all chats

type SenderWithBots

type SenderWithBots struct {
	ID int64 `json:"id"`

	// Hooks
	AfterStart      func(*SenderWithBots) `json:"-"`
	AfterFinish     func(*SenderWithBots) `json:"-"`
	AfterStartEach  func(*Mailing)        `json:"-"`
	AfterFinishEach func(*Mailing)        `json:"-"`

	Mailings  []*Mailing `json:"mailings"`
	StartTime time.Time  `json:"start_time"`

	BotsProvider BotsProvider  `json:"-"`
	ChatsFetcher ChatsProvider `json:"-"`
	AdFetcher    AdProvider    `json:"-"`
	ServiceChat  dto.Chat      `json:"service_chat"`
}

SenderWithBots sends mailing via multiple bots

func NewSenderWithBots

func NewSenderWithBots(botsProvider BotsProvider, chatsFetcher ChatsProvider, adFetcher AdProvider) *SenderWithBots

NewSenderWithBots returns new instance of mailing sender for multiple bots

func (*SenderWithBots) Run

func (s *SenderWithBots) Run() error

Run starts the mailing. Stops when all bots complete its mailings.

func (*SenderWithBots) SetAfterFinishEachHook

func (s *SenderWithBots) SetAfterFinishEachHook(f func(*Mailing)) *SenderWithBots

SetAfterFinishEachHook sets the function which will be executed after mailing finish for each bot

func (*SenderWithBots) SetAfterFinishHook

func (s *SenderWithBots) SetAfterFinishHook(f func(*SenderWithBots)) *SenderWithBots

SetAfterFinishHook sets the function which will be executed after mailing finish

func (*SenderWithBots) SetAfterStartEachHook

func (s *SenderWithBots) SetAfterStartEachHook(f func(*Mailing)) *SenderWithBots

SetAfterStartEachHook sets the function which will be executed after mailing start for each bot

func (*SenderWithBots) SetAfterStartHook

func (s *SenderWithBots) SetAfterStartHook(f func(*SenderWithBots)) *SenderWithBots

SetAfterStartHook sets the function which will be executed after mailing start

func (*SenderWithBots) SetServiceChat

func (s *SenderWithBots) SetServiceChat(chatID int64) *SenderWithBots

SetServiceChat sets the chat which will be used to upload files

func (*SenderWithBots) Statistics

func (s *SenderWithBots) Statistics() dto.MultipleBotsStatistics

Statistics returns mailing metrics

Jump to

Keyboard shortcuts

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