Documentation
¶
Overview ¶
Package telegram provides a Telegram provider for omnichat.
Index ¶
- Constants
- type Callback
- type CallbackHandler
- type Command
- type Config
- type InlineButton
- type LocalizedCommands
- type Provider
- func (p *Provider) AnswerCallback(ctx context.Context, callbackID, text string, showAlert bool) error
- func (p *Provider) Connect(ctx context.Context) error
- func (p *Provider) DeleteCommands(ctx context.Context, languageCode string) error
- func (p *Provider) Disconnect(ctx context.Context) error
- func (p *Provider) Name() string
- func (p *Provider) OnCallback(handler CallbackHandler)
- func (p *Provider) OnEvent(handler provider.EventHandler)
- func (p *Provider) OnMessage(handler provider.MessageHandler)
- func (p *Provider) OnWebAppData(handler WebAppDataHandler)
- func (p *Provider) Send(ctx context.Context, chatID string, msg provider.OutgoingMessage) error
- func (p *Provider) SetCommands(ctx context.Context, commands []Command) error
- func (p *Provider) SetLocalizedCommands(ctx context.Context, commands LocalizedCommands) error
- type WebAppData
- type WebAppDataHandler
Constants ¶
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
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 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
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 (*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) DeleteCommands ¶ added in v0.7.0
DeleteCommands removes bot commands for the specified language (or default if empty).
func (*Provider) Disconnect ¶
Disconnect closes the Telegram connection.
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) SetCommands ¶ added in v0.7.0
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.