router

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBackFromWizardCallback

func IsBackFromWizardCallback(c telebot.Context) bool

IsBackFromWizardCallback checks if callback data is back button. It checks if Unique from InlineButton is equal to InlineBtnBackUniq.

Types

type CollectedRoute

type CollectedRoute struct {
	Endpoint any
	Handler  telebot.HandlerFunc
}

CollectedRoute model

type Handler

type Handler interface {
	GetRoutes() []Route
}

type Route

type Route struct {
	// telebot data
	Endpoint   any
	Handler    telebot.HandlerFunc
	Middleware telebot.MiddlewareFunc

	// scene data
	SceneName string
	SceneType session.SceneType
	SceneStep uint
}

Route model

func NewRoute

func NewRoute(endpoint any, h telebot.HandlerFunc, opts ...any) Route

CreateRoute create route

func NewSimpleScene

func NewSimpleScene(name string, h ...Route) []Route

NewSimpleScene create simple scene

func NewWizardScene

func NewWizardScene(name string, endpoints []any, h ...Route) []Route

NewWizardScene create step scene

type RouteGroup

type RouteGroup struct {
	// contains filtered or unexported fields
}

RouteGroup model

func NewRouteGroup

func NewRouteGroup(routes ...Route) *RouteGroup

NewRouteGroup create route group

func (*RouteGroup) Add

func (rg *RouteGroup) Add(routes ...Route) *RouteGroup

Add add routes to route group

func (*RouteGroup) AddReplyButton

func (rg *RouteGroup) AddReplyButton(key string, route Route) *RouteGroup

Add routes for reply button and i18n Need provide key for button, and it make needed routes for handle on this endpoint on other languages

func (*RouteGroup) Extract

func (rg *RouteGroup) Extract() []Route

Extract extract routes from route group

func (*RouteGroup) SetMiddleware

func (rg *RouteGroup) SetMiddleware(md telebot.MiddlewareFunc) *RouteGroup

SetMiddleware set middleware to route group

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(bot *bot.Bot) *Router

NewRouter creates a new Router that will use the given bot.

A Router is a convenient way to manage multiple routes for a single bot. It allows you to easily add middleware to all routes and to easily extract all the routes from the router.

The returned Router has a middleware function set that applies to all routes added to the router.

The returned Router also has a group set that is used to group all routes added to the router.

func (*Router) Collect

func (r *Router) Collect()

Collect collects all routes from the given routes and makes a collected routes model for the router.

It uses the collectRoutes function to get the collected routes and then iterates over the collected routes and adds the endpoints to the router.

It will be called after all routes have been added to the router.

func (*Router) WithHandler

func (r *Router) WithHandler(h ...Handler) *Router

WithHandler adds routes from the given Handlers to the router.

The given Handlers' GetRoutes methods are called and the returned routes are added to the router.

The returned Router is the same as the receiver, but with the added routes.

func (*Router) WithMiddleware

func (r *Router) WithMiddleware(m ...telebot.MiddlewareFunc) *Router

WithMiddleware sets middleware functions to the router's bot.

The middleware functions are applied to all routes added to the router. The middleware functions are applied in the order they are given.

Jump to

Keyboard shortcuts

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