tgbot

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BotListenerAction

func BotListenerAction(ctx context.Context, runner *runners.Runner) error

func BotPublisherAction

func BotPublisherAction(ctx context.Context, runner *runners.Runner) error

func BotWorkerRunnerAction

func BotWorkerRunnerAction(ctx context.Context, runner *runners.Runner) error

func CreateBotContext

func CreateBotContext(svc *GoTGBotService) (ctx context.Context, cancel context.CancelFunc)

func Has

func Has(b, flag SetupLevel) bool

Types

type BotListener

type BotListener struct {
	BotRunner
	// contains filtered or unexported fields
}

func (*BotListener) AddCallbackHandler added in v0.0.3

func (lst *BotListener) AddCallbackHandler(title string, filter func(update tgbotapi.Update) bool, handler ListenerHandlerFunc)

func (*BotListener) AddCommandHandler

func (lst *BotListener) AddCommandHandler(title string, command string, handler ListenerHandlerFunc)

func (*BotListener) AddHandler

func (lst *BotListener) AddHandler(title string, filter func(update tgbotapi.Update) bool, handler func(ctx context.Context, update tgbotapi.Update) error)

func (*BotListener) SetupCommandsMessage

func (lst *BotListener) SetupCommandsMessage() (msg tgbotapi.SetMyCommandsConfig, err error)

type BotPublisher

type BotPublisher struct {
	BotRunner
	// contains filtered or unexported fields
}

func (*BotPublisher) Publish

func (pbx *BotPublisher) Publish(message tgbotapi.Chattable)

func (*BotPublisher) ReplyToMessage

func (pbx *BotPublisher) ReplyToMessage(update tgbotapi.Update, text string)

func (*BotPublisher) SendHTMLMessage

func (pbx *BotPublisher) SendHTMLMessage(chatID int64, htmlMessage string)

func (*BotPublisher) SendInlineKeyboard

func (pbx *BotPublisher) SendInlineKeyboard(chatID int64, text string, keyboardOptions ...string)

func (*BotPublisher) SendMenuKeyboard added in v0.0.3

func (pbx *BotPublisher) SendMenuKeyboard(chatID int64, caption string, baseCommand string, keyboardOptions ...string)

SendMenuKeyboard sends a menu keyboard to the given chatID. caption is the caption of the menu. baseCommand is the command handler name that will be called when the user selects an option. keyboardOptions is a list of options. Each option is in format "Title:data". You can use "-" to separate options in a row.

func (*BotPublisher) SendTextMessage

func (pbx *BotPublisher) SendTextMessage(chatID int64, text string)

type BotRunner

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

func (*BotRunner) Init

func (runner *BotRunner) Init(name string)

func (*BotRunner) String

func (runner *BotRunner) String() string

type BotWorker

type BotWorker struct {
	BotRunner
	// contains filtered or unexported fields
}

func (*BotWorker) AddSchedule

func (wrk *BotWorker) AddSchedule(schedule *sch.Schedule)

type BotWorkerAction

type BotWorkerAction func(ctx context.Context) error

type GoTGBotService

type GoTGBotService struct {
	BotRunner
	// contains filtered or unexported fields
}

func CreateBotService

func CreateBotService() *GoTGBotService

CreateBotService creates a new empty bot service This is the first step to create a bot service

After this step, you should:

* LoadConfigurationFromFile or LoadConfigurationFromEnv

* InitBot

* AddRepository (optional, if not set, automatic repository will be created)

func GetBotService

func GetBotService(ctx context.Context) *GoTGBotService

func (*GoTGBotService) AddCallbackHandlers added in v0.0.3

func (svc *GoTGBotService) AddCallbackHandlers(handlers ...*ListenerCallbackHandler) *GoTGBotService

func (*GoTGBotService) AddCommandHandlers

func (svc *GoTGBotService) AddCommandHandlers(handlers ...*ListenerCommandHandler) *GoTGBotService

func (*GoTGBotService) AddHandlers

func (svc *GoTGBotService) AddHandlers(handlers ...*ListenerFilteredHandler) *GoTGBotService

func (*GoTGBotService) Configuration

func (svc *GoTGBotService) Configuration() *config.Configuration

func (*GoTGBotService) InitBot

func (svc *GoTGBotService) InitBot() *GoTGBotService

InitBot setups bot, loggin

func (*GoTGBotService) Listener

func (svc *GoTGBotService) Listener() *BotListener

func (*GoTGBotService) LoadConfigurationFromEnv

func (svc *GoTGBotService) LoadConfigurationFromEnv(prefix string) *GoTGBotService

func (*GoTGBotService) LoadConfigurationFromFile

func (svc *GoTGBotService) LoadConfigurationFromFile(filename string) *GoTGBotService

func (*GoTGBotService) Publisher

func (svc *GoTGBotService) Publisher() *BotPublisher

func (*GoTGBotService) Repository

func (svc *GoTGBotService) Repository() IRepository

func (*GoTGBotService) SetDatabase

func (svc *GoTGBotService) SetDatabase(dbs ...*gorm.DB) *GoTGBotService

SetDatabase sets the database for the bot repository

If not set, the bot repository will be created with the default connection string

func (*GoTGBotService) SetRepository

func (svc *GoTGBotService) SetRepository(repository IRepository) *GoTGBotService

SetRepository sets the repository for the bot

You must implement a IRepository interface and pass it to this method

Do not need to use SetDatabase

func (*GoTGBotService) SetupBackgroundRunOnceSchedules

func (svc *GoTGBotService) SetupBackgroundRunOnceSchedules(schedules ...*schedules.Schedule) *GoTGBotService

func (*GoTGBotService) SetupBackgroundSchedules

func (svc *GoTGBotService) SetupBackgroundSchedules(schedules ...*schedules.Schedule) *GoTGBotService

func (*GoTGBotService) Start

func (svc *GoTGBotService) Start() error

func (*GoTGBotService) Stop

func (svc *GoTGBotService) Stop() error

type IRepository

type IRepository interface {
	Save(*infra.Message) error
	GetChats() ([]*infra.Chat, error)
	SaveChat(chat *tgbotapi.Chat) error
	SaveMessage(message *tgbotapi.Message) error
	HouseKeeping(maxAge time.Duration) error
}

type ListenerCallbackHandler added in v0.0.3

type ListenerCallbackHandler struct {
	Title  string
	Filter ListenerFilter
	Func   ListenerHandlerFunc
}

func CreateListenerCallbackHandler added in v0.0.3

func CreateListenerCallbackHandler(title string, command string, handlerFunc ListenerHandlerFunc) *ListenerCallbackHandler

type ListenerCommandHandler

type ListenerCommandHandler struct {
	Command     string
	Title       string
	Func        ListenerHandlerFunc
	SubCommands []*ListenerCommandHandler
}

type ListenerFilter

type ListenerFilter = func(tgbotapi.Update) bool

ListenerFilter is the filter for messages received by the bot. If the filter returns true, the message will be handled by the handler.

type ListenerFilteredHandler

type ListenerFilteredHandler struct {
	Command string
	Title   string
	Func    ListenerHandlerFunc
	Filter  ListenerFilter
}

type ListenerHandlerFunc

type ListenerHandlerFunc = func(context.Context, tgbotapi.Update) error

ListenerHandlerFunc is the handler for messages received by the bot.

type SetupLevel

type SetupLevel uint8
const (
	Empty SetupLevel = 1 << iota
	Instance
	Configuration
	Init
	Workers
	Repository
	Handlers
)

func Clear

func Clear(b, flag SetupLevel) SetupLevel

func Set

func Set(b, flag SetupLevel) SetupLevel

func Toggle

func Toggle(b, flag SetupLevel) SetupLevel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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