tg

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package tg is a minimal Telegram Bot API HTTP client.

Index

Constants

View Source
const DefaultBaseURL = "https://api.telegram.org"

Variables

This section is empty.

Functions

func DryRun

func DryRun(baseURL string, r Request) map[string]any

DryRun describes the request that Call would send, without credentials.

Types

type APIError

type APIError struct {
	Code        int             `json:"error_code"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters,omitempty"`
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsAuth

func (e *APIError) IsAuth() bool

IsAuth reports whether the error means the bot token was rejected. Telegram answers 401 for a revoked token and 404 for a malformed one.

type Client

type Client struct {
	Token   string
	BaseURL string
	HTTP    *http.Client
}

func (*Client) Call

func (c *Client) Call(ctx context.Context, r Request) (json.RawMessage, error)

func (*Client) Download

func (c *Client) Download(ctx context.Context, filePath, dst string) error

Download fetches a file previously resolved with getFile into dst.

func (*Client) Redact

func (c *Client) Redact(s string) string

Redact removes the bot token from any text that may reach logs or output.

type Request

type Request struct {
	Method string
	Params map[string]any
	Files  map[string]string
}

Request is a prepared Bot API call. Params holds JSON-compatible values, Files maps a field name to a local path that is uploaded as multipart.

Jump to

Keyboard shortcuts

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