Documentation ¶
Index ¶
- type Conversation
- func (c *Conversation) ReplyToMessage(m string, messageID int) (api.Message, error)
- func (c *Conversation) SendMessage(m string) (api.Message, error)
- func (c *Conversation) SendMessageWithKeyboard(m string, keyboardOptions []string) (api.Message, error)
- func (c *Conversation) SendVideo(fileName string, file []byte) (api.Message, error)
- type Flow
- type FlowStep
- type Telego
- func (t *Telego) AddCommandHandler(c string, fs FlowStep)
- func (t *Telego) AddCommandHandlerSession(c string, fs FlowStep, ttl int32)
- func (t *Telego) AddKindHandler(k kind.Kind, fs FlowStep)
- func (t *Telego) AddKindHandlerSession(k kind.Kind, fs FlowStep, ttl int32)
- func (t *Telego) Listen()
- func (t *Telego) SetDefaultMessageHandler(f FlowStep)
- func (t *Telego) SetTelegramHost(tm string)
- func (t *Telego) SetupMetrics()
- type TelegramClient
- func (c *TelegramClient) ReplyToMessage(message string, chatID int, messageID int) (api.Message, error)
- func (c *TelegramClient) SendMessage(mo api.MessageOut) (api.Message, error)
- func (c *TelegramClient) SendMessageText(message string, chatID int) (api.Message, error)
- func (c *TelegramClient) SendMessageWithKeyboard(message string, chatID int, keyboardOptions []string) (api.Message, error)
- func (c *TelegramClient) SendVideo(fileName string, file []byte, chatID int) (api.Message, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conversation ¶
type Conversation struct { ChatID int // Chat ID to which we are storing the session Flow Flow // Flow that is going to be executed in this instance of he conversation Context map[string]interface{} // Context which is going to allow to the user store data which is going to be accessible from every step // contains filtered or unexported fields }
Conversation abstraction to make send messages to an specific chat.
func (*Conversation) ReplyToMessage ¶
ReplyToMessage replies to a message in the conversation.
func (*Conversation) SendMessage ¶
func (c *Conversation) SendMessage(m string) (api.Message, error)
SendMessage sends a message to the conversation
func (*Conversation) SendMessageWithKeyboard ¶
func (c *Conversation) SendMessageWithKeyboard(m string, keyboardOptions []string) (api.Message, error)
SendMessageWithKeyboard sends a message showing a list of options to the user as a custom keyboard
type Flow ¶
type Flow struct { ActualStep FlowStep // Step that has to be executed the next time that we receive an update TimeToLive int32 // Time to live of the session when executing this flow }
Flow has the information about the next step that has to be executed into the flow and the time to live for that flow.
type FlowStep ¶
type FlowStep func(api.Update, Conversation) FlowStep
FlowStep it accepts an update and a conversation and it returns the next step. In order to no execute any more steps, it has to return nil
type Telego ¶
type Telego struct { Client TelegramClient // Client allows send messages to Telegram chats // contains filtered or unexported fields }
Telego is the main struct on which we can define all the flows and handlers.
func Initialise ¶
Initialise inits the telegram instance with the telegram bot access token. See https://core.telegram.org/bots/api#authorizing-your-bot
func (*Telego) AddCommandHandler ¶ added in v0.1.2
AddCommandHandler adds the step that it is going to be executed when we receive a certain command
func (*Telego) AddCommandHandlerSession ¶ added in v0.1.2
AddCommandHandlerSession adds the step that it is going to be executed when we receive a message certain command, keeping the information that the handler saves for the time defined in ttl
func (*Telego) AddKindHandler ¶
AddKindHandler adds the step that it is going to be executed when we receive a message of a certain kind
func (*Telego) AddKindHandlerSession ¶
AddKindHandlerSession adds the step that it is going to be executed when we receive a message of a certain kind, keeping the information that the handler saves for the time defined in ttl
func (*Telego) Listen ¶
func (t *Telego) Listen()
Listen main loop which is going to be listening for updates.
func (*Telego) SetDefaultMessageHandler ¶
SetDefaultMessageHandler Sets the default message handler for the telegram bot. It defines what we are going to do with messages that by default the bot doesn't understand (eg. send a description of the commands)
func (*Telego) SetTelegramHost ¶
SetTelegramHost sets the telegram host where telegram is running
func (*Telego) SetupMetrics ¶
func (t *Telego) SetupMetrics()
SetupMetrics sets up the metrics for a telegram bot. It exposes metrics when the bot sends a message, when the bot receives a message and the sessions that the bot is keeping with chat information.
type TelegramClient ¶
type TelegramClient struct {
AccessToken string
}
TelegramClient manages the connection to the Telegram API
func (*TelegramClient) ReplyToMessage ¶
func (c *TelegramClient) ReplyToMessage(message string, chatID int, messageID int) (api.Message, error)
ReplyToMessage sends a message to a chat replying to the indicated message.
func (*TelegramClient) SendMessage ¶
func (c *TelegramClient) SendMessage(mo api.MessageOut) (api.Message, error)
SendMessage sends a message with the filled MessageOut object.
func (*TelegramClient) SendMessageText ¶
SendMessageText sends the given message to the given chat ID
func (*TelegramClient) SendMessageWithKeyboard ¶
func (c *TelegramClient) SendMessageWithKeyboard(message string, chatID int, keyboardOptions []string) (api.Message, error)
SendMessageWithKeyboard sends a message showing a list of options to the user as a custom keyboard