Documentation ¶
Index ¶
- Variables
- func DefineAction(typeName string, a Action) error
- func Escape2(str string) string
- type Action
- type ActionFunc
- type Behaviour
- func (beh *Behaviour) GetScreen(pth Path) *Screen
- func (beh *Behaviour) PathExist(pth Path) bool
- func (b *Behaviour) WithInit(a Action) *Behaviour
- func (b *Behaviour) WithInitFunc(fn ActionFunc) *Behaviour
- func (b *Behaviour) WithRoot(root Component) *Behaviour
- func (b *Behaviour) WithRootNode(node *RootNode) *Behaviour
- type Bot
- func (bot *Bot) Debug(debug bool) *Bot
- func (bot *Bot) DeleteCommands()
- func (bot *Bot) GetSession(sid SessionId) (*Session, bool)
- func (bot *Bot) Run() error
- func (bot *Bot) Send(sid SessionId, v Sendable) (*Message, error)
- func (bot *Bot) SendRaw(sid SessionId, v tgbotapi.Chattable) (*Message, error)
- func (bot *Bot) SetCommands(scope tgbotapi.BotCommandScope, cmdMap CommandMap) error
- func (b *Bot) WithBehaviour(beh *Behaviour) *Bot
- func (b *Bot) WithSessions(sessions SessionMap) *Bot
- type Button
- func (btn *Button) ActionFunc(fn ActionFunc) *Button
- func (btn *Button) Go(pth Path, args ...any) *Button
- func (btn *Button) Key() string
- func (btn *Button) ToTelegram() apix.KeyboardButton
- func (btn *Button) ToTelegramInline() apix.InlineKeyboardButton
- func (btn *Button) WithAction(a Action) *Button
- func (btn *Button) WithData(dat string) *Button
- func (btn *Button) WithSendLocation(ok bool) *Button
- func (btn *Button) WithUrl(url string) *Button
- type ButtonMap
- type ButtonRow
- type CC
- type ChannelAction
- type ChannelContext
- type Chat
- type Command
- type CommandCompo
- func (widget *CommandCompo) Filter(u *Update) bool
- func (compo *CommandCompo) Serve(c *Context)
- func (w *CommandCompo) WithCommands(cmds ...*Command) *CommandCompo
- func (w *CommandCompo) WithPreStart(a Action) *CommandCompo
- func (w *CommandCompo) WithPreStartFunc(fn ActionFunc) *CommandCompo
- func (w *CommandCompo) WithUsage(a Action) *CommandCompo
- func (w *CommandCompo) WithUsageFunc(fn ActionFunc) *CommandCompo
- type CommandMap
- type CommandName
- type CommandType
- type Component
- type Context
- func (c *Context) Arg() any
- func (c *Context) Copy() *Context
- func (c *Context) Go(pth Path, args ...any)
- func (c *Context) History() []Path
- func (c *Context) Input() chan *Update
- func (c *Context) Path() Path
- func (c *Context) PathExist(pth Path) bool
- func (c *Context) ReadString(pref string, args ...any) string
- func (c *Context) Run(a Action)
- func (c *Context) RunCompo(compo Component, args ...any) *UpdateChan
- func (c *Context) RunWidget(widget Widget, args ...any) *UpdateChan
- func (c *Context) Send(v Sendable) (*Message, error)
- func (c *Context) Sendf(format string, v ...any) (*Message, error)
- func (c *Context) Sendf2(format string, v ...any) (*Message, error)
- func (c *Context) SendfHTML(format string, v ...any) (*Message, error)
- func (c *Context) Skip(u *Update)
- func (c *Context) WithArg(v any) *Context
- func (c *Context) WithInput(input *UpdateChan) *Context
- func (c *Context) WithUpdate(u *Update) *Context
- type ContextType
- type Errorer
- type File
- type FileType
- type FilterFunc
- type Filterer
- type Func
- type Inline
- type InlineCompo
- type InvoiceCompo
- type Keyboard
- func (kbd *Keyboard) ActionFunc(fn ActionFunc) *Keyboard
- func (kbd Keyboard) ButtonMap() ButtonMap
- func (kbd *Keyboard) Inline() *Inline
- func (kbd *Keyboard) List(btns ...*Button) *Keyboard
- func (kbd *Keyboard) Reply() *Reply
- func (kbd *Keyboard) Row(btns ...*Button) *Keyboard
- func (kbd *Keyboard) WithAction(a Action) *Keyboard
- type Location
- type LocationCompo
- type Maker
- type Message
- type MessageCompo
- func (compo *MessageCompo) Filter(_ *Update) bool
- func (msg *MessageCompo) HTML() *MessageCompo
- func (msg *MessageCompo) Inline(inline *Inline) *InlineCompo
- func (msg *MessageCompo) Location(lat, long float64) *LocationCompo
- func (msg *MessageCompo) MD() *MessageCompo
- func (msg *MessageCompo) MD2() *MessageCompo
- func (msg *MessageCompo) Reply(reply *Reply) *ReplyCompo
- func (config *MessageCompo) SendConfig(sid SessionId, bot *Bot) *SendConfig
- func (compo *MessageCompo) Serve(c *Context)
- func (compo *MessageCompo) SetMessage(msg *Message)
- func (compo *MessageCompo) Update(c *Context)
- type MessageId
- type MessageMap
- type Node
- type Path
- type PhotoConfig
- type Poll
- type PollCompo
- type RenderFunc
- type Reply
- type ReplyCompo
- type RootNode
- type Screen
- type ScreenGo
- type ScreenMap
- type SendConfig
- type Sendable
- type Server
- type Session
- type SessionId
- type SessionMap
- type SessionScope
- type UI
- type Update
- type UpdateChan
- type User
- type Widget
- type WrongUpdateType
Constants ¶
This section is empty.
Variables ¶
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") )
var (
Init func()
)
var (
NewRawMessage = tgbotapi.NewMessage
)
var (
UnknownFileTypeErr = errors.New("unknown file type")
)
Functions ¶
func DefineAction ¶
Define interface to make it marshalable to JSON etc. Like in GOB. Must be done both on client and server if one is provided.
Types ¶
type ActionFunc ¶
type ActionFunc func(*Context)
func (ActionFunc) Act ¶
func (af ActionFunc) Act(c *Context)
type Behaviour ¶
The type describes behaviour for the bot in personal chats.
func (*Behaviour) WithInit ¶
The Action will be called on session creation, not when starting or restarting the bot with the Start Action.
func (*Behaviour) WithInitFunc ¶
func (b *Behaviour) WithInitFunc( fn ActionFunc, ) *Behaviour
Alias to WithInit to simplify behaviour definitions.
func (*Behaviour) WithRoot ¶
The function sets as the standard root widget CommandWidget and its commands..
func (*Behaviour) WithRootNode ¶
type Bot ¶
type Bot struct { // Custom data value. Data any Api *tgbotapi.BotAPI Me *User // contains filtered or unexported fields }
The wrapper around Telegram API.
func (*Bot) DeleteCommands ¶
func (bot *Bot) DeleteCommands()
func (*Bot) GetSession ¶
Get session by its ID. Can be used for any scope including private, group and channel.
func (*Bot) Send ¶
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) SetCommands ¶
func (bot *Bot) SetCommands( scope tgbotapi.BotCommandScope, cmdMap CommandMap, ) error
Setting the command on the user side.
func (*Bot) WithBehaviour ¶
func (*Bot) WithSessions ¶
func (b *Bot) WithSessions(sessions SessionMap) *Bot
type Button ¶
The type wraps Telegram API's button to provide Action functionality.
func (*Button) ActionFunc ¶
func (btn *Button) ActionFunc(fn ActionFunc) *Button
func (*Button) ToTelegram ¶
func (btn *Button) ToTelegram() apix.KeyboardButton
func (*Button) ToTelegramInline ¶
func (btn *Button) ToTelegramInline() apix.InlineKeyboardButton
func (*Button) WithAction ¶
Set the action when pressing the button. By default is nil and does nothing.
func (*Button) WithSendLocation ¶
Sets whether the button must send owner's location.
type ButtonMap ¶
func (ButtonMap) LocationButton ¶
Returns the only location button in the map.
type CC ¶
type CC = ChannelContext
type ChannelAction ¶
type ChannelAction struct {
Act (*ChannelContext)
}
type ChannelContext ¶
type ChannelContext struct { }
The argument for handling in channenl behaviours.
type Command ¶
type Command struct { Name CommandName Type CommandType Description string Action Action Widget Widget }
func NewCommand ¶
func NewCommand(name CommandName, desc string) *Command
func (*Command) ActionFunc ¶
func (c *Command) ActionFunc(af ActionFunc) *Command
func (*Command) ToApi ¶
func (c *Command) ToApi() tgbotapi.BotCommand
func (*Command) WidgetFunc ¶
func (*Command) WithAction ¶
func (*Command) WithWidget ¶
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
func (*CommandCompo) WithCommands ¶
func (w *CommandCompo) WithCommands(cmds ...*Command) *CommandCompo
Set the commands to handle.
func (*CommandCompo) WithPreStart ¶
func (w *CommandCompo) WithPreStart(a Action) *CommandCompo
Set the prestart action.
func (*CommandCompo) WithPreStartFunc ¶
func (w *CommandCompo) WithPreStartFunc(fn ActionFunc) *CommandCompo
Set the prestart action with function.
func (*CommandCompo) WithUsage ¶
func (w *CommandCompo) WithUsage(a Action) *CommandCompo
Set the usage action.
func (*CommandCompo) WithUsageFunc ¶
func (w *CommandCompo) WithUsageFunc(fn ActionFunc) *CommandCompo
Set the usage action with function.
type CommandMap ¶
type CommandMap map[CommandName]*Command
type CommandName ¶
type CommandName string
type CommandType ¶
type CommandType uint8
const ( PrivateCommandType CommandType = iota GroupCommandType ChannelCommandType )
type Context ¶
type Context struct { // The update that called the Context usage. *Update // contains filtered or unexported fields }
Interface to interact with the user.
func (*Context) Copy ¶
Returns copy of current context so it will not affect the current one. But be careful because most of the insides uses pointers which are not deeply copied.
func (*Context) Input ¶
Get the input for current widget. Should be used inside handlers (aka "Serve").
func (*Context) ReadString ¶
Simple way to read strings for widgets.
func (*Context) RunWidget ¶
func (c *Context) RunWidget(widget Widget, args ...any) *UpdateChan
Run widget in background returning the new input channel for it.
func (*Context) Sendf ¶
Sends the formatted with fmt.Sprintf message to the user using default Markdown parsing format.
func (*Context) Skip ¶
Only for the root widget usage. Skip the update sending it down to the underlying widget.
func (*Context) WithInput ¶
func (c *Context) WithInput(input *UpdateChan) *Context
func (*Context) WithUpdate ¶
type ContextType ¶
type ContextType uint8
const ( NoContextType ContextType = iota WidgetContextType ActionContextType )
type File ¶
type File struct { *MessageCompo // contains filtered or unexported fields }
func (*File) NeedsUpload ¶
func (*File) SendConfig ¶
func (f *File) SendConfig( sid SessionId, bot *Bot, ) *SendConfig
type FilterFunc ¶
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.
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) SendConfig ¶
func (compo *InlineCompo) SendConfig( sid SessionId, bot *Bot, ) *SendConfig
Implementing the Sendable interface.
func (*InlineCompo) Serve ¶
func (widget *InlineCompo) Serve(c *Context)
Implementing the Server interface.
func (*InlineCompo) Update ¶
func (compo *InlineCompo) Update(c *Context)
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 // contains filtered or unexported fields }
The general keyboard type used both in Reply and Inline.
func NewKeyboard ¶
Returns the new keyboard with specified rows.
func (*Keyboard) ActionFunc ¶
func (kbd *Keyboard) ActionFunc(fn ActionFunc) *Keyboard
Alias to WithAction but better typing when setting a specific function
func (*Keyboard) WithAction ¶
Set the default action when no button provides key to the data we got.
type LocationCompo ¶
type LocationCompo struct { *MessageCompo Location }
func (*LocationCompo) SendConfig ¶
func (compo *LocationCompo) SendConfig( sid SessionId, bot *Bot, ) *SendConfig
type MessageCompo ¶
Simple text message component type.
func NewMessage ¶
func NewMessage(text string) *MessageCompo
Return new message with the specified text.
func (*MessageCompo) Filter ¶
func (compo *MessageCompo) Filter(_ *Update) bool
Filter that skips everything. Messages cannot do anything with updates.
func (*MessageCompo) HTML ¶
func (msg *MessageCompo) HTML() *MessageCompo
Set the HTML parsing mode.
func (*MessageCompo) Inline ¶
func (msg *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 (msg *MessageCompo) MD() *MessageCompo
Set the default Markdown parsing mode.
func (*MessageCompo) MD2 ¶
func (msg *MessageCompo) MD2() *MessageCompo
Set the Markdown 2 parsing mode.
func (*MessageCompo) Reply ¶
func (msg *MessageCompo) Reply(reply *Reply) *ReplyCompo
Transform the message component into one with reply keyboard.
func (*MessageCompo) SendConfig ¶
func (config *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)
Is only implemented to make it sendable and so we can put it return of rendering functions.
func (*MessageCompo) Update ¶
func (compo *MessageCompo) Update(c *Context)
type MessageMap ¶
type PhotoConfig ¶
type PhotoConfig = tgbotapi.PhotoConfig
type RenderFunc ¶
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) WithOneTime ¶
Set if the keyboard should be hidden after one of buttons is pressede.
func (*Reply) WithRemove ¶
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
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 ¶
The first node with the "/" path.
func NewRootNode ¶
Return new root node with the specified widget in the screen.
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.
type SendConfig ¶
type SendConfig struct { // The name will be used to store // the message in the map. Name string // Message with text and keyboard. Message *tgbotapi.MessageConfig // The image to be sent. Image *tgbotapi.PhotoConfig Location *tgbotapi.LocationConfig 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.
func (*SendConfig) WithName ¶
func (cfg *SendConfig) WithName(name string) *SendConfig
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 }
The type represents current state of user interaction per each of them.
func NewSession ¶
func NewSession(id SessionId, scope SessionScope) *Session
Return new empty session with specified user ID.
type SessionId ¶
type SessionId int64
Represents unique value to identify chats. In fact is simply ID of the chat.
type SessionMap ¶
The type represents map of sessions using as key.
func (SessionMap) Add ¶
func (sm SessionMap) Add(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.
type UpdateChan ¶
type UpdateChan struct {
// contains filtered or unexported fields
}
The type represents general update channel.
func (*UpdateChan) Chan ¶
func (updates *UpdateChan) Chan() chan *Update
func (*UpdateChan) Closed ¶
func (updates *UpdateChan) Closed() bool
Returns true if the channel is closed.
func (*UpdateChan) Read ¶
func (updates *UpdateChan) Read() *Update
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 WrongUpdateType ¶
type WrongUpdateType struct {
Type string
}
func (WrongUpdateType) Error ¶
func (wut WrongUpdateType) Error() string