Documentation ¶
Index ¶
Constants ¶
View Source
const ( ChatTypePrivate = "private" // Name of the private chat type APICallTimeoutSec = 30 // Outgoing API calls are constrained by this timeout CommandTimeoutSec = 30 // Command execution is constrained by this timeout /* PollIntervalSecMin and PollIntervalSecMax together determine the range of random number of seconds to wait between each message polling attempt. The randomness helps multiple laitos instances to poll messages simultaneously without starving any specific instance. */ PollIntervalSecMin = 2 PollIntervalSecMax = 5 )
Variables ¶
This section is empty.
Functions ¶
func TestTelegramBot ¶
func TestTelegramBot(bot *Daemon, t testingstub.T)
Run unit tests on telegram bot. See TestSMTPD_StartAndBlock for bot setup.
Types ¶
type APIChat ¶
type APIChat struct { ID int64 `json:"id"` FirstName string `json:"first_name"` LastName string `json:"last_name"` UserName string `json:"username"` Type string `json:"type"` }
Telegram API entity - chat
type APIMessage ¶
type APIMessage struct { ID int64 `json:"message_id"` From APIUser `json:"from"` Chat APIChat `json:"chat"` Timestamp int64 `json:"date"` Text string `json:"text"` }
Telegram API entity - message
type APIUpdate ¶
type APIUpdate struct { ID int64 `json:"update_id"` Message APIMessage `json:"message"` }
Telegram API entity - one bot update
type APIUpdates ¶
Telegram API entity - getUpdates response
type APIUser ¶
type APIUser struct { ID int64 `json:"id"` FirstName string `json:"first_name"` LastName string `json:"last_name"` UserName string `json:"username"` }
Telegram API entity - user
type Daemon ¶
type Daemon struct { AuthorizationToken string `json:"AuthorizationToken"` // Telegram bot API auth token PerUserLimit int `json:"PerUserLimit"` // PerUserLimit determines how many messages may be processed per chat at regular interval Processor *toolbox.CommandProcessor `json:"-"` // Feature command processor // contains filtered or unexported fields }
Process feature commands from incoming telegram messages, reply to the chats with command results.
func (*Daemon) Initialise ¶
func (*Daemon) ProcessMessages ¶
func (bot *Daemon) ProcessMessages(ctx context.Context, updates APIUpdates)
Process incoming chat messages and reply command results to chat initiators.
func (*Daemon) StartAndBlock ¶
Immediately begin processing incoming chat messages. Block caller indefinitely.
Click to show internal directories.
Click to hide internal directories.