tg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tg wraps the Telegram client with the rate limits and retries the bot needs. Every outgoing API call goes through here so the limits live in one place instead of being sprinkled over the bridge logic.

Index

Constants

View Source
const (
	// PollTimeout is the long polling window asked of Telegram.
	PollTimeout = 50 * time.Second
)

Variables

This section is empty.

Functions

func IsBlocked

func IsBlocked(err error) bool

IsBlocked reports whether the client has blocked the bot (or deleted their account), which makes delivery impossible until they write again.

func IsNotModified

func IsNotModified(err error) bool

IsNotModified reports an edit that changed nothing, which Telegram rejects but which is not a failure for us.

func IsThreadNotFound

func IsThreadNotFound(err error) bool

IsThreadNotFound reports whether the topic is gone — normally because somebody deleted it by hand in the group.

func IsTopicClosed

func IsTopicClosed(err error) bool

IsTopicClosed reports whether the topic is closed for posting.

Types

type Client

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

Client is the rate limited, retrying facade over the Bot API.

func New

func New(api *bot.Bot, groupID int64, log *slog.Logger) *Client

New builds a client for the given bot and support group.

func (*Client) API

func (c *Client) API() *bot.Bot

API exposes the raw client for calls that need no limiting.

func (*Client) CloseTopic

func (c *Client) CloseTopic(ctx context.Context, threadID int) error

CloseTopic closes a topic without deleting it or its binding.

func (*Client) Copy

func (c *Client) Copy(ctx context.Context, toChatID int64, toThreadID int, fromChatID int64, messageID int) (int, error)

Copy relays a message with copyMessage and returns the id of the copy. forwardMessage is deliberately not used: a forward depends on the sender's privacy settings and can arrive without attribution, and it would leak the operator's account to the client.

func (*Client) CreateTopic

func (c *Client) CreateTopic(ctx context.Context, name string) (int, error)

CreateTopic opens a forum topic in the support group.

func (*Client) EditCaption

func (c *Client) EditCaption(ctx context.Context, chatID int64, messageID int, caption string) error

EditCaption edits the caption of a media message the bot sent earlier.

func (*Client) EditText

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

EditText edits the text of a message the bot sent earlier.

func (*Client) GetChat

func (c *Client) GetChat(ctx context.Context, chatID int64) (*models.ChatFullInfo, error)

GetChat reads the support group, used for the start-up preconditions.

func (*Client) GetChatMember

func (c *Client) GetChatMember(ctx context.Context, chatID, userID int64) (*models.ChatMember, error)

GetChatMember reads a membership, used to verify the bot's own rights.

func (*Client) GetMe

func (c *Client) GetMe(ctx context.Context) (*models.User, error)

GetMe returns the bot account, used for the start-up preconditions.

func (*Client) GroupID

func (c *Client) GroupID() int64

GroupID is the support supergroup this client writes to.

func (*Client) Pin

func (c *Client) Pin(ctx context.Context, chatID int64, messageID int) error

Pin pins a message, used for the client card at the top of a topic.

func (*Client) ReopenTopic

func (c *Client) ReopenTopic(ctx context.Context, threadID int) error

ReopenTopic reopens a topic closed earlier by /close.

func (*Client) SendHTML

func (c *Client) SendHTML(ctx context.Context, chatID int64, threadID, replyTo int, html string) (*models.Message, error)

SendHTML sends a message with HTML markup, optionally as a reply to another message in the same chat. It stays silent on purpose: it carries a status line, which should not ring anybody's phone.

func (*Client) SendText

func (c *Client) SendText(ctx context.Context, chatID int64, threadID int, text string) (*models.Message, error)

SendText sends a plain text message. threadID may be 0 for private chats.

type PollClient

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

PollClient is the HTTP client the bot uses for every API call. It adds an exponential backoff between failed long polling attempts: when Telegram is unreachable the bot keeps running and retries from 1 up to 30 seconds apart instead of hammering the network or exiting.

Only getUpdates is paced. Other calls are not retried here — their bodies are streamed and cannot be replayed, and a blind retry of sendMessage or copyMessage would risk delivering the same message twice.

func NewPollClient

func NewPollClient(log *slog.Logger) *PollClient

NewPollClient builds the HTTP client for bot.WithHTTPClient.

func (*PollClient) Do

func (p *PollClient) Do(req *http.Request) (*http.Response, error)

Do implements bot.HttpClient.

Jump to

Keyboard shortcuts

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