easierbot

package module
v0.0.0-...-b111301 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	API              *tgbotapi.BotAPI
	Handlers         *MessagesHandlers
	Data             interface{} // this attribute is for data storage
	MessageParseMode string
	// contains filtered or unexported fields
}

Bot is the main object of the bot.

func NewBot

func NewBot(token string, debug bool) *Bot

NewBot is constructor of the Bot structure

func NewBotViaWebhook

func NewBotViaWebhook(token, webhookSite, listenAddr string, debug bool) *Bot

func (*Bot) RunBotServer

func (bot *Bot) RunBotServer()

RunBotServer runs listening webhook and updates. It needs running after set handlers.

func (*Bot) SendMessage

func (bot *Bot) SendMessage(chatID int64, message string)

SendMessage is a simple method of sending simple messages by chatId

type MessageHandler

type MessageHandler func(bot *Bot, msg *tgbotapi.Message)

MessageHandler is a function for handling a bot message

type MessagesHandlers

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

MessagesHandlers contains all handlers of messages

func NewMessagesHandlers

func NewMessagesHandlers() *MessagesHandlers

func (*MessagesHandlers) AddCommandHandler

func (h *MessagesHandlers) AddCommandHandler(command string, handler MessageHandler)

AddCommandHandler sets a handler under a command. The handler runs when the update listener got this command.

func (*MessagesHandlers) AddRegexpHandler

func (h *MessagesHandlers) AddRegexpHandler(expr string, handler MessageHandler)

AddRegexpHandler sets a handler under a regular expression. The handler runs when the update listener got this text which has a regexp match.

func (*MessagesHandlers) AddSeveralCommandsHandler

func (h *MessagesHandlers) AddSeveralCommandsHandler(commands []string, handler MessageHandler)

AddSeveralCommandsHandler sets a handler under several commands. The handler runs when the update listener got this commands

func (*MessagesHandlers) SetContentHandler

func (h *MessagesHandlers) SetContentHandler(contentType contentType.ContentType, handler MessageHandler)

SetContentHandler sets handler which will be executed if a message has another type of content.

func (*MessagesHandlers) SetDefaultHandler

func (h *MessagesHandlers) SetDefaultHandler(handler MessageHandler)

SetDefaultHandler sets handler which will be executed in other cases.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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