Documentation
¶
Index ¶
- Constants
- Variables
- type Context
- type Dispatcher
- func (d *Dispatcher) AddHandler(handler Handler)
- func (d *Dispatcher) AddHandlerToGroup(handler Handler, group int)
- func (d *Dispatcher) ProcessRawUpdate(b *gotgbot.Bot, r json.RawMessage)
- func (d *Dispatcher) ProcessUpdate(b *gotgbot.Bot, update *gotgbot.Update)
- func (d *Dispatcher) Start(b *gotgbot.Bot)
- func (d *Dispatcher) Stop()
- type DispatcherOpts
- type Handler
- type PollingOpts
- type Updater
- type UpdaterOpts
- type WebhookOpts
Constants ¶
const DefaultMaxRoutines = 50
Variables ¶
var ContinueGroups = errors.New("group iteration continued")
var EndGroups = errors.New("group iteration ended")
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Bot *gotgbot.Bot Update *gotgbot.Update Data map[string]string EffectiveMessage *gotgbot.Message EffectiveChat *gotgbot.Chat EffectiveUser *gotgbot.User }
TODO: extend to be used as a generic cancel context
func NewContext ¶
func NewContext(b *gotgbot.Bot, update *gotgbot.Update) *Context
type Dispatcher ¶
type Dispatcher struct { // Error handles any errors that occur during handler execution. Error func(ctx *Context, err error) // Panic handles any panics that occur during handler execution. // If this field is nil, the stack is logged to stderr. Panic func(ctx *Context, stack []byte) // ErrorLog is the output to log to in the case of a library error. ErrorLog *log.Logger // contains filtered or unexported fields }
func NewDispatcher ¶
func NewDispatcher(updates chan json.RawMessage, opts *DispatcherOpts) *Dispatcher
NewDispatcher creates a new dispatcher, which process and handles incoming updates from the updates channel.
func (*Dispatcher) AddHandler ¶
func (d *Dispatcher) AddHandler(handler Handler)
AddHandler adds a new handler to the dispatcher. The dispatcher will call CheckUpdate() to see whether the handler should be executed, and then HandleUpdate() to execute it.
func (*Dispatcher) AddHandlerToGroup ¶
func (d *Dispatcher) AddHandlerToGroup(handler Handler, group int)
AddHandlerToGroup adds a handler to a specific group; lowest number will be processed first.
func (*Dispatcher) ProcessRawUpdate ¶
func (d *Dispatcher) ProcessRawUpdate(b *gotgbot.Bot, r json.RawMessage)
func (*Dispatcher) ProcessUpdate ¶
func (d *Dispatcher) ProcessUpdate(b *gotgbot.Bot, update *gotgbot.Update)
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start(b *gotgbot.Bot)
Start to handle incoming updates
func (*Dispatcher) Stop ¶
func (d *Dispatcher) Stop()
Stop waits for all currently processing updates to finish, and then returns.
type DispatcherOpts ¶
type DispatcherOpts struct { // Error handles any errors that occur during handler execution. Error func(ctx *Context, err error) // Panic handles any panics that occur during handler execution. // If no panic is defined, the stack is logged to Panic func(ctx *Context, stack []byte) // MaxRoutines is used to decide how to limit the number of goroutines spawned by the dispatcher. // If MaxRoutines == 0, DefaultMaxRoutines is used instead. // If MaxRoutines < 0, no limits are imposed. MaxRoutines int ErrorLog *log.Logger }
type Handler ¶
type Handler interface { // CheckUpdate checks whether the update should handled by this handler. CheckUpdate(b *gotgbot.Bot, u *gotgbot.Update) bool // HandleUpdate processes the update. HandleUpdate(ctx *Context) error // Name gets the handler name; used to differentiate handlers programmatically. Names should be unique. Name() string }
type PollingOpts ¶
type PollingOpts struct { Clean bool GetUpdatesOpts gotgbot.GetUpdatesOpts }
type Updater ¶
type Updater struct { Bot gotgbot.Bot Dispatcher *Dispatcher UpdateChan chan json.RawMessage ErrorLog *log.Logger // contains filtered or unexported fields }
func NewUpdater ¶
func NewUpdater(bot *gotgbot.Bot, opts *UpdaterOpts) Updater
NewUpdater Creates a new Updater, as well as the necessary structures for
func (*Updater) Idle ¶
func (u *Updater) Idle()
Idle starts an infinite loop to avoid the program exciting while the background threads handle updates.
func (*Updater) StartPolling ¶
func (u *Updater) StartPolling(b *gotgbot.Bot, opts *PollingOpts) error
StartPolling Starts the polling logic
func (*Updater) StartWebhook ¶
func (u *Updater) StartWebhook(b *gotgbot.Bot, opts WebhookOpts) error
StartWebhook Starts the webhook server with the relevant settings (ie, TLS or not)
type UpdaterOpts ¶
type UpdaterOpts struct { PollingTimeout time.Duration ErrorLog *log.Logger DispatcherOpts DispatcherOpts }
type WebhookOpts ¶
func (*WebhookOpts) GetListenAddr ¶
func (w *WebhookOpts) GetListenAddr() string
GetListenAddr returns the local listening address, including port.
func (*WebhookOpts) GetWebhookURL ¶
func (w *WebhookOpts) GetWebhookURL(domain string) string
GetWebhookURL returns the domain in the form domain/path. eg: example.com/super_secret_token