telegram

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 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 Chat

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

Chat represents a Telegram chat.

type Client

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

Client is a Telegram Bot API client.

func New

func New(token string) *Client

New creates a Telegram client with the given bot token.

func (*Client) AckUpdate

func (c *Client) AckUpdate(ctx context.Context, updateID int) error

AckUpdate acknowledges all updates up to and including updateID by calling getUpdates with offset = updateID + 1. This permanently removes those updates from the pending queue.

func (*Client) GetUpdate

func (c *Client) GetUpdate(ctx context.Context, updateID int) (*Update, error)

GetUpdate fetches all pending updates and returns the one matching updateID. Returns an error if the update is not found among pending updates.

func (*Client) GetUpdates

func (c *Client) GetUpdates(ctx context.Context, limit int) ([]Update, error)

GetUpdates fetches pending updates from the Telegram Bot API. It does not pass an offset, so this is a read-only peek at pending messages.

func (*Client) SendMessage added in v0.13.0

func (c *Client) SendMessage(ctx context.Context, chatID int64, text string) error

SendMessage sends a text message to the given chat via the Telegram Bot API.

func (*Client) SetHTTPDoer

func (c *Client) SetHTTPDoer(doer apiclient.HTTPDoer)

SetHTTPDoer replaces the HTTP client used for API requests.

type Config

type Config struct {
	Name         string  `mapstructure:"name"`
	Token        string  `mapstructure:"token"`
	Description  string  `mapstructure:"description"`
	AllowedUsers []int64 `mapstructure:"allowed_users"`
}

Config holds the configuration for a single Telegram bot instance.

func LoadConfigs

func LoadConfigs(dir string) ([]Config, error)

LoadConfigs reads a .humanconfig YAML file from dir and returns the list of configured Telegram instances. Returns nil and no error if the file does not exist.

type Instance

type Instance struct {
	Name         string
	Description  string
	Client       *Client
	AllowedUsers []int64
}

Instance represents a configured Telegram bot ready for use.

func LoadInstances

func LoadInstances(dir string) ([]Instance, error)

LoadInstances reads config, applies env overrides, creates clients, and returns ready-to-use Telegram instances.

type Message

type Message struct {
	MessageID int    `json:"message_id"`
	From      *User  `json:"from,omitempty"`
	Chat      Chat   `json:"chat"`
	Date      int64  `json:"date"`
	Text      string `json:"text"`
}

Message represents a Telegram message.

type MessageDetail

type MessageDetail struct {
	UpdateID  int    `json:"update_id"`
	MessageID int    `json:"message_id"`
	From      string `json:"from"`
	FromID    int64  `json:"from_id"`
	Username  string `json:"username"`
	ChatID    int64  `json:"chat_id"`
	ChatType  string `json:"chat_type"`
	Date      string `json:"date"`
	Text      string `json:"text"`
}

MessageDetail is the CLI output type for the get command.

type MessageSummary

type MessageSummary struct {
	UpdateID  int    `json:"update_id"`
	MessageID int    `json:"message_id"`
	From      string `json:"from"`
	Date      string `json:"date"`
	Text      string `json:"text"`
}

MessageSummary is the CLI output type for the list command.

type Update

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

Update represents a single update from the Telegram Bot API.

type User

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

User represents a Telegram user.

Jump to

Keyboard shortcuts

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