telegram

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 7 Imported by: 3

Documentation

Overview

Package telegram provides a Telegram provider for omnichat.

Index

Constants

View Source
const (
	// MetaInlineKeyboard specifies inline keyboard buttons.
	// Value: [][]InlineButton (rows of buttons)
	MetaInlineKeyboard = "telegram_inline_keyboard"

	// MetaDisablePreview disables link preview in messages.
	// Value: bool (default: false)
	MetaDisablePreview = "telegram_disable_preview"

	// MetaDisableNotification sends the message silently.
	// Value: bool (default: false)
	MetaDisableNotification = "telegram_disable_notification"

	// MetaProtectContent protects the message from forwarding/saving.
	// Value: bool (default: false)
	MetaProtectContent = "telegram_protect_content"
)

Telegram-specific metadata keys for OutgoingMessage.Metadata.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback added in v0.7.0

type Callback struct {
	// ID is the callback query ID.
	ID string

	// Data is the callback data from the button.
	Data string

	// ChatID is the chat where the callback originated.
	ChatID string

	// SenderID is the user who pressed the button.
	SenderID string

	// SenderName is the user's display name.
	SenderName string

	// MessageID is the message containing the button.
	MessageID string
}

Callback represents an inline keyboard callback.

type CallbackHandler added in v0.7.0

type CallbackHandler func(ctx context.Context, callback *Callback) error

CallbackHandler handles inline keyboard button callbacks.

type Command added in v0.7.0

type Command struct {
	// Command is the command name (without leading slash).
	Command string

	// Description is the command description shown in the menu.
	Description string
}

Command represents a bot command for registration.

type Config

type Config struct {
	Token  string
	Logger *slog.Logger
}

Config configures the Telegram provider.

type InlineButton added in v0.7.0

type InlineButton struct {
	// Text is the button label text.
	Text string `json:"text"`

	// URL is an HTTP/HTTPS URL to open when button is pressed.
	URL string `json:"url,omitempty"`

	// CallbackData is data sent to bot when button is pressed.
	CallbackData string `json:"callback_data,omitempty"`

	// WebAppURL is the URL for a Web App to open when button is pressed.
	WebAppURL string `json:"web_app_url,omitempty"`

	// SwitchInlineQuery opens inline mode in another chat.
	SwitchInlineQuery string `json:"switch_inline_query,omitempty"`

	// SwitchInlineQueryCurrentChat opens inline mode in current chat.
	SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"`
}

InlineButton represents a Telegram inline keyboard button.

type LocalizedCommands added in v0.7.0

type LocalizedCommands map[string][]Command

LocalizedCommands maps language codes to command lists. Use empty string "" for default/fallback commands.

type Provider

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

Provider implements the Provider interface for Telegram.

func New

func New(config Config) (*Provider, error)

New creates a new Telegram provider.

func (*Provider) AnswerCallback added in v0.7.0

func (p *Provider) AnswerCallback(ctx context.Context, callbackID, text string, showAlert bool) error

AnswerCallback responds to a callback query with optional text and alert.

func (*Provider) Connect

func (p *Provider) Connect(ctx context.Context) error

Connect establishes connection to Telegram.

func (*Provider) DeleteCommands added in v0.7.0

func (p *Provider) DeleteCommands(ctx context.Context, languageCode string) error

DeleteCommands removes bot commands for the specified language (or default if empty).

func (*Provider) Disconnect

func (p *Provider) Disconnect(ctx context.Context) error

Disconnect closes the Telegram connection.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name.

func (*Provider) OnCallback added in v0.7.0

func (p *Provider) OnCallback(handler CallbackHandler)

OnCallback registers a callback handler for inline keyboard buttons.

func (*Provider) OnEvent

func (p *Provider) OnEvent(handler provider.EventHandler)

OnEvent registers an event handler.

func (*Provider) OnMessage

func (p *Provider) OnMessage(handler provider.MessageHandler)

OnMessage registers a message handler.

func (*Provider) OnWebAppData added in v0.7.0

func (p *Provider) OnWebAppData(handler WebAppDataHandler)

OnWebAppData registers a handler for web app data responses.

func (*Provider) Send

func (p *Provider) Send(ctx context.Context, chatID string, msg provider.OutgoingMessage) error

Send sends a message to a Telegram chat.

func (*Provider) SetCommands added in v0.7.0

func (p *Provider) SetCommands(ctx context.Context, commands []Command) error

SetCommands sets bot commands for the default language.

func (*Provider) SetLocalizedCommands added in v0.7.0

func (p *Provider) SetLocalizedCommands(ctx context.Context, commands LocalizedCommands) error

SetLocalizedCommands sets bot commands for multiple languages. The language code "" sets the default commands.

type WebAppData added in v0.7.0

type WebAppData struct {
	// Data is the data string sent by the web app.
	Data string

	// ButtonText is the text of the button that opened the web app.
	ButtonText string

	// ChatID is the chat where the web app was opened.
	ChatID string

	// SenderID is the user who opened the web app.
	SenderID string

	// SenderName is the user's display name.
	SenderName string
}

WebAppData represents data sent from a Telegram Web App.

type WebAppDataHandler added in v0.7.0

type WebAppDataHandler func(ctx context.Context, data *WebAppData) error

WebAppDataHandler handles web app data responses.

Jump to

Keyboard shortcuts

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