menu

package
v0.0.0-...-516d34e Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Stay    = 0
	Forward = 1
	Back    = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(e *Node, c *tb.Callback) int

Callback function declaration that includes a "node" that a call was made from

type Dialog

type Dialog struct {
	Message  *tb.Message
	Language string
	Position *Node
}

A dialog is an abstract piece that holds a menu message sent by the bot and a language that the interface is displayed

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

A flow is essentially a high-level representation of a menu

func NewMenuFlow

func NewMenuFlow(id string, bot *tb.Bot, engine *tr.Engine) (*Menu, error)

Creates a new flow and initializes the specified locale directory Warning! When setting a id treat it gently, like picking a directory name, same rules applies. It will fail without a notice if you put special characters or symbols (except for underscore) in it. Suggested names: flow1, flow_1, MyFlow

func (f *Menu) Build(lang string) *Menu

Builds the flow for a specified locale

func (f *Menu) CountNodes() int

Count all nodes in the tree

func (f *Menu) GetBot() *tb.Bot

Get attached Telegram bot

func (f *Menu) GetDialog(id string) (*Dialog, bool)

Retrieves a dialog by user id

func (f *Menu) GetId() string

Get menu's unique identificator

func (f *Menu) GetRoot() *Node

Get the root node

func (f *Menu) HandleBack(e *Node, c *tb.Callback) int

Helper handler for back buttons

func (f *Menu) HandleForward(e *Node, c *tb.Callback) int

Helper handler for forward buttons

func (f *Menu) MoveTo(to tb.Recipient, text, lang string, position *Node) error

Takes a user to a specified menu position (page)

func (f *Menu) NewBackNode(text string) *Node

Creates a new back button node in the flow that automatically takes a user one page back

func (f *Menu) NewNode(text string, endpoint Callback) *Node

Creates a new node in the flow

func (f *Menu) SetCaption(recipient tb.Recipient, text string, params ...interface{}) *Menu

Sets a new caption for the menu The caption will be updated right away Params are automatically placed in the text if provided

func (f *Menu) Start(to tb.Recipient, text, lang string) error

Sends a new instance of a menu to a user with a specified locale Tries to delete the old menu before sending a new one

func (f *Menu) StartAt(to tb.Recipient, text, lang string, at *Node) error

Sends an instance of a menu to a user starting at a specified node Tries to delete the old menu before sending a new one

func (f *Menu) Stop(to tb.Recipient, text, lang string) error

Removes the menu from a user and deletes the session

type Node

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

An element of a menu that holds all required information by a page a.k.a a button that holds other buttons for the next page

func (*Node) Add

func (e *Node) Add(text string, endpoint Callback) *Node

Adds a new node to the current node Returns the current node

func (*Node) AddManySub

func (e *Node) AddManySub(elements []*Node) *Node

Adds many new sub nodes Returns the current node

func (*Node) AddSub

func (e *Node) AddSub(text string, endpoint Callback) *Node

Adds a new sub node Returns the new node

func (*Node) AddWith

func (e *Node) AddWith(text string, endpoint Callback, elements ...*Node) *Node

Adds a new node with many sub-nodes to the current node Returns the current node

func (*Node) GetEndpoint

func (e *Node) GetEndpoint() Callback

Get node's callback endpoint

func (*Node) GetFlow

func (e *Node) GetFlow() *Menu

Get related flow

func (*Node) GetId

func (e *Node) GetId() string

Get node's identificator

func (*Node) GetLanguage

func (e *Node) GetLanguage(c *tb.Callback) string

Gets a language currently used in a dialog by the user

func (*Node) GetMarkup

func (e *Node) GetMarkup(lang string) *tb.ReplyMarkup

Get a markups in a specified language Caution! Menu must be built for the specified language beforehand

func (*Node) GetNodes

func (e *Node) GetNodes() []*Node

Get all children nodes

func (*Node) GetPath

func (e *Node) GetPath() string

Get node's locale path

func (*Node) GetText

func (e *Node) GetText() string

Get node's default text

func (*Node) Previous

func (e *Node) Previous() *Node

Get previous (parent) node in the tree

func (*Node) SetCaption

func (e *Node) SetCaption(c *tb.Callback, text string, params ...interface{}) *Node

Sets a new caption for the flow that will be updated in the next menu iteration params are automatically placed in the text if provided

func (*Node) SetLanguage

func (e *Node) SetLanguage(c *tb.Callback, lang string) *Node

Sets a language for the user's dialog

Jump to

Keyboard shortcuts

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