Documentation ¶
Index ¶
- type Bot
- func (bot *Bot) DeleteMessage(chatID int64, messageID int) error
- func (bot *Bot) Do() error
- func (bot *Bot) GetUserEmail(userID int) (email string, ok bool)
- func (bot *Bot) Help() string
- func (bot *Bot) LoadConfig() error
- func (bot *Bot) NewMessageResponseOpt() MessageResponseOpt
- func (bot *Bot) ParseUserID(s string, mustExists bool) int
- func (bot *Bot) ProcessCommand(handler MessageHandler, command string, params []string) (bool, error)
- func (bot *Bot) ProcessMessage(handler MessageHandler, text string) (bool, error)
- func (bot *Bot) ProcessUpdate(update tgbotapi.Update) (bool, error)
- func (bot *Bot) RegisterConfig(scope string, configData interface{})
- func (bot *Bot) RegisterProcessor(name string, processor Processor, configData interface{})
- func (bot *Bot) SaveConfig()
- func (bot *Bot) SaveConfigNow() error
- func (bot *Bot) SendMessageResponse(handler MessageHandler, text string, opt MessageResponseOpt)
- func (bot *Bot) SendMessageResponseToPrivate(handler MessageHandler, text string, opt MessageResponseOpt)
- func (bot *Bot) Version() string
- type MessageHandler
- type MessageResponseOpt
- type Processor
- type StubProcessor
- func (p *StubProcessor) Help() string
- func (p *StubProcessor) ProcessCommand(handler MessageHandler, command string, params []string) (bool, error)
- func (p *StubProcessor) ProcessMessage(handler MessageHandler, text string) (bool, error)
- func (p *StubProcessor) ProcessUpdate(update tgbotapi.Update) (bool, error)
- func (p *StubProcessor) Version() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct { Debug bool Verbose bool Tgbot *tgbotapi.BotAPI // contains filtered or unexported fields }
Bot - incapsula lo stack di Telegram
func (*Bot) LoadConfig ¶
LoadConfig - carica le impostazioni. Se non viene invocata esternamente ci pensa comunque bot.Do()
func (*Bot) NewMessageResponseOpt ¶
func (bot *Bot) NewMessageResponseOpt() MessageResponseOpt
NewMessageResponseOpt resituisce un MessageResponse con valori inizializzati
func (*Bot) ParseUserID ¶
ParseUserID ritorna l'ID utente specificato dalla stringa in input. Se numerico lo ritorna tale e quale (mustExists verifica che l'utente esista nel DB interno). Se "username" o "@username" cerca l'utente corrispondente nel DB interno.
func (*Bot) ProcessCommand ¶
func (*Bot) ProcessMessage ¶
func (bot *Bot) ProcessMessage(handler MessageHandler, text string) (bool, error)
func (*Bot) RegisterConfig ¶
func (*Bot) RegisterProcessor ¶
RegisterProcessor aggiunge un processor al bot, estendendone le funzionalità
func (*Bot) SaveConfig ¶
func (bot *Bot) SaveConfig()
SaveConfig - può essere invocata spesso dato che utilizza l'antibounce
func (*Bot) SaveConfigNow ¶
SaveConfigNow - salva immediatamente le impostazioni
func (*Bot) SendMessageResponse ¶
func (bot *Bot) SendMessageResponse(handler MessageHandler, text string, opt MessageResponseOpt)
SendMessageResponse invia un messaggio di risposta all'handler
func (*Bot) SendMessageResponseToPrivate ¶
func (bot *Bot) SendMessageResponseToPrivate(handler MessageHandler, text string, opt MessageResponseOpt)
SendMessageResponseToPrivate invia un messaggio di risposta all'handler forzandolo in chat privata
type MessageHandler ¶
type MessageHandler struct { UserID int Username string Group userGroup ChatID int64 IsPrivate bool MessageID int // messaggio a cui appartiene il comando EditMessageID int // se > 0 messaggio da editare anzichè inviarne uno nuovo ReplyUserID int // utente del messaggio a cui si è risposto ReplyUsername string }
MessageHandler contiene i riferimenti utili all'invio messaggi dai metodi di processing
type MessageResponseOpt ¶
type MessageResponseOpt struct { ForcePrivate bool ReplyToSenderMessage bool ReplaceSenderMessage bool LinksPreview bool HTMLformat bool KeyboardInline *tgbotapi.InlineKeyboardMarkup KeyboardReply *tgbotapi.ReplyKeyboardMarkup }
MessageResponseOpt contiene i flag di modalità di risposta
type Processor ¶
type Processor interface { Help() string Version() string // Restituiscono true quando il comando o messaggio è stato effettivamente processato ProcessUpdate(update tgbotapi.Update) (bool, error) ProcessCommand(handler MessageHandler, command string, params []string) (bool, error) ProcessMessage(handler MessageHandler, text string) (bool, error) }
Processor implementa i metodi per processare comandi e messaggi semplici
type StubProcessor ¶
type StubProcessor struct { }
StubProcessor implementa tutti i metodi di Processor ma con funzioni vuote, pronte per l'override
func (*StubProcessor) Help ¶
func (p *StubProcessor) Help() string
func (*StubProcessor) ProcessCommand ¶
func (p *StubProcessor) ProcessCommand(handler MessageHandler, command string, params []string) (bool, error)
func (*StubProcessor) ProcessMessage ¶
func (p *StubProcessor) ProcessMessage(handler MessageHandler, text string) (bool, error)
func (*StubProcessor) ProcessUpdate ¶
func (p *StubProcessor) ProcessUpdate(update tgbotapi.Update) (bool, error)
func (*StubProcessor) Version ¶
func (p *StubProcessor) Version() string