Documentation ¶
Index ¶
- func ReceiverForceServe(start bool) tReceiverParam
- func ReceiverMultiExecutors(n ...int) tReceiverParam
- func ReceiverSingleExecutor() tReceiverParam
- type Receiver
- func (r *Receiver) Button(what string, when ...session.TStep) *tReger
- func (r *Receiver) Buttons(what []string, when ...session.TStep) *tReger
- func (r *Receiver) Command(what string, when ...session.TStep) *tReger
- func (r *Receiver) Commands(what []string, when ...session.TStep) *tReger
- func (r *Receiver) ExtendContext(extender interface{}) error
- func (r *Receiver) ExtendContext2(f func(c *Ctx) unsafe.Pointer)
- func (r *Receiver) InlineButton(what session.Action, when ...session.TStep) *tReger
- func (r *Receiver) InlineButtons(what []session.Action, when ...session.TStep) *tReger
- func (r *Receiver) PushUpdate()
- func (r *Receiver) Serve() error
- func (r *Receiver) Text(when ...session.TStep) *tReger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReceiverForceServe ¶
func ReceiverForceServe(start bool) tReceiverParam
func ReceiverMultiExecutors ¶
func ReceiverMultiExecutors(n ...int) tReceiverParam
n must be in the range [0..16]
func ReceiverSingleExecutor ¶
func ReceiverSingleExecutor() tReceiverParam
Types ¶
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
-- Receiver -- 'Receiver' is the part of Telegram TBot UIG Framework. 'Receiver' is engaged is receiving incoming messages as bot updates, converting updates to the context objects, if it's possible, and calls the registered middlewares and handlers.
'Receiver' must be created by 'NewReceiver' function directly (way to specify some 'Receiver' options) or by internal 'TBot' constructor.
As object, 'Receiver' contains logger pointer, bot pointer, updates channel (to which the Telegram TBot updates are coming), map of registered handlers (specified for event types), map of registered middlewares (specified for event types), general handlers and middlewares (if special handlers or middlewares aren't registered) and executor's channel. See 'tEventType', 'tHandlerCallback', 'tMiddlewareCallback' types for details, it's important to understand how it works and what is it.
How it works. 1. Telegram sends update to the bot server. TBot server receives that update and creates 'tgbotapi.Update' object by that update. 2. Receiver takes each such update object and tries to find executors for it (registered handlers). 2.1. Before that, Receiver tries to construct Event object that will contain info about event of received update. That object will contain info "what kind of event" and "what is body of event". 3. Then Receiver tries to create context object for received update. (See 'TCtx' type for details). That object will be passed to the registered middlewares and handlers. 4. Receiver performs all middleware checks for created context object. If middlewares allowed the next processing, the context object wraps in 'tExecutor' object, that will contain context object and all executors which must be called for that context object. 5. Receiver pass 'tExecutor' object to the executor's channel and some free executor goroutine will take it from channel and execute it.
What is the middleware? Middleware is the special callback that can be registered for any event, takes context object as argument and must return true or false. So, when any event received from Telegram servers, and if middleware registered for that event, the middleware(s) will be called before handler(s). If at least one of middlewares returns 'false' no one next of middlewares and handlers will be called! Thus with middlewares you can manage calls of handlers. Keep in mind, that all middlewares executes in one goroutine for each events, and should not be too algorithmically complex, otherwise the perfomance may decline.
func (*Receiver) ExtendContext ¶
func (*Receiver) ExtendContext2 ¶
func (*Receiver) InlineButton ¶
func (r *Receiver) InlineButton( what session.Action, when ...session.TStep, ) *tReger
'InlineButton' the same as 'tReger.InlineButton'.
func (*Receiver) InlineButtons ¶
func (r *Receiver) InlineButtons( what []session.Action, when ...session.TStep, ) *tReger
'InlineButtons' the same as 'tReger.InlineButtons'.
func (*Receiver) PushUpdate ¶
func (r *Receiver) PushUpdate()