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
- func IsBlocked(err error) bool
- func IsNotModified(err error) bool
- func IsThreadNotFound(err error) bool
- func IsTopicClosed(err error) bool
- type Client
- func (c *Client) API() *bot.Bot
- func (c *Client) CloseTopic(ctx context.Context, threadID int) error
- func (c *Client) Copy(ctx context.Context, toChatID int64, toThreadID int, fromChatID int64, ...) (int, error)
- func (c *Client) CreateTopic(ctx context.Context, name string) (int, error)
- func (c *Client) EditCaption(ctx context.Context, chatID int64, messageID int, caption string) error
- func (c *Client) EditText(ctx context.Context, chatID int64, messageID int, text string) error
- func (c *Client) GetChat(ctx context.Context, chatID int64) (*models.ChatFullInfo, error)
- func (c *Client) GetChatMember(ctx context.Context, chatID, userID int64) (*models.ChatMember, error)
- func (c *Client) GetMe(ctx context.Context) (*models.User, error)
- func (c *Client) GroupID() int64
- func (c *Client) Pin(ctx context.Context, chatID int64, messageID int) error
- func (c *Client) ReopenTopic(ctx context.Context, threadID int) error
- func (c *Client) SendHTML(ctx context.Context, chatID int64, threadID, replyTo int, html string) (*models.Message, error)
- func (c *Client) SendText(ctx context.Context, chatID int64, threadID int, text string) (*models.Message, error)
- type PollClient
Constants ¶
const ( // PollTimeout is the long polling window asked of Telegram. PollTimeout = 50 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func IsBlocked ¶
IsBlocked reports whether the client has blocked the bot (or deleted their account), which makes delivery impossible until they write again.
func IsNotModified ¶
IsNotModified reports an edit that changed nothing, which Telegram rejects but which is not a failure for us.
func IsThreadNotFound ¶
IsThreadNotFound reports whether the topic is gone — normally because somebody deleted it by hand in the group.
func IsTopicClosed ¶
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 (*Client) CloseTopic ¶
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 ¶
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) 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) ReopenTopic ¶
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.
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.