cbdata

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Key = "callbackData"

handlers.Data key for unpacked callback data

Variables

View Source
var ErrInvalidPrefix = errors.New("invalid prefix")

Functions

func Filter

func Filter[T any](prefix string) handlers.Filter[*goram.CallbackQuery]

Creates callback query filter for callback data. Unpacks callback data and check the prefix. If a query has no data, the created filter returns false. If the prefix matches, the created filter puts unpacked callback data to handler data with "callbackData" key and returns true. Otherwise returns false.

func FilterFunc

func FilterFunc[T any](
	prefix string,
	predicate func(data T) bool,
) handlers.Filter[*goram.CallbackQuery]

Does the same as .Filter() but also applies the provided predicate.

func Pack

func Pack[T any](prefix string, value T) string

Packs callback data string.

T should be fixed size. T will be binary encoded to consume less space (because callback data is up to 64 bytes only). Prefix is used to determine what value got encoded to the string. See .Unpack(). Prefix should not contain ':' since it is used as a delimiter.

Returns packed callback data string. Panics if T can't be binary encoded. The returned string is *not* checked to fit 64 bytes.

func Unpack

func Unpack[T any](prefix string, callbackData string) (T, error)

Unpacks a string encoded by .Pack().

If prefixes do not match, returns ErrInvalidPrefix. Otherwise returns encoded value and a binary read error, if occured.

Types

This section is empty.

Jump to

Keyboard shortcuts

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