telegram

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 40 Imported by: 1 module, 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

Index

Constants

View Source
const (
	ClientName = "telegram"
)

Variables

This section is empty.

Functions

func IsRetryable

func IsRetryable(err error) bool

Types

type APIError

type APIError struct {
	Method      string
	StatusCode  int
	ErrorCode   int
	Description string
	RetryAfter  time.Duration
}

func (*APIError) Error

func (e *APIError) Error() string

type AnswerCallbackQueryRequest

type AnswerCallbackQueryRequest struct {
	CallbackQueryID string `json:"callback_query_id"`
	Text            string `json:"text,omitempty"`
	ShowAlert       bool   `json:"show_alert,omitempty"`
}

type AnswerGuestQueryRequest added in v0.1.15

type AnswerGuestQueryRequest struct {
	GuestQueryID string                   `json:"guest_query_id"`
	Result       InlineQueryResultArticle `json:"result"`
}

type AnswerInlineQueryRequest added in v0.1.15

type AnswerInlineQueryRequest struct {
	InlineQueryID string                     `json:"inline_query_id"`
	Results       []InlineQueryResultArticle `json:"results"`
	CacheTime     int                        `json:"cache_time,omitempty"`
	IsPersonal    bool                       `json:"is_personal,omitempty"`
}

type Audio added in v0.1.9

type Audio struct {
	FileID   string `json:"file_id"`
	FileName string `json:"file_name,omitempty"`
	MIMEType string `json:"mime_type,omitempty"`
	FileSize int64  `json:"file_size,omitempty"`
	Duration int    `json:"duration,omitempty"`
}

type BotAPI

type BotAPI interface {
	GetMe(ctx context.Context) (User, error)
	GetUpdates(ctx context.Context, req GetUpdatesRequest) ([]Update, error)
	GetFile(ctx context.Context, fileID string) (File, error)
	DownloadFile(ctx context.Context, filePath string) ([]byte, error)
	SendMessage(ctx context.Context, req SendMessageRequest) (SentMessage, error)
	SendMessageDraft(ctx context.Context, req SendMessageDraftRequest) error
	SendChatAction(ctx context.Context, req SendChatActionRequest) error
	SendVoice(ctx context.Context, req SendVoiceRequest) (SentMessage, error)
	SendAudio(ctx context.Context, req SendAudioRequest) (SentMessage, error)
	SendDocument(ctx context.Context, req SendDocumentRequest) (SentMessage, error)
	EditMessageText(ctx context.Context, req EditMessageTextRequest) (EditMessageTextResponse, error)
	EditMessageMedia(ctx context.Context, req EditMessageMediaRequest) (EditMessageMediaResponse, error)
	AnswerCallbackQuery(ctx context.Context, req AnswerCallbackQueryRequest) error
	AnswerGuestQuery(ctx context.Context, req AnswerGuestQueryRequest) (SentGuestMessage, error)
	AnswerInlineQuery(ctx context.Context, req AnswerInlineQueryRequest) error
	DeleteMessage(ctx context.Context, req DeleteMessageRequest) error
	SetMyCommands(ctx context.Context, req SetMyCommandsRequest) error
	DeleteMyCommands(ctx context.Context, req DeleteMyCommandsRequest) error
}

type BotCommand

type BotCommand struct {
	Command     string `json:"command"`
	Description string `json:"description"`
}

type BotCommandScope

type BotCommandScope struct {
	Type   string `json:"type"`
	ChatID int64  `json:"chat_id,omitempty"`
}

type CallbackQuery

type CallbackQuery struct {
	ID              string   `json:"id"`
	From            *User    `json:"from"`
	Message         *Message `json:"message,omitempty"`
	InlineMessageID string   `json:"inline_message_id,omitempty"`
	Data            string   `json:"data,omitempty"`
}

type Chat

type Chat struct {
	ID   int64  `json:"id"`
	Type string `json:"type"`
}

type ChosenInlineResult added in v0.1.15

type ChosenInlineResult struct {
	ResultID        string    `json:"result_id"`
	From            *User     `json:"from,omitempty"`
	InlineMessageID string    `json:"inline_message_id,omitempty"`
	Query           string    `json:"query,omitempty"`
	Location        *Location `json:"location,omitempty"`
}

type Client

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

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

func (*Client) AnswerCallbackQuery

func (c *Client) AnswerCallbackQuery(ctx context.Context, req AnswerCallbackQueryRequest) error

func (*Client) AnswerGuestQuery added in v0.1.15

func (c *Client) AnswerGuestQuery(ctx context.Context, req AnswerGuestQueryRequest) (SentGuestMessage, error)

func (*Client) AnswerInlineQuery added in v0.1.15

func (c *Client) AnswerInlineQuery(ctx context.Context, req AnswerInlineQueryRequest) error

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(ctx context.Context, req DeleteMessageRequest) error

func (*Client) DeleteMyCommands

func (c *Client) DeleteMyCommands(ctx context.Context, req DeleteMyCommandsRequest) error

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, filePath string) ([]byte, error)

func (*Client) EditMessageMedia added in v0.1.15

func (*Client) EditMessageText

func (*Client) GetFile

func (c *Client) GetFile(ctx context.Context, fileID string) (File, error)

func (*Client) GetMe

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

func (*Client) GetUpdates

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

func (*Client) SendAudio added in v0.1.10

func (c *Client) SendAudio(ctx context.Context, req SendAudioRequest) (SentMessage, error)

func (*Client) SendChatAction

func (c *Client) SendChatAction(ctx context.Context, req SendChatActionRequest) error

func (*Client) SendDocument added in v0.1.15

func (c *Client) SendDocument(ctx context.Context, req SendDocumentRequest) (SentMessage, error)

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, req SendMessageRequest) (SentMessage, error)

func (*Client) SendMessageDraft added in v0.1.15

func (c *Client) SendMessageDraft(ctx context.Context, req SendMessageDraftRequest) error

func (*Client) SendVoice added in v0.1.9

func (c *Client) SendVoice(ctx context.Context, req SendVoiceRequest) (SentMessage, error)

func (*Client) SetMyCommands

func (c *Client) SetMyCommands(ctx context.Context, req SetMyCommandsRequest) error

type ClientConfig

type ClientConfig struct {
	Token      string
	BaseURL    string
	HTTPClient HTTPDoer
}

type Config

type Config struct {
	BaseURL  string
	APIToken string
	BotToken string
	// TelegramBaseURL overrides the Bot API address; empty means Telegram's.
	TelegramBaseURL string
	AllowedUserID   int64
	InlineCachePath string
	// CallbackCachePath keeps the long button data behind short references.
	CallbackCachePath string
	// RenderStatePath keeps which Telegram messages show each run in delivery.
	RenderStatePath         string
	Geo                     *geo.OSMService
	Offset                  *atomic.Int64
	SkipCommandRegistration bool
}

type DeleteMessageRequest

type DeleteMessageRequest struct {
	ChatID    int64 `json:"chat_id"`
	MessageID int64 `json:"message_id"`
}

type DeleteMyCommandsRequest

type DeleteMyCommandsRequest struct {
	Scope *BotCommandScope `json:"scope,omitempty"`
}

type DeliveryAddress

type DeliveryAddress struct {
	Kind            string `json:"kind,omitempty"`
	ChatID          int64  `json:"chat_id,omitempty"`
	MessageID       int64  `json:"message_id,omitempty"`
	GuestQueryID    string `json:"guest_query_id,omitempty"`
	InlineMessageID string `json:"inline_message_id,omitempty"`
}

func ChatDeliveryAddress added in v0.2.0

func ChatDeliveryAddress(chatID int64) DeliveryAddress

ChatDeliveryAddress addresses the private or group chat chatID.

type Document

type Document struct {
	FileID   string `json:"file_id"`
	FileName string `json:"file_name,omitempty"`
	MIMEType string `json:"mime_type,omitempty"`
	FileSize int64  `json:"file_size,omitempty"`
}

type EditMessageMediaRequest added in v0.1.15

type EditMessageMediaRequest struct {
	ChatID          int64                 `json:"chat_id,omitempty"`
	MessageID       int64                 `json:"message_id,omitempty"`
	InlineMessageID string                `json:"inline_message_id,omitempty"`
	Media           InputMediaAudio       `json:"media"`
	ReplyMarkup     *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}

type EditMessageMediaResponse added in v0.1.15

type EditMessageMediaResponse struct {
	MessageID int64 `json:"message_id"`
}

type EditMessageTextRequest

type EditMessageTextRequest struct {
	ChatID          int64                 `json:"chat_id,omitempty"`
	MessageID       int64                 `json:"message_id,omitempty"`
	InlineMessageID string                `json:"inline_message_id,omitempty"`
	Text            string                `json:"text"`
	ParseMode       string                `json:"parse_mode,omitempty"`
	ReplyMarkup     *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}

type EditMessageTextResponse

type EditMessageTextResponse struct {
	MessageID int64 `json:"message_id"`
}

type File

type File struct {
	FileID   string `json:"file_id"`
	FilePath string `json:"file_path,omitempty"`
	FileSize int64  `json:"file_size,omitempty"`
}

type GetFileRequest

type GetFileRequest struct {
	FileID string `json:"file_id"`
}

type GetUpdatesRequest

type GetUpdatesRequest struct {
	Offset         int64    `json:"offset,omitempty"`
	Limit          int      `json:"limit,omitempty"`
	TimeoutSeconds int      `json:"timeout,omitempty"`
	AllowedUpdates []string `json:"allowed_updates,omitempty"`
}

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

type InlineKeyboardButton

type InlineKeyboardButton struct {
	Text         string `json:"text"`
	CallbackData string `json:"callback_data,omitempty"`
}

type InlineKeyboardMarkup

type InlineKeyboardMarkup struct {
	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}

type InlineQuery added in v0.1.15

type InlineQuery struct {
	ID       string    `json:"id"`
	From     *User     `json:"from,omitempty"`
	Query    string    `json:"query,omitempty"`
	Offset   string    `json:"offset,omitempty"`
	ChatType string    `json:"chat_type,omitempty"`
	Location *Location `json:"location,omitempty"`
}

type InlineQueryResultArticle added in v0.1.15

type InlineQueryResultArticle struct {
	Type                string                  `json:"type"`
	ID                  string                  `json:"id"`
	Title               string                  `json:"title"`
	Description         string                  `json:"description,omitempty"`
	InputMessageContent InputTextMessageContent `json:"input_message_content"`
	ReplyMarkup         *InlineKeyboardMarkup   `json:"reply_markup,omitempty"`
}

type InputMediaAudio added in v0.1.15

type InputMediaAudio struct {
	Type      string `json:"type"`
	Media     string `json:"media"`
	Caption   string `json:"caption,omitempty"`
	ParseMode string `json:"parse_mode,omitempty"`
	Title     string `json:"title,omitempty"`
	Performer string `json:"performer,omitempty"`
}

type InputTextMessageContent added in v0.1.15

type InputTextMessageContent struct {
	MessageText string `json:"message_text"`
	ParseMode   string `json:"parse_mode,omitempty"`
}

type KeyboardButton added in v0.1.16

type KeyboardButton struct {
	Text            string `json:"text"`
	RequestLocation bool   `json:"request_location,omitempty"`
}

type Location added in v0.1.15

type Location struct {
	Latitude             float64 `json:"latitude"`
	Longitude            float64 `json:"longitude"`
	HorizontalAccuracy   float64 `json:"horizontal_accuracy,omitempty"`
	LivePeriod           int     `json:"live_period,omitempty"`
	Heading              int     `json:"heading,omitempty"`
	ProximityAlertRadius int     `json:"proximity_alert_radius,omitempty"`
}

type Message

type Message struct {
	MessageID          int64                 `json:"message_id"`
	Date               int64                 `json:"date,omitempty"`
	From               *User                 `json:"from,omitempty"`
	Chat               Chat                  `json:"chat"`
	GuestQueryID       string                `json:"guest_query_id,omitempty"`
	GuestBotCallerUser *User                 `json:"guest_bot_caller_user,omitempty"`
	GuestBotCallerChat *Chat                 `json:"guest_bot_caller_chat,omitempty"`
	Text               string                `json:"text,omitempty"`
	Caption            string                `json:"caption,omitempty"`
	Photo              []PhotoSize           `json:"photo,omitempty"`
	Document           *Document             `json:"document,omitempty"`
	Voice              *Voice                `json:"voice,omitempty"`
	Audio              *Audio                `json:"audio,omitempty"`
	Location           *Location             `json:"location,omitempty"`
	ReplyToMessage     *Message              `json:"reply_to_message,omitempty"`
	ReplyMarkup        *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}

type PhotoSize

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

type ReplyKeyboardMarkup added in v0.1.16

type ReplyKeyboardMarkup struct {
	Keyboard        [][]KeyboardButton `json:"keyboard"`
	ResizeKeyboard  bool               `json:"resize_keyboard,omitempty"`
	OneTimeKeyboard bool               `json:"one_time_keyboard,omitempty"`
	Selective       bool               `json:"selective,omitempty"`
}

type ReplyKeyboardRemove added in v0.1.16

type ReplyKeyboardRemove struct {
	RemoveKeyboard bool `json:"remove_keyboard"`
	Selective      bool `json:"selective,omitempty"`
}

type SendAudioRequest added in v0.1.10

type SendAudioRequest struct {
	ChatID              int64
	Audio               []byte
	FileName            string
	Caption             string
	MIMEType            string
	DisableNotification bool
}

type SendChatActionRequest

type SendChatActionRequest struct {
	ChatID int64  `json:"chat_id"`
	Action string `json:"action"`
}

type SendDocumentRequest added in v0.1.15

type SendDocumentRequest struct {
	ChatID   int64
	Document []byte
	FileName string
	Caption  string
	MIMEType string
}

type SendMessageDraftRequest added in v0.1.15

type SendMessageDraftRequest struct {
	ChatID    int64  `json:"chat_id"`
	DraftID   int64  `json:"draft_id"`
	Text      string `json:"text"`
	ParseMode string `json:"parse_mode,omitempty"`
}

type SendMessageRequest

type SendMessageRequest struct {
	ChatID                  int64  `json:"chat_id"`
	Text                    string `json:"text"`
	ParseMode               string `json:"parse_mode,omitempty"`
	ReplyMarkup             any    `json:"reply_markup,omitempty"`
	SkipReplyKeyboardRemove bool   `json:"-"`
	DisableNotification     bool   `json:"disable_notification,omitempty"`
}

type SendVoiceRequest added in v0.1.9

type SendVoiceRequest struct {
	ChatID   int64
	Voice    []byte
	FileName string
	Caption  string
	MIMEType string
}

type SentGuestMessage added in v0.1.15

type SentGuestMessage struct {
	InlineMessageID string `json:"inline_message_id"`
}

type SentMessage

type SentMessage struct {
	MessageID int64     `json:"message_id"`
	Voice     *Voice    `json:"voice,omitempty"`
	Audio     *Audio    `json:"audio,omitempty"`
	Document  *Document `json:"document,omitempty"`
}

type SetMyCommandsRequest

type SetMyCommandsRequest struct {
	Commands []BotCommand     `json:"commands"`
	Scope    *BotCommandScope `json:"scope,omitempty"`
}

type Update

type Update struct {
	UpdateID           int64               `json:"update_id"`
	Message            *Message            `json:"message,omitempty"`
	GuestMessage       *Message            `json:"guest_message,omitempty"`
	InlineQuery        *InlineQuery        `json:"inline_query,omitempty"`
	ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
	CallbackQuery      *CallbackQuery      `json:"callback_query,omitempty"`
}

type User

type User struct {
	ID                        int64  `json:"id"`
	IsBot                     bool   `json:"is_bot"`
	Username                  string `json:"username,omitempty"`
	CanJoinGroups             bool   `json:"can_join_groups,omitempty"`
	CanReadAllGroupMessages   bool   `json:"can_read_all_group_messages,omitempty"`
	SupportsGuestQueries      bool   `json:"supports_guest_queries,omitempty"`
	SupportsInlineQueries     bool   `json:"supports_inline_queries,omitempty"`
	CanConnectToBusiness      bool   `json:"can_connect_to_business,omitempty"`
	HasTopicsEnabled          bool   `json:"has_topics_enabled,omitempty"`
	AllowsUsersToCreateTopics bool   `json:"allows_users_to_create_topics,omitempty"`
	CanManageBots             bool   `json:"can_manage_bots,omitempty"`
}

type Voice added in v0.1.9

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

type Worker

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

func NewWorker

func NewWorker(cfg Config) (*Worker, error)

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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