telegrambot

package
v0.0.0-...-2db35d6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MPL-2.0 Imports: 15 Imported by: 0

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

type APIUpdates struct {
	OK      bool        `json:"ok"`
	Updates []APIUpdate `json:"result"`
}

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 (bot *Daemon) Initialise() error

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) ReplyTo

func (bot *Daemon) ReplyTo(chatID int64, text string) error

Send a text reply to the telegram chat.

func (*Daemon) StartAndBlock

func (bot *Daemon) StartAndBlock() error

Immediately begin processing incoming chat messages. Block caller indefinitely.

func (*Daemon) Stop

func (bot *Daemon) Stop()

Stop previously started message handling loop.

Jump to

Keyboard shortcuts

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