bot

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 20 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 {
	// contains filtered or unexported fields
}

func NewBot

func NewBot(logger *slog.Logger, api telegram.BotAPI, cfg *config.Config, userRepo storage.UserRepository, msgRepo storage.MessageRepository, statsRepo storage.StatsRepository, logRepo storage.LogRepository, factRepo storage.FactRepository, factHistoryRepo storage.FactHistoryRepository, orClient openrouter.Client, speechKitClient yandex.Client, ragService *rag.Service, translator *i18n.Translator) (*Bot, error)

func (*Bot) API

func (b *Bot) API() telegram.BotAPI

func (*Bot) HandleUpdate

func (b *Bot) HandleUpdate(ctx context.Context, rawUpdate json.RawMessage, remoteAddr string)

func (*Bot) ProcessUpdate

func (b *Bot) ProcessUpdate(ctx context.Context, update *telegram.Update, source string)

func (*Bot) SetWebhook

func (b *Bot) SetWebhook(webhookURL string) error

func (*Bot) Stop

func (b *Bot) Stop()

type Chat

type Chat struct {
	ID       int64  `json:"id"`
	Type     string `json:"type"`
	Title    string `json:"title"`
	Username string `json:"username"`
}

Chat represents a chat.

type Document

type Document struct {
	FileID       string     `json:"file_id"`
	FileUniqueID string     `json:"file_unique_id"`
	Thumbnail    *PhotoSize `json:"thumbnail,omitempty"`
	FileName     string     `json:"file_name,omitempty"`
	MimeType     string     `json:"mime_type,omitempty"`
	FileSize     int        `json:"file_size,omitempty"`
}

Document represents a general file (as opposed to photos, voice messages and audio files).

type Message

type Message struct {
	MessageID        int            `json:"message_id"`
	From             *User          `json:"from"`
	Chat             *Chat          `json:"chat"`
	Date             int            `json:"date"`
	Text             string         `json:"text"`
	Caption          string         `json:"caption"`
	Photo            []PhotoSize    `json:"photo"`
	Document         *Document      `json:"document"`
	Voice            *Voice         `json:"voice"`
	ForwardOrigin    *MessageOrigin `json:"forward_origin"`
	IsCommand        bool           `json:"-"` // This will be determined manually
	Command          string         `json:"-"` // This will be determined manually
	CommandArguments string         `json:"-"` // This will be determined manually
}

Message represents a message.

type MessageGroup

type MessageGroup struct {
	Messages   []*telegram.Message
	Timer      *time.Timer
	CancelFunc context.CancelFunc
	UserID     int64
}

MessageGroup represents a collection of messages from a single user that are processed together.

type MessageGrouper

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

MessageGrouper handles the grouping of incoming messages from users.

func NewMessageGrouper

func NewMessageGrouper(b *Bot, logger *slog.Logger, turnWait time.Duration, onGroupReady func(ctx context.Context, group *MessageGroup)) *MessageGrouper

NewMessageGrouper creates a new MessageGrouper.

func (*MessageGrouper) AddMessage

func (mg *MessageGrouper) AddMessage(msg *telegram.Message)

AddMessage adds a new message to a user's group.

type MessageOrigin

type MessageOrigin struct {
	Type            string `json:"type"`
	Date            int    `json:"date"`
	SenderUser      *User  `json:"sender_user,omitempty"`
	SenderUserName  string `json:"sender_user_name,omitempty"`
	SenderChat      *Chat  `json:"sender_chat,omitempty"`
	AuthorSignature string `json:"author_signature,omitempty"`
	MessageID       int    `json:"message_id,omitempty"`
}

MessageOrigin is a union type that can be one of MessageOriginUser, MessageOriginHiddenUser, MessageOriginChat, or MessageOriginChannel.

func (*MessageOrigin) UnmarshalJSON

func (mo *MessageOrigin) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom unmarshaler for MessageOrigin to handle the union type.

type PhotoSize

type PhotoSize struct {
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	Width        int    `json:"width"`
	Height       int    `json:"height"`
	FileSize     int    `json:"file_size,omitempty"`
}

PhotoSize represents one size of a photo or a file / sticker thumbnail.

type ReactionType

type ReactionType struct {
	Type  string `json:"type"`
	Emoji string `json:"emoji,omitempty"`
}

ReactionType represents a reaction type.

type SetMessageReactionConfig

type SetMessageReactionConfig struct {
	ChatID    int64
	MessageID int
	Reaction  []ReactionType
	IsBig     bool
}

SetMessageReactionConfig contains information about a reaction to be set on a message.

func (SetMessageReactionConfig) Method

func (config SetMessageReactionConfig) Method() string

Method returns the method name for the SetMessageReaction method.

func (SetMessageReactionConfig) Params

func (config SetMessageReactionConfig) Params() (map[string]string, error)

Params returns a map of parameters for the SetMessageReaction method.

type Update

type Update struct {
	UpdateID int      `json:"update_id"`
	Message  *Message `json:"message"`
}

Update is a Telegram object that represents an incoming update.

type User

type User struct {
	ID        int64  `json:"id"`
	IsBot     bool   `json:"is_bot"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	UserName  string `json:"username"`
}

User represents a Telegram user or bot.

type Voice

type Voice struct {
	FileID       string `json:"file_id"`
	FileUniqueID string `json:"file_unique_id"`
	Duration     int    `json:"duration"`
	MimeType     string `json:"mime_type,omitempty"`
	FileSize     int    `json:"file_size,omitempty"`
}

Voice represents a voice note.

Jump to

Keyboard shortcuts

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