context

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: GPL-3.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package context provides the handler context and cross-platform message helpers.

Index

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

func (c *Context) AnswerCallback(text string) error

AnswerCallback acknowledges the current callback interaction.

func (*Context) CallbackRoute

func (c *Context) CallbackRoute() string

func (*Context) CanEdit

func (c *Context) CanEdit() bool

func (*Context) ClearState

func (c *Context) ClearState() error

ClearState deletes FSM state for this user/chat from injected FSM manager.

func (*Context) Command

func (c *Context) Command() string

func (*Context) Edit

func (c *Context) Edit(text string, kb *keyboard.Keyboard) error

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

func (c *Context) EditByRef(ref platform.MessageRef, text string, kb *keyboard.Keyboard) error

EditByRef tries to edit a message by an explicit message reference. If unsupported or unavailable, it falls back to Send.

func (*Context) EditText

func (c *Context) EditText(text string) error

EditText tries to edit the message related to the current event. If editing is unsupported or unavailable, it falls back to SendText.

func (*Context) Get

func (c *Context) Get(key string) (any, bool)

func (*Context) Input

func (c *Context) Input() string

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 (c *Context) IsCallback() bool

func (*Context) Locale added in v2.0.3

func (c *Context) Locale() string

Locale returns the locale selected for this request.

func (*Context) Log

func (c *Context) Log() *slog.Logger

Log returns the event-scoped logger or slog.Default when none was injected.

func (*Context) PlatformName

func (c *Context) PlatformName() string

func (*Context) Send

func (c *Context) Send(text string, kb *keyboard.Keyboard) error

Send replies with text and an optional keyboard.

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) SendText

func (c *Context) SendText(text string) error

SendText replies to the current event with text.

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) Set

func (c *Context) Set(key string, value any)

func (*Context) SetLocale added in v2.0.3

func (c *Context) SetLocale(locale string)

SetLocale changes the request locale while preserving the attached localizer.

func (*Context) SetLocalizer added in v2.0.3

func (c *Context) SetLocalizer(localizer Localizer, locale string)

SetLocalizer attaches request-scoped localization support.

func (*Context) SetState

func (c *Context) SetState(mode string, step int, data map[string]string) error

SetState writes FSM state for this user/chat to injected FSM manager.

func (*Context) State

func (c *Context) State() (mode string, step int, data map[string]string, ok bool, err error)

State returns current FSM state for this user/chat from injected FSM manager.

func (*Context) T added in v2.0.3

func (c *Context) T(key string, args ...map[string]any) (string, error)

T translates key using the request locale. It accepts zero or one argument map.

func (*Context) Text

func (c *Context) Text() string

type Localizer added in v2.0.3

type Localizer interface {
	Translate(locale, key string, args map[string]any) (string, error)
}

Localizer is the implementation-neutral translation contract used by Context.T.

Jump to

Keyboard shortcuts

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