Documentation ¶
Index ¶
- Variables
- func AccessDenied(m *Message)
- type DefaultMux
- func (dm *DefaultMux) DefaultHandler() *Handler
- func (dm *DefaultMux) FileHandler() *Handler
- func (dm *DefaultMux) HandleDefault(handler HandlerFunction, description ...string)
- func (dm *DefaultMux) HandleFile(handler HandlerFunction, description ...string)
- func (dm *DefaultMux) HandleFunc(path string, handler HandlerFunction, description ...string)
- func (dm *DefaultMux) Handlers() Handlers
- func (dm *DefaultMux) Mux(msg *Message) (*Handler, MessageVars)
- type Handler
- type HandlerFunction
- type Handlers
- type KeyboardOption
- type Message
- func (m *Message) Download(dir string) error
- func (m *Message) Reply(reply string, options ...Option)
- func (m *Message) ReplyAudio(filepath string)
- func (m *Message) ReplyDocument(filepath string)
- func (m *Message) ReplyKeyboard(text string, buttons [][]string, options ...KeyboardOption)
- func (m *Message) ReplyPhoto(filepath string, caption ...string)
- func (m *Message) ReplySticker(filepath string)
- func (m *Message) Replyf(reply string, values ...interface{})
- func (m *Message) Text() string
- type MessageVars
- type Middleware
- type Mux
- type Option
- type Server
- func (s *Server) AddMiddleware(mid Middleware)
- func (s *Server) Handle(path string, reply string, description ...string)
- func (s *Server) HandleDefault(handler HandlerFunction, description ...string)
- func (s *Server) HandleFile(handler HandlerFunction, description ...string)
- func (s *Server) HandleFunc(path string, handler HandlerFunction, description ...string)
- func (s *Server) HelpHandler(m *Message)
- func (s *Server) ListenAndServe() error
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
var DisablePreview = func(msg *adapter.Message) { msg.DisablePreview = true }
var OneTimeKeyboard = func(msg *adapter.Message) { msg.OneTimeKeyboard = true }
var WithMarkdown = func(msg *adapter.Message) { msg.Markdown = true }
Functions ¶
func AccessDenied ¶
func AccessDenied(m *Message)
Types ¶
type DefaultMux ¶
type DefaultMux struct {
// contains filtered or unexported fields
}
DefaultMux is a default multiplexer, supports parametrized commands. Parameters should be enclosed with curly brackets, like in "/say {hi}" - "hi" is a parameter.
func (*DefaultMux) DefaultHandler ¶
func (dm *DefaultMux) DefaultHandler() *Handler
DefaultHandler returns default handler, nil if it's not set
func (*DefaultMux) FileHandler ¶
func (dm *DefaultMux) FileHandler() *Handler
func (*DefaultMux) HandleDefault ¶
func (dm *DefaultMux) HandleDefault(handler HandlerFunction, description ...string)
HandleDefault adds new default handler, when nothing matches with message, "description" is for "/help" handler.
func (*DefaultMux) HandleFile ¶
func (dm *DefaultMux) HandleFile(handler HandlerFunction, description ...string)
func (*DefaultMux) HandleFunc ¶
func (dm *DefaultMux) HandleFunc(path string, handler HandlerFunction, description ...string)
HandleFunc adds new handler function to mux, "description" is for "/help" handler.
func (*DefaultMux) Handlers ¶
func (dm *DefaultMux) Handlers() Handlers
Handlers returns list of handlers currently presented in mux
func (*DefaultMux) Mux ¶
func (dm *DefaultMux) Mux(msg *Message) (*Handler, MessageVars)
Mux takes message content and returns corresponding handler and parsed vars from message
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a struct that represents any message handler with handler function, descriptio, pattern and parsed variables
type HandlerFunction ¶
type HandlerFunction func(*Message)
HandlerFunction is a function that can process incoming messages
type KeyboardOption ¶
type Message ¶
type Message struct { *adapter.Message Vars MessageVars }
Message is a received message from chat, with parsed variables
func (*Message) ReplyAudio ¶
ReplyAudio sends audio file to chat
func (*Message) ReplyDocument ¶
ReplyDocument sends generic file (not audio, voice, image) to the chat
func (*Message) ReplyKeyboard ¶
func (m *Message) ReplyKeyboard(text string, buttons [][]string, options ...KeyboardOption)
func (*Message) ReplyPhoto ¶
ReplyPhoto sends photo to the chat. Has optional caption.
func (*Message) ReplySticker ¶
ReplySticker sends sticker to the chat.
type MessageVars ¶
MessageVars is a parsed message variables lookup table
type Middleware ¶
type Middleware func(HandlerFunction) HandlerFunction
func NewAuth ¶
func NewAuth(whitelist []string) Middleware
type Mux ¶
type Mux interface { Mux(*Message) (*Handler, MessageVars) HandleFunc(string, HandlerFunction, ...string) HandleFile(HandlerFunction, ...string) HandleDefault(HandlerFunction, ...string) Handlers() Handlers DefaultHandler() *Handler FileHandler() *Handler }
Mux interface represents message multiplexer
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a telegram bot server. Looks and feels like net/http.
func NewServer ¶
func NewServer(token string, options ...ServerOption) (*Server, error)
NewServer creates new Server with Telegram API Token and default /help handler
func (*Server) AddMiddleware ¶
func (s *Server) AddMiddleware(mid Middleware)
func (*Server) Handle ¶
Handle is a shortcut for HandleFunc to reply just with static text, "description" is for "/help" handler.
func (*Server) HandleDefault ¶
func (s *Server) HandleDefault(handler HandlerFunction, description ...string)
HandleDefault delegates HandleDefault to the current Mux
func (*Server) HandleFile ¶
func (s *Server) HandleFile(handler HandlerFunction, description ...string)
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(path string, handler HandlerFunction, description ...string)
HandleFunc delegates HandleFunc to the current Mux
func (*Server) HelpHandler ¶
HelpHandler is a default handler for /help, shows available commands and their description
func (*Server) ListenAndServe ¶
ListenAndServe starts Server, returns error on failure
type ServerOption ¶
type ServerOption func(*Server)
func WithMux ¶
func WithMux(m Mux) ServerOption
func WithWebhook ¶
func WithWebhook(url string, addr string) ServerOption