tg

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 11 Imported by: 0

README

TeleGopher

Put here TeleGopher image, please

The high level API to implement complicated behaviour based Telegram bots in W3 manner with URLs, screens, UIs and so on.

Tasks

  • Tech
    • Added easy way to work with payments
    • Make more documentation including the Go embedded one
  • Do some examples to show how it works

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ScreenNotExistErr    = errors.New("screen does not exist")
	SessionNotExistErr   = errors.New("session does not exist")
	KeyboardNotExistErr  = errors.New("keyboard does not exist")
	NotAvailableErr      = errors.New("the context is not available")
	EmptyKeyboardTextErr = errors.New("got empty text for a keyboard")
	ActionNotDefinedErr  = errors.New("action was not defined")
	MapCollisionErr      = errors.New("map collision occured")
	ContextNotExistErr   = errors.New("the context does not exist")
	StatusCodeErr        = errors.New("not success response status code")
	NotSendErr           = errors.New("could not send message")
	NoWidgetForScreenErr = errors.New("no widget defined for the screen")
	EmptyCompoErr        = errors.New("empty component")
	EmptyWidgetErr       = errors.New("empty widget")
)
View Source
var (
	NewRawMessage = tgbotapi.NewMessage
)
View Source
var (
	UnknownFileTypeErr = errors.New("unknown file type")
)

Functions

func Escape2

func Escape2(str string) string

Escape special characters in Markdown 2 and return the resulting string.

Types

type Action

type Action interface {
	Act(Context)
}

Customized actions for the bot.

type ActionFunc

type ActionFunc func(Context)

func (ActionFunc) Act

func (af ActionFunc) Act(c Context)

type Behaviour

type Behaviour struct {
	Root    Component
	Init    Action
	Screens ScreenMap
}

The type describes behaviour for the bot in personal chats.

func NewBehaviour

func NewBehaviour() *Behaviour

Returns new empty behaviour.

func (*Behaviour) GetScreen

func (beh *Behaviour) GetScreen(pth Path) *Screen

Returns the screen by it's ID.

func (*Behaviour) PathExist

func (beh *Behaviour) PathExist(pth Path) bool

Check whether the screen exists in the behaviour.

func (*Behaviour) SetInit added in v0.16.0

func (b *Behaviour) SetInit(a Action) *Behaviour

The Action will be called on session creation, not when starting or restarting the bot with the Start Action.

func (*Behaviour) SetRootNode added in v0.16.0

func (b *Behaviour) SetRootNode(node *RootNode) *Behaviour

Sets the root node of the Behaviour. Mostly used for commands and such stuff.

func (*Behaviour) SetRootWidget added in v0.16.0

func (b *Behaviour) SetRootWidget(root Component) *Behaviour

The function sets as the standard root widget CommandWidget and its commands..

type Bot

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

The wrapper around Telegram API.

func NewBot

func NewBot(token string) (*Bot, error)

Return the new bot with empty sessions and behaviour.

func (*Bot) Api

func (bot *Bot) Api() *tgbotapi.BotAPI

func (*Bot) Data

func (bot *Bot) Data() any

func (*Bot) DeleteCommands

func (bot *Bot) DeleteCommands()

func (*Bot) GotSession added in v0.16.0

func (bot *Bot) GotSession(
	sid SessionId,
) (*Session, bool)

Get session by its ID. Can be used for any scope including private, group and channel.

func (*Bot) Me

func (bot *Bot) Me() User

func (*Bot) Run

func (bot *Bot) Run() error

Run the bot with the Behaviour.

func (*Bot) Send

func (bot *Bot) Send(
	sid SessionId, v Sendable,
) (*Message, error)

Send the Renderable to the specified session client side. Can be used for both group and private sessions because SessionId represents both for chat IDs.

func (*Bot) SendRaw

func (bot *Bot) SendRaw(
	sid SessionId, v tgbotapi.Chattable,
) (*Message, error)

Send to the session specified its ID raw chattable from the tgbotapi.

func (*Bot) Sendf

func (bot *Bot) Sendf(
	sid SessionId, format string, v ...any,
) (*Message, error)

func (*Bot) SetBehaviour added in v0.16.0

func (b *Bot) SetBehaviour(beh *Behaviour) *Bot

func (*Bot) SetCommands

func (bot *Bot) SetCommands(
	scope tgbotapi.BotCommandScope,
	cmdMap CommandMap,
) error

Setting the command on the user side.

func (*Bot) SetData added in v0.16.0

func (bot *Bot) SetData(v any) *Bot

func (*Bot) SetDebug added in v0.16.0

func (bot *Bot) SetDebug(debug bool) *Bot

func (*Bot) SetSessions added in v0.16.0

func (b *Bot) SetSessions(sessions SessionMap) *Bot

type Button

type Button struct {
	Text         string
	Data         string
	Url          string
	SendLocation bool
	Action       Action
	// Used to skip buttons in generating by functions.
	Valid bool
}

The type wraps Telegram API's button to provide Action functionality.

func Buttonf added in v0.16.0

func Buttonf(format string, v ...any) Button

Returns new button with the specified text and no action.

func (Button) Go

func (btn Button) Go(pth Path) Button

func (Button) GoWithArg added in v0.16.0

func (btn Button) GoWithArg(pth Path, arg any) Button

func (Button) Key

func (btn Button) Key() string

Return the key of the button to identify it by messages and callbacks.

func (Button) Rand

func (btn Button) Rand() Button

Randomize buttons data to make the key unique. No guaranties about collisions though.

func (Button) ToTelegram

func (btn Button) ToTelegram() apix.KeyboardButton

func (Button) ToTelegramInline

func (btn Button) ToTelegramInline() apix.InlineKeyboardButton

func (Button) WithAction

func (btn Button) WithAction(a Action) Button

Set the action when pressing the button. By default is nil and does nothing.

func (Button) WithData

func (btn Button) WithData(dat string) Button

func (Button) WithSendLocation

func (btn Button) WithSendLocation(ok bool) Button

Sets whether the button must send owner's location.

func (Button) WithUrl

func (btn Button) WithUrl(format string, v ...any) Button

Set the URL for the button. Only for inline buttons.

type ButtonMap

type ButtonMap map[string]Button

func (ButtonMap) LocationButton

func (btnMap ButtonMap) LocationButton() (Button, bool)

type ButtonRow

type ButtonRow []Button

Represents the reply button row.

func NewButtonRow

func NewButtonRow(btns ...Button) ButtonRow

type Chat

type Chat = tgbotapi.Chat

type Command

type Command struct {
	Name        CommandName
	Type        CommandType
	Description string
	Action      Action
	Widget      Widget
	WidgetArg   any
}

func NewCommand

func NewCommand(name CommandName, desc string) Command

func (Command) Go

func (c Command) Go(pth Path) Command

Simple command to go to another screen.

func (Command) GoWithArg added in v0.16.0

func (c Command) GoWithArg(pth Path, arg any) Command

func (Command) ToApi

func (c Command) ToApi() tgbotapi.BotCommand

Convert command into the tgbotapi.BotCommand

func (Command) WithAction

func (c Command) WithAction(a Action) Command

func (Command) WithWidget

func (c Command) WithWidget(w Widget) Command

type CommandCompo

type CommandCompo struct {
	PreStart Action
	Commands CommandMap
	Usage    Action
}

The type is used to recognize commands and execute its actions and widgets .

func NewCommandCompo

func NewCommandCompo(cmds ...Command) *CommandCompo

Returns new empty CommandCompo.

func (*CommandCompo) Filter

func (widget *CommandCompo) Filter(
	u Update,
) bool

Filtering all the non commands.

func (*CommandCompo) Serve

func (compo *CommandCompo) Serve(c Context)

Implementing server.

func (*CommandCompo) SetCommands added in v0.16.0

func (w *CommandCompo) SetCommands(cmds ...Command) *CommandCompo

Set the commands to handle.

func (*CommandCompo) SetPreStart added in v0.16.0

func (w *CommandCompo) SetPreStart(a Action) *CommandCompo

Set the prestart action.

func (*CommandCompo) SetUsage added in v0.16.0

func (w *CommandCompo) SetUsage(a Action) *CommandCompo

Set the usage action.

type CommandMap

type CommandMap map[CommandName]Command

type CommandName

type CommandName string

type CommandType

type CommandType uint8
const (
	PrivateCommandType CommandType = iota
	GroupCommandType
	ChannelCommandType
)

type Component

type Component interface {
	Filterer
	Server
}

The type describes interfaces needed to be implemented to be endpoint handlers.

type Context

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

Interface to interact with the user.

func (Context) Arg

func (c Context) Arg() any

func (Context) As

func (c Context) As(sid SessionId) (Context, bool)

Run commands as other user. Was implemented to make other user to leave the bot at first but maybe you will find another usage for this. Returns users context by specified session ID or false if the user is not logged in.

func (Context) Bot added in v0.16.0

func (c Context) Bot() *Bot

Return the session related bot.

func (Context) CallbackUpdate added in v0.16.0

func (c Context) CallbackUpdate() *Update

func (Context) GetFile

func (c Context) GetFile(fileId FileId) (io.ReadCloser, string, error)

Returns the reader for specified file ID and path.

func (Context) Go

func (c Context) Go(pth Path) error

Simple go without an argument for context.

func (Context) GoWithArg added in v0.16.0

func (c Context) GoWithArg(pth Path, arg any) error

Changes screen of user to the Id one. Also gives the arg to the widget calling contexts.

func (Context) Input

func (c Context) Input() chan Update

Get the input for current widget. Should be used inside handlers (aka "Serve").

func (Context) Path

func (c Context) Path() Path

func (Context) PathExist

func (c Context) PathExist(pth Path) bool

Returns true if the path exists and false otherwise.

func (Context) PathHistory added in v0.16.0

func (c Context) PathHistory() []Path

Return context's session's path history.

func (Context) ReadFile

func (c Context) ReadFile(fileId FileId) ([]byte, string, error)

Reads all the content from the specified file.

func (Context) ReadString

func (c Context) ReadString(promptf string, args ...any) string

Simple way to read strings for widgets with the specified prompt.

func (Context) Run

func (c Context) Run(a Action)

func (Context) Send

func (c Context) Send(v Sendable) (*Message, error)

Sends to the Sendable object to the session user.

func (Context) Sendf

func (c Context) Sendf(format string, v ...any) (*Message, error)

Sends the formatted with fmt.Sprintf message to the user using default Markdown parsing format.

func (Context) Sendf2

func (c Context) Sendf2(format string, v ...any) (*Message, error)

Same as Sendf but uses Markdown 2 format for parsing.

func (Context) SendfHTML

func (c Context) SendfHTML(format string, v ...any) (*Message, error)

Same as Sendf but uses HTML format for parsing.

func (Context) SendfR

func (c Context) SendfR(format string, v ...any) (*Message, error)

Send the message in raw format escaping all the special characters.

func (Context) Session added in v0.16.0

func (c Context) Session() Session

func (Context) SessionData added in v0.16.0

func (c Context) SessionData() any

func (Context) SessionId added in v0.16.0

func (c Context) SessionId() SessionId

func (Context) SessionScope added in v0.16.0

func (c Context) SessionScope() SessionScope

func (Context) SetSessionData added in v0.16.0

func (c Context) SetSessionData(v any)

func (Context) SkipUpdate added in v0.16.0

func (c Context) SkipUpdate(u Update)

Only for the root widget usage. Skip the update sending it down to the underlying widget.

func (Context) WithArg

func (c Context) WithArg(v any) Context

func (Context) WithInput

func (c Context) WithInput(input *UpdateChan) Context

func (Context) WithUpdate

func (c Context) WithUpdate(u Update) Context

type ContextType

type ContextType uint8
const (
	NoContextType ContextType = iota
	WidgetContextType
	ActionContextType
)

type File

type File struct {
	MessageCompo
	// contains filtered or unexported fields
}

The type implements the structure to easily send files to the client.

func NewFile

func NewFile(reader io.Reader) *File

Create the new file with the specified reader. By default it NeedsUpload is set to true.

func (*File) Caption

func (f *File) Caption(caption string) *File

Set the file caption.

func (*File) Data

func (f *File) Data(data string) *File

Set the data to return via SendData()

func (*File) Document

func (f *File) Document() *File

func (*File) Name

func (f *File) Name(name string) *File

func (*File) NeedsUpload

func (f *File) NeedsUpload() bool

func (*File) Photo

func (f *File) Photo() *File

Set the file type to PhotoFileType.

func (*File) SendConfig

func (f *File) SendConfig(
	sid SessionId, bot *Bot,
) SendConfig

func (*File) SendData

func (f *File) SendData() string

func (*File) Type

func (f *File) Type() FileType

Get the file type.

func (*File) Upload

func (f *File) Upload(upload bool) *File

Specifiy whether the file needs to be uploaded to Telegram.

func (*File) UploadData

func (f *File) UploadData() (string, io.Reader, error)

type FileConfig

type FileConfig = tgbotapi.FileConfig

type FileId

type FileId string

type FileType

type FileType int
const (
	NoFileType FileType = iota
	PhotoFileType
	DocumentFileType
)

type FilterFunc

type FilterFunc func(Update) bool

func (FilterFunc) Filter

func (f FilterFunc) Filter(
	u Update,
) bool

type Filterer

type Filterer interface {
	// Return true if should filter the update
	// and not send it inside the widget.
	Filter(Update) bool
}

Implementing the interface provides way to know exactly what kind of updates the widget needs.

type Func

type Func func(Context)

General type function to define actions, single component widgets and components themselves.

func (Func) Act

func (f Func) Act(c Context)

func (Func) Filter

func (f Func) Filter(_ Update) bool

func (Func) Render

func (f Func) Render(_ Context) UI

func (Func) Serve

func (f Func) Serve(c Context)

type GoWidget

type GoWidget string

func (GoWidget) Filter

func (widget GoWidget) Filter(u Update) bool

func (GoWidget) Render

func (widget GoWidget) Render(c Context) UI

func (GoWidget) Serve

func (widget GoWidget) Serve(c Context)

Implementing the Server interface.

type Inline

type Inline struct {
	Keyboard
}

The type represents keyboard to be emdedded into the messages (inline in Telegram terms).

func (Inline) ToApi

func (kbd Inline) ToApi() tgbotapi.InlineKeyboardMarkup

Convert the inline keyboard to markup for the tgbotapi.

type InlineCompo

type InlineCompo struct {
	MessageCompo
	Inline
}

The type implements message with an inline keyboard.

func (*InlineCompo) Filter

func (compo *InlineCompo) Filter(u Update) bool

Implementing the Filterer interface.

func (*InlineCompo) OnOneUpdate

func (compo *InlineCompo) OnOneUpdate(c Context, u Update) error

func (*InlineCompo) SendConfig

func (compo *InlineCompo) SendConfig(
	sid SessionId, bot *Bot,
) SendConfig

Implementing the Sendable interface.

func (*InlineCompo) Serve

func (compo *InlineCompo) Serve(c Context)

Implementing the Server interface.

func (*InlineCompo) Update

func (compo *InlineCompo) Update(c Context) error

Update the component on the client side. Requires exactly the pointer but not the value cause it changes insides of the structure.

type InvoiceCompo

type InvoiceCompo struct {
	*MessageCompo
	tgbotapi.InvoiceConfig
}

func (*InvoiceCompo) SendConfig

func (compo *InvoiceCompo) SendConfig(
	sid SessionId, bot *Bot,
) *SendConfig

type Keyboard

type Keyboard struct {
	// The action is called if there is no
	// defined action for the button.
	Action Action
	Rows   []ButtonRow
}

The general keyboard type used both in Reply and Inline.

func NewKeyboard

func NewKeyboard(rows ...ButtonRow) Keyboard

Returns the new keyboard with specified rows.

func (Keyboard) ButtonMap

func (kbd Keyboard) ButtonMap() ButtonMap

Returns the map of buttons. Where the key is button data and the value is Action.

func (Keyboard) Inline

func (kbd Keyboard) Inline() Inline

Convert the keyboard to the more specific inline one.

func (Keyboard) List

func (kbd Keyboard) List(btns ...Button) Keyboard

Adds buttons as one column list.

func (Keyboard) MakeButtonMap

func (kbd Keyboard) MakeButtonMap() ButtonMap

Returns the map of buttons on the most fresh version of the keyboard.

func (*Keyboard) RemoveRow

func (kbd *Keyboard) RemoveRow(i int)

func (Keyboard) Reply

func (kbd Keyboard) Reply() Reply

Convert the keyboard to the more specific reply one. By default OneTime = true.

func (Keyboard) Row

func (kbd Keyboard) Row(btns ...Button) Keyboard

Adds a new button row to the current keyboard.

func (Keyboard) RowNum

func (kbd Keyboard) RowNum() int

func (Keyboard) WithAction

func (kbd Keyboard) WithAction(a Action) Keyboard

Set the default action when no button provides key to the data we got.

type Location

type Location = tgbotapi.Location

type LocationCompo

type LocationCompo struct {
	MessageCompo
	Location
}

func (*LocationCompo) SendConfig

func (compo *LocationCompo) SendConfig(
	sid SessionId, bot *Bot,
) SendConfig

type Maker

type Maker[V any] interface {
	Make(*Context) V
}

type Message

type Message = tgbotapi.Message

type MessageCompo

type MessageCompo struct {
	// Low level Message represents
	// the already sent to the client message.
	// Will be nil if the message is not rendered to the client.
	Message *Message
	// Parsing mode for the text: HTML, MD, MD2...
	ParseMode string
	// The text to display.
	Text string
}

Simple text message component type.

func Messagef added in v0.16.0

func Messagef(format string, v ...any) *MessageCompo

Return new message with the specified text formatted with the fmt.Sprintf function.

func (*MessageCompo) Delete

func (compo *MessageCompo) Delete(c Context) error

Calling the method removes the message on the client side and sets the Message in the component to nil.

func (*MessageCompo) Filter

func (compo *MessageCompo) Filter(_ Update) bool

Filter that skips everything. Messages cannot do anything with updates.

func (*MessageCompo) HTML

func (compo *MessageCompo) HTML() *MessageCompo

Set the HTML parsing mode.

func (*MessageCompo) Inline

func (compo *MessageCompo) Inline(inline Inline) *InlineCompo

Transform the message component into one with reply keyboard.

func (*MessageCompo) Location

func (msg *MessageCompo) Location(
	lat, long float64,
) *LocationCompo

Transform the message component into the location one.

func (*MessageCompo) MD

func (compo *MessageCompo) MD() *MessageCompo

Set the default Markdown parsing mode.

func (*MessageCompo) MD2

func (compo *MessageCompo) MD2() *MessageCompo

Set the Markdown 2 parsing mode.

func (*MessageCompo) Panel

func (compo *MessageCompo) Panel(
	c Context,
	rowser Rowser,
) *PanelCompo

Transform to the panel with dynamic rows.

func (*MessageCompo) Reply

func (msg *MessageCompo) Reply(reply Reply) *ReplyCompo

Transform the message component into one with reply keyboard.

func (*MessageCompo) SendConfig

func (compo *MessageCompo) SendConfig(
	sid SessionId, bot *Bot,
) SendConfig

Implementing the Sendable interface.

func (*MessageCompo) Serve

func (compo *MessageCompo) Serve(c Context)

Empty serving to use messages in rendering.

func (*MessageCompo) SetMessage

func (compo *MessageCompo) SetMessage(msg *Message)

Implementing the Sendable interface. Also used for embedding for things like InlineCompo etc.

func (*MessageCompo) Update

func (compo *MessageCompo) Update(c Context) error

Call the function after the message was sent.

type MessageId

type MessageId int64

type MessageMap

type MessageMap map[string]*Message

type Node

type Node struct {
	Path   Path
	Screen *Screen
	Subs   []*Node
}

The node is a simple way to represent tree-like structured applications.

func NewNode

func NewNode(relPath Path, widget Widget, subs ...*Node) *Node

func (*Node) ScreenMap

func (n *Node) ScreenMap(root Path) ScreenMap

type PanelCompo

type PanelCompo struct {
	InlineCompo
	Rowser Rowser
}

The type represents the inline panel with scrollable via buttons content. Can be used for example to show users via SQL and offset or something like that.

func (*PanelCompo) Update

func (compo *PanelCompo) Update(c Context)

type Path

type Path string

Unique identifier for the screen and relative paths to the screen.

func (Path) Clean

func (p Path) Clean() Path

Clean the path deleting exceed ., .. and / .

func (Path) Dir

func (p Path) Dir() Path

func (Path) IsAbs

func (p Path) IsAbs() bool

Returns true if the path is absolute.

func (Path) IsEmpty

func (p Path) IsEmpty() bool

Returns true if the path is empty.

type PhotoConfig

type PhotoConfig = tgbotapi.PhotoConfig

type Poll

type Poll struct {
}

Still to be implemented.

type PollCompo

type PollCompo struct {
}

type RenderFunc

type RenderFunc func(c Context) UI

The way to describe custom function based Widgets.

func (RenderFunc) Render

func (fn RenderFunc) Render(c Context) UI

type Reply

type Reply struct {
	Keyboard
	// If true will be removed after one press.
	OneTime bool
	// If true will remove the keyboard on send.
	Remove bool
}

The type represents reply keyboards.

func (Reply) ToApi

func (kbd Reply) ToApi() any

Convert the Keyboard to the Telegram API type of reply keyboard.

func (Reply) WithOneTime

func (kbd Reply) WithOneTime(oneTime bool) Reply

Set if the keyboard should be hidden after one of buttons is pressede.

func (Reply) WithRemove

func (kbd Reply) WithRemove(remove bool) Reply

Set if we should remove current keyboard on the user side when sending the keyboard.

type ReplyCompo

type ReplyCompo struct {
	MessageCompo
	Reply
}

The type implements reply keyboard widget.

func (*ReplyCompo) Filter

func (compo *ReplyCompo) Filter(
	u Update,
) bool

Implementing the Server interface.

func (*ReplyCompo) SendConfig

func (compo *ReplyCompo) SendConfig(
	sid SessionId, bot *Bot,
) SendConfig

Implementing the sendable interface.

func (*ReplyCompo) Serve

func (compo *ReplyCompo) Serve(c Context)

Implementing the UI interface.

type RootNode

type RootNode struct {
	Screen *Screen
	Subs   []*Node
}

The first node with the "/" path.

func NewRootNode

func NewRootNode(widget Widget, subs ...*Node) *RootNode

Return new root node with the specified widget in the screen.

func (*RootNode) ScreenMap

func (n *RootNode) ScreenMap() ScreenMap

type Rowser

type Rowser interface {
	MakeRows(c Context) []ButtonRow
}

type RowserFunc

type RowserFunc func(c Context) []ButtonRow

func (RowserFunc) MakeRows

func (fn RowserFunc) MakeRows(c Context) []ButtonRow

type Screen

type Screen struct {
	// The widget to run when reaching the screen.
	Widget Widget
}

Screen statement of the bot. Mostly what buttons to show.

func NewScreen

func NewScreen(widget Widget) *Screen

Returns the new screen with specified name and widget.

type ScreenGo

type ScreenGo struct {
	Path Path
	Arg  any
}

The type implements changing screen to the underlying ScreenId

func (ScreenGo) Act

func (sc ScreenGo) Act(c Context)

func (ScreenGo) Serve

func (sc ScreenGo) Serve(c Context)

The same as Act.

type ScreenMap

type ScreenMap map[Path]*Screen

Map structure for the screens.

type SendConfig

type SendConfig struct {
	Chattable tgbotapi.Chattable
	Error     error
}

The type is used as an endpoint to send messages via bot.Send .

func (SendConfig) ToApi

func (config SendConfig) ToApi() tgbotapi.Chattable

Convert to the bot.Api.Send format.

type Sendable

type Sendable interface {
	SendConfig(SessionId, *Bot) SendConfig
	SetMessage(*Message)
}

Implementing the interface provides way to define what message will be sent to the side of a user.

type Server

type Server interface {
	Serve(Context)
}

Implementing the interface provides the way to define how to handle updates.

type Session

type Session struct {
	// Id of the chat of the user.
	Id    SessionId
	Scope SessionScope
	// Custom value for each user.
	Data any
	// contains filtered or unexported fields
}

The type represents current state of user interaction per each of them.

func NewSession

func NewSession(bot *Bot, id SessionId, scope SessionScope) *Session

Return new empty session.

type SessionId

type SessionId int64

Represents unique value to identify chats. In fact is simply ID of the chat.

func (SessionId) ToApi

func (si SessionId) ToApi() int64

Convert the SessionId to Telegram API's type.

type SessionMap

type SessionMap map[SessionId]*Session

The type represents map of sessions using as key.

func (SessionMap) Add

func (sm SessionMap) Add(
	bot *Bot,
	sid SessionId,
	scope SessionScope,
) *Session

Add new empty session by it's ID.

type SessionScope

type SessionScope uint8

The way to determine where the context is related to.

const (
	NoSessionScope SessionScope = iota
	PrivateSessionScope
	GroupSessionScope
	ChannelSessionScope
)

type UI

type UI []Component

The type that represents endpoint user interface via set of components that will work on the same screen in the same time.

func Go

func Go(pth Path) UI

type Update

type Update struct {
	tgbotapi.Update
}

func (Update) DocumentId

func (u Update) DocumentId() FileId

func (Update) DocumentMimeType

func (u Update) DocumentMimeType() string

func (*Update) DocumentName

func (u *Update) DocumentName() string

func (Update) DocumentSize

func (u Update) DocumentSize() int

func (Update) HasDocument

func (u Update) HasDocument() bool

func (Update) HasPhotos

func (u Update) HasPhotos() bool

func (Update) PhotoIds

func (u Update) PhotoIds() []FileId

type UpdateChan

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

The type represents general update channel.

func NewUpdateChan

func NewUpdateChan() *UpdateChan

Return new update channel.

func (*UpdateChan) Chan

func (updates *UpdateChan) Chan() chan Update

func (*UpdateChan) Close

func (updates *UpdateChan) Close()

Close the channel. Used in defers.

func (*UpdateChan) Closed

func (updates *UpdateChan) Closed() bool

Returns true if the channel is closed.

func (*UpdateChan) Read

func (updates *UpdateChan) Read() (Update, bool)

Read an update from the channel.

func (*UpdateChan) Send

func (updates *UpdateChan) Send(u Update) bool

Send an update to the channel. Returns true if the update was sent.

type User

type User = tgbotapi.User

type Widget

type Widget interface {
	Render(Context) UI
}

The type describes dynamic screen widget That can have multiple UI components.

type WrongUpdateType

type WrongUpdateType struct {
	Type string
}

func (WrongUpdateType) Error

func (wut WrongUpdateType) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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