chain

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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChainIsEmpty = errors.New("chain has zero handlers")

Functions

This section is empty.

Types

type Callback

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

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

type Chain

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

A flow is chain or double-linked list of events organized by type

func NewChainFlow

func NewChainFlow(id string, bot *tb.Bot) (*Chain, error)

Creates a new chain flow

func (*Chain) DeletePosition

func (c *Chain) DeletePosition(of tb.Recipient)

Deletes the user current position in the flow

func (*Chain) GetBot

func (c *Chain) GetBot() *tb.Bot

Get attached Telegram bot

func (*Chain) GetId

func (c *Chain) GetId() string

Get chain's unique identificator

func (*Chain) GetPosition

func (c *Chain) GetPosition(of tb.Recipient) (*Node, bool)

Gets the user position in the flow

func (*Chain) GetRoot

func (c *Chain) GetRoot() *Node

Get the root node

func (*Chain) Process

func (c *Chain) Process(m *tb.Message) bool

Process with the next flow iteration Returns true only if the iteration was successful

func (*Chain) Search

func (c *Chain) Search(nodeId string) (*Node, bool)

Search for a node with ID

func (*Chain) SetDefaultHandler

func (c *Chain) SetDefaultHandler(endpoint Callback) *Chain

Get the root node

func (*Chain) SetPosition

func (c *Chain) SetPosition(of tb.Recipient, node *Node)

Sets the user current position in the flow

func (*Chain) Start

func (c *Chain) Start(to tb.Recipient, text string, options ...interface{}) (err error)

Executes the chain for the user by putting him on a first stage of the chain

type Node

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

Node is an element in a double-linked list

func (*Node) CheckEvent

func (e *Node) CheckEvent(m *tb.Message) bool

Checks if the message type is matching the node type

func (*Node) GetEndpoint

func (e *Node) GetEndpoint() Callback

Get node's callback endpoint

func (*Node) GetFlow

func (e *Node) GetFlow() *Chain

Get related flow

func (*Node) GetId

func (e *Node) GetId() string

Get node's identificator

func (*Node) Next

func (e *Node) Next() *Node

Get the next node in the list

func (*Node) Previous

func (e *Node) Previous() *Node

Get the previous node in the list

func (*Node) SearchDown

func (e *Node) SearchDown(nodeId string) (*Node, bool)

Tries to find a node with ID down the list

func (*Node) SearchUp

func (e *Node) SearchUp(nodeId string) (*Node, bool)

Tries to find a node with ID up the list

func (*Node) Then

func (e *Node) Then(id string, endpoint Callback, expectedEvent string) *Node

Creates a following element in the list

Jump to

Keyboard shortcuts

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