Documentation ¶
Index ¶
- Variables
- func Escape2(str string) string
- type Action
- type ActionFunc
- type Behaviour
- type Bot
- func (bot *Bot) Api() *tgbotapi.BotAPI
- func (bot *Bot) Data() any
- func (bot *Bot) DeleteCommands()
- func (bot *Bot) GotSession(sid SessionId) (*Session, bool)
- func (bot *Bot) Me() User
- 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) Sendf(sid SessionId, format string, v ...any) (*Message, error)
- func (b *Bot) SetBehaviour(beh *Behaviour) *Bot
- func (bot *Bot) SetCommands(scope tgbotapi.BotCommandScope, cmdMap CommandMap) error
- func (bot *Bot) SetData(v any) *Bot
- func (bot *Bot) SetDebug(debug bool) *Bot
- func (b *Bot) SetSessions(sessions SessionMap) *Bot
- type Button
- func (btn Button) Go(pth Path) Button
- func (btn Button) GoWithArg(pth Path, arg any) Button
- func (btn Button) Key() string
- func (btn Button) Rand() Button
- 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(format string, v ...any) Button
- type ButtonMap
- type ButtonRow
- type Chat
- type Command
- type CommandCompo
- type CommandMap
- type CommandName
- type CommandType
- type Component
- type Context
- func (c Context) Arg() any
- func (c Context) As(sid SessionId) (Context, bool)
- func (c Context) Bot() *Bot
- func (c Context) CallbackUpdate() *Update
- func (c Context) GetFile(fileId FileId) (io.ReadCloser, string, error)
- func (c Context) Go(pth Path) error
- func (c Context) GoWithArg(pth Path, arg any) error
- func (c Context) Input() chan Update
- func (c Context) Path() Path
- func (c Context) PathExist(pth Path) bool
- func (c Context) PathHistory() []Path
- func (c Context) ReadFile(fileId FileId) ([]byte, string, error)
- func (c Context) ReadString(promptf string, args ...any) string
- func (c Context) Run(a Action)
- 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) SendfR(format string, v ...any) (*Message, error)
- func (c Context) Session() Session
- func (c Context) SessionData() any
- func (c Context) SessionId() SessionId
- func (c Context) SessionScope() SessionScope
- func (c Context) SetSessionData(v any)
- func (c Context) SkipUpdate(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 File
- func (f *File) Caption(caption string) *File
- func (f *File) Data(data string) *File
- func (f *File) Document() *File
- func (f *File) Name(name string) *File
- func (f *File) NeedsUpload() bool
- func (f *File) Photo() *File
- func (f *File) SendConfig(sid SessionId, bot *Bot) SendConfig
- func (f *File) SendData() string
- func (f *File) Type() FileType
- func (f *File) Upload(upload bool) *File
- func (f *File) UploadData() (string, io.Reader, error)
- type FileConfig
- type FileId
- type FileType
- type FilterFunc
- type Filterer
- type Func
- type GoWidget
- type Inline
- type InlineCompo
- type InvoiceCompo
- type Keyboard
- func (kbd Keyboard) ButtonMap() ButtonMap
- func (kbd Keyboard) Inline() Inline
- func (kbd Keyboard) List(btns ...Button) Keyboard
- func (kbd Keyboard) MakeButtonMap() ButtonMap
- func (kbd *Keyboard) RemoveRow(i int)
- func (kbd Keyboard) Reply() Reply
- func (kbd Keyboard) Row(btns ...Button) Keyboard
- func (kbd Keyboard) RowNum() int
- func (kbd Keyboard) WithAction(a Action) Keyboard
- type Location
- type LocationCompo
- type Maker
- type Message
- type MessageCompo
- func (compo *MessageCompo) Delete(c Context) error
- func (compo *MessageCompo) Filter(_ Update) bool
- func (compo *MessageCompo) HTML() *MessageCompo
- func (compo *MessageCompo) Inline(inline Inline) *InlineCompo
- func (msg *MessageCompo) Location(lat, long float64) *LocationCompo
- func (compo *MessageCompo) MD() *MessageCompo
- func (compo *MessageCompo) MD2() *MessageCompo
- func (compo *MessageCompo) Panel(c Context, rowser Rowser) *PanelCompo
- func (msg *MessageCompo) Reply(reply Reply) *ReplyCompo
- func (compo *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) error
- type MessageId
- type MessageMap
- type Node
- type PanelCompo
- type Path
- type PhotoConfig
- type Poll
- type PollCompo
- type RenderFunc
- type Reply
- type ReplyCompo
- type RootNode
- type Rowser
- type RowserFunc
- 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") 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") )
var (
NewRawMessage = tgbotapi.NewMessage
)
var (
UnknownFileTypeErr = errors.New("unknown file type")
)
Functions ¶
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) SetInit ¶ added in v0.16.0
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
Sets the root node of the Behaviour. Mostly used for commands and such stuff.
func (*Behaviour) SetRootWidget ¶ added in v0.16.0
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 (*Bot) DeleteCommands ¶
func (bot *Bot) DeleteCommands()
func (*Bot) GotSession ¶ added in v0.16.0
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) SetBehaviour ¶ added in v0.16.0
func (*Bot) SetCommands ¶
func (bot *Bot) SetCommands( scope tgbotapi.BotCommandScope, cmdMap CommandMap, ) error
Setting the command on the user side.
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 (Button) Rand ¶
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 ¶
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 ¶
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) ToApi ¶
func (c Command) ToApi() tgbotapi.BotCommand
Convert command into the tgbotapi.BotCommand
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
Filtering all the non commands.
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 Context ¶
type Context struct {
// contains filtered or unexported fields
}
Interface to interact with the user.
func (Context) As ¶
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) CallbackUpdate ¶ added in v0.16.0
func (Context) GoWithArg ¶ added in v0.16.0
Changes screen of user to the Id one. Also gives the arg to the widget calling contexts.
func (Context) Input ¶
Get the input for current widget. Should be used inside handlers (aka "Serve").
func (Context) PathHistory ¶ added in v0.16.0
Return context's session's path history.
func (Context) ReadString ¶
Simple way to read strings for widgets with the specified prompt.
func (Context) Sendf ¶
Sends the formatted with fmt.Sprintf message to the user using default Markdown parsing format.
func (Context) SessionData ¶ added in v0.16.0
func (Context) SessionScope ¶ added in v0.16.0
func (c Context) SessionScope() SessionScope
func (Context) SetSessionData ¶ added in v0.16.0
func (Context) SkipUpdate ¶ added in v0.16.0
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 }
The type implements the structure to easily send files to the client.
func NewFile ¶
Create the new file with the specified reader. By default it NeedsUpload is set to true.
func (*File) NeedsUpload ¶
func (*File) SendConfig ¶
func (f *File) SendConfig( sid SessionId, bot *Bot, ) SendConfig
type FileConfig ¶
type FileConfig = tgbotapi.FileConfig
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) 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 ¶
Returns the new keyboard with specified rows.
func (Keyboard) ButtonMap ¶
Returns the map of buttons. Where the key is button data and the value is Action.
func (Keyboard) MakeButtonMap ¶
Returns the map of buttons on the most fresh version of the keyboard.
func (Keyboard) Reply ¶
Convert the keyboard to the more specific reply one. By default OneTime = true.
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 ¶
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 MessageMap ¶
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 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
Implementing the Server interface.
func (*ReplyCompo) SendConfig ¶
func (compo *ReplyCompo) SendConfig( sid SessionId, bot *Bot, ) SendConfig
Implementing the sendable interface.
type RootNode ¶
The first node with the "/" path.
func NewRootNode ¶
Return new root node with the specified widget in the screen.
type RowserFunc ¶
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.
type SendConfig ¶
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.
type SessionMap ¶
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.
type Update ¶
func (Update) DocumentId ¶
func (Update) DocumentMimeType ¶
func (*Update) DocumentName ¶
func (Update) DocumentSize ¶
func (Update) HasDocument ¶
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, 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 WrongUpdateType ¶
type WrongUpdateType struct {
Type string
}
func (WrongUpdateType) Error ¶
func (wut WrongUpdateType) Error() string