telegram

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 19 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

Index

Constants

View Source
const LongPollSeconds = 50

LongPollSeconds is the getUpdates long-poll timeout; the HTTP client timeout above must be larger.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code        int
	Description string
	RetryAfter  int
}

func (*APIError) Error

func (e *APIError) Error() string

type Bot

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

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"`
}

func (Chat) IDString

func (c Chat) IDString() string

type Client

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

func New

func New(token string) *Client

func (*Client) AnswerCallbackQuery

func (c *Client) AnswerCallbackQuery(ctx context.Context, id, text string) error

func (*Client) EditMessageText

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

func (*Client) GetMe

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

func (*Client) GetUpdates

func (c *Client) GetUpdates(ctx context.Context, offset int64, timeout int) ([]Update, error)

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, chatID, text string) error

func (*Client) SendMessageWithMarkup

func (c *Client) SendMessageWithMarkup(ctx context.Context, chatID, text string, markup *InlineKeyboardMarkup) error

func (*Client) Token

func (c *Client) Token() string

func (*Client) WithAPIBase

func (c *Client) WithAPIBase(base string) *Client

func (*Client) WithHTTPClient

func (c *Client) WithHTTPClient(h *http.Client) *Client

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 Message

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

type Pollers

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

func NewPollers

func NewPollers(reg *Registry, st *store.Store, logger *slog.Logger, hub pub) *Pollers

func (*Pollers) StartAll

func (p *Pollers) StartAll(ctx context.Context) error

func (*Pollers) StartForUser

func (p *Pollers) StartForUser(_ context.Context, userID string) error

StartForUser launches a poller goroutine. The goroutine's lifetime is bound to the server-wide root context (not the caller's ctx, which for an API request is cancelled as soon as the response is sent); the returned stop channel and StopForUser control per-user shutdown.

func (*Pollers) StopAll

func (p *Pollers) StopAll()

func (*Pollers) StopForUser

func (p *Pollers) StopForUser(userID string) error

func (*Pollers) WithAPIBase

func (p *Pollers) WithAPIBase(base string) *Pollers

type Registry

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

func NewRegistry

func NewRegistry(st *store.Store, c *crypto.Crypto) *Registry

func (*Registry) GetOrCreate

func (r *Registry) GetOrCreate(ctx context.Context, userID string) (*Client, error)

func (*Registry) Invalidate

func (r *Registry) Invalidate(userID string)

func (*Registry) WithAPIBase

func (r *Registry) WithAPIBase(base string) *Registry

type SendMessageRequest

type SendMessageRequest struct {
	ChatID      string          `json:"chat_id"`
	Text        string          `json:"text"`
	ParseMode   string          `json:"parse_mode,omitempty"`
	ReplyMarkup json.RawMessage `json:"reply_markup,omitempty"`
}

type Service

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

func NewService

func NewService(pollers *Pollers, st *store.Store, hub *ws.Hub, logger *slog.Logger) *Service

func (*Service) SendReminder

func (s *Service) SendReminder(ctx context.Context, userID, chatID, text, taskID, buttonLabel string) error

SendReminder sends a due-task reminder carrying an inline "Complete" button whose callback data completes the task straight from Telegram.

func (*Service) SendTest

func (s *Service) SendTest(ctx context.Context, userID, chatID, text string) error

func (*Service) StartAll

func (s *Service) StartAll(ctx context.Context) error

func (*Service) StartForUser

func (s *Service) StartForUser(ctx context.Context, userID string) error

func (*Service) StopAll

func (s *Service) StopAll()

func (*Service) StopForUser

func (s *Service) StopForUser(userID string) error

func (*Service) ValidateToken

func (s *Service) ValidateToken(ctx context.Context, botToken string) (string, error)

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"`
	IsBot     bool   `json:"is_bot"`
	FirstName string `json:"first_name"`
	Username  string `json:"username"`
}

Jump to

Keyboard shortcuts

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