telegram

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCaption = 1024

Variables

View Source
var (
	ErrNotConfigured = errors.New("telegram bot is not configured")
	ErrBotBlocked    = errors.New("telegram: bot was blocked by the user or the chat is gone")
	ErrBadLogin      = errors.New("telegram login data is invalid or expired")
)
View Source
var ErrQueueFull = errors.New("telegram: send queue for this bot is full")

Functions

func Do

func Do(ctx context.Context, token, op string, run func(ctx context.Context, b *Bot) error) error

func IsTransient

func IsTransient(err error) bool

func ParseCommand

func ParseCommand(text string) (cmd, arg string)

func Submit

func Submit(token string, job Job) error

Types

type APIError

type APIError struct {
	Method          string
	Code            int
	Description     string
	MigrateToChatID int64
}

func (*APIError) Error

func (e *APIError) Error() string

type Bot

type Bot struct {
	Token    string
	Username string
	Secret   string
	API      string
	// contains filtered or unexported fields
}

func For

func For(token string) *Bot

func New

func New(token, username, webhookSecret string) *Bot

func Use

func Use(b *Bot) *Bot

func (*Bot) AnswerCallback

func (b *Bot) AnswerCallback(ctx context.Context, callbackID string) error

func (*Bot) BotID

func (b *Bot) BotID() string

func (*Bot) Check

func (b *Bot) Check(ctx context.Context) (string, error)

func (*Bot) Configured

func (b *Bot) Configured() bool
func (b *Bot) DeepLink(startToken string) string

func (*Bot) GetChat

func (b *Bot) GetChat(ctx context.Context, chatID string) (ChatInfo, error)

func (*Bot) GetMe

func (b *Bot) GetMe(ctx context.Context) (BotInfo, error)

func (*Bot) ResolveChatID

func (b *Bot) ResolveChatID(ctx context.Context, handleOrID string) (string, error)

func (*Bot) SendFile

func (b *Bot) SendFile(ctx context.Context, chatID, method, field, filePath, caption string) error

func (*Bot) SendHTML

func (b *Bot) SendHTML(ctx context.Context, chatID, text string) error

func (*Bot) SendHTMLRaw

func (b *Bot) SendHTMLRaw(ctx context.Context, chatID, text string) error

func (*Bot) SendMarkdown

func (b *Bot) SendMarkdown(ctx context.Context, chatID, text string) error

func (*Bot) SendMessage

func (b *Bot) SendMessage(ctx context.Context, chatID, text string) error

func (*Bot) SendMessageButtons

func (b *Bot) SendMessageButtons(ctx context.Context, chatID, text string, buttons []Button) (int64, error)

func (*Bot) SendMessageID

func (b *Bot) SendMessageID(ctx context.Context, chatID, text string) (int64, error)

func (*Bot) SendPayload

func (b *Bot) SendPayload(ctx context.Context, chatID string, payload map[string]any) (int64, error)

func (*Bot) SendPhotoHTML

func (b *Bot) SendPhotoHTML(ctx context.Context, chatID, photoURL, caption string) error

func (*Bot) SendWithMode

func (b *Bot) SendWithMode(ctx context.Context, chatID, text, parseMode string) error

func (*Bot) SetWebhook

func (b *Bot) SetWebhook(ctx context.Context, webhookURL string) error

func (*Bot) VerifyLogin

func (b *Bot) VerifyLogin(vals url.Values) (LoginData, error)

func (*Bot) VerifyWebhook

func (b *Bot) VerifyWebhook(r *http.Request) bool

type BotInfo

type BotInfo struct {
	ID        int64
	Username  string
	FirstName string
}

func GetMe

func GetMe(ctx context.Context, token string) (BotInfo, error)

type Button

type Button struct {
	Text string
	Data string
}

type CallbackQuery

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

type Chat

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

type ChatInfo

type ChatInfo struct {
	ID        int64  `json:"id"`
	Type      string `json:"type"`
	Username  string `json:"username"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Title     string `json:"title"`
}

type Job

type Job struct {
	Op   string
	Run  func(ctx context.Context, b *Bot) error
	Done func(err error)
}

type LoginData

type LoginData struct {
	ID        int64
	Username  string
	FirstName string
	LastName  string
	AuthDate  time.Time
}

func (LoginData) DisplayName

func (l LoginData) DisplayName() string

type Message

type Message struct {
	MessageID      int64    `json:"message_id"`
	Text           string   `json:"text"`
	Chat           Chat     `json:"chat"`
	From           *User    `json:"from"`
	ReplyToMessage *Message `json:"reply_to_message"`
}

type Update

type Update struct {
	UpdateID      int64          `json:"update_id"`
	Message       *Message       `json:"message"`
	CallbackQuery *CallbackQuery `json:"callback_query"`
}

type User

type User struct {
	ID           int64  `json:"id"`
	Username     string `json:"username"`
	FirstName    string `json:"first_name"`
	LanguageCode string `json:"language_code"`
	IsBot        bool   `json:"is_bot"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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