Documentation
¶
Overview ¶
Package context provides the handler context and cross-platform message helpers.
Index ¶
- type Context
- func (c *Context) Allow(action string, limit int, window time.Duration, keyParts ...string) (bool, time.Duration)
- func (c *Context) AnswerCallback(text string) error
- func (c *Context) CallbackRoute() string
- func (c *Context) CanEdit() bool
- func (c *Context) ClearState() error
- func (c *Context) Command() string
- func (c *Context) Edit(text string, kb *keyboard.Keyboard) error
- func (c *Context) EditByRef(ref platform.MessageRef, text string, kb *keyboard.Keyboard) error
- func (c *Context) EditText(text string) error
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) Input() string
- func (c *Context) IsCallback() bool
- func (c *Context) Locale() string
- func (c *Context) Log() *slog.Logger
- func (c *Context) PlatformName() string
- func (c *Context) Send(text string, kb *keyboard.Keyboard) error
- func (c *Context) SendMessage(msg platform.OutgoingMessage) error
- func (c *Context) SendPrivate(msg platform.OutgoingMessage) error
- func (c *Context) SendText(text string) error
- func (c *Context) SendTextWithRef(text string) (platform.MessageRef, error)
- func (c *Context) SendWithAttachments(text string, kb *keyboard.Keyboard, files ...attachments.Attachment) error
- func (c *Context) Set(key string, value any)
- func (c *Context) SetLocale(locale string)
- func (c *Context) SetLocalizer(localizer Localizer, locale string)
- func (c *Context) SetState(mode string, step int, data map[string]string) error
- func (c *Context) State() (mode string, step int, data map[string]string, ok bool, err error)
- func (c *Context) T(key string, args ...map[string]any) (string, error)
- func (c *Context) Text() string
- type Localizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Context stdctx.Context
Event event.Event
Platform platform.Platform
Logger *slog.Logger
Payload *payload.Payload
Values map[string]any
// contains filtered or unexported fields
}
Context carries an event, platform adapter and request-scoped values.
func (*Context) Allow ¶
func (c *Context) Allow(action string, limit int, window time.Duration, keyParts ...string) (bool, time.Duration)
Allow uses injected rate limiter (if present) for arbitrary actions. If limiter is not injected, request is considered allowed.
func (*Context) AnswerCallback ¶
AnswerCallback acknowledges the current callback interaction.
func (*Context) CallbackRoute ¶
func (*Context) ClearState ¶
ClearState deletes FSM state for this user/chat from injected FSM manager.
func (*Context) Edit ¶
Edit tries to edit the message related to the current event. If editing is unsupported or unavailable, it falls back to Send.
func (*Context) EditByRef ¶
EditByRef tries to edit a message by an explicit message reference. If unsupported or unavailable, it falls back to Send.
func (*Context) EditText ¶
EditText tries to edit the message related to the current event. If editing is unsupported or unavailable, it falls back to SendText.
func (*Context) Input ¶
Input returns user input unified for text and callback events. For callbacks it prefers payload action, then payload route, then raw payload string.
func (*Context) IsCallback ¶
func (*Context) PlatformName ¶
func (*Context) SendMessage ¶ added in v2.0.1
func (c *Context) SendMessage(msg platform.OutgoingMessage) error
SendMessage sends a portable message to the current event target.
func (*Context) SendPrivate ¶ added in v2.0.1
func (c *Context) SendPrivate(msg platform.OutgoingMessage) error
SendPrivate sends a message only through the adapter's private-delivery capability. It never falls back to the current chat.
func (*Context) SendTextWithRef ¶
func (c *Context) SendTextWithRef(text string) (platform.MessageRef, error)
SendTextWithRef sends text and returns a reference when the adapter supports it.
func (*Context) SendWithAttachments ¶
func (c *Context) SendWithAttachments(text string, kb *keyboard.Keyboard, files ...attachments.Attachment) error
SendWithAttachments replies with text, keyboard and media attachments.
func (*Context) SetLocale ¶ added in v2.0.3
SetLocale changes the request locale while preserving the attached localizer.
func (*Context) SetLocalizer ¶ added in v2.0.3
SetLocalizer attaches request-scoped localization support.
func (*Context) State ¶
State returns current FSM state for this user/chat from injected FSM manager.