telega/context
The per-update context every handler receives.
A Context is built by the chat instance for each update and dropped once
the update is handled. It carries the update, the session loaded for this
chat, the injected dependencies, the API configuration and a
Scope for per-update scratch state. Handlers return a
(possibly updated) Context; bot.next_session is how a handler changes
the session it will hand back.
bot.Context is the same type under its historical name.
Types
pub type Context(session, error, dependencies) {
Context(
key: String,
update: update.Update,
config: @internal Config,
session: session,
dependencies: dependencies,
log_prefix: option.Option(String),
bot_info: types.User,
scope: scope.Scope,
)
}
Constructors
-
Context( key: String, update: update.Update, config: @internal Config, session: session, dependencies: dependencies, log_prefix: option.Option(String), bot_info: types.User, scope: scope.Scope, )Arguments
- key
-
The session key this update was routed under (
telega.with_session_key). - dependencies
-
Non-persisted services injected at bot init (a db pool, an http client, an i18n catalog). Unlike
session, never persisted. Seetelega.with_dependencies. - log_prefix
-
Prefix
telega.log_info/log_errorput in front of their messages; set bytelega.log_context. - scope
-
Scratch space for this update, shared by every copy of the context and dropped once the update is handled. Where the dialog engine keeps its “callback already answered” flag and its widget stash, where a pre-handler’s annotations land, and where a middleware can hand a resolved locale to handlers nested below it. See
telega/scope.
Values
pub fn new(
key key: String,
update update: update.Update,
config config: @internal Config,
session session: session,
dependencies dependencies: dependencies,
bot_info bot_info: types.User,
) -> Context(session, error, dependencies)
A fresh context for one update, with an empty scope.