Documentation
¶
Overview ¶
Package telegram (piece ②) connects Exhale to a Telegram bot over long polling: an outbound connection, so no public URL or open port is needed (ADR 0001, 0007). It only renders action-layer messages as inline keyboards and passes button presses back. Its home message is the app itself: one pinned message that navigates by editing in place (ADR 0019).
Index ¶
- Constants
- Variables
- type Adapter
- func (a *Adapter) Edit(ctx context.Context, chatID, messageID string, m actions.Message) error
- func (a *Adapter) Name() string
- func (a *Adapter) Send(ctx context.Context, chatID string, m actions.Message) (string, error)
- func (a *Adapter) Serve(ctx context.Context) error
- func (a *Adapter) SetEngine(e *actions.Engine)
- func (a *Adapter) String() string
- func (a *Adapter) Username() string
- type BotStatus
- type Manager
- func (m *Manager) Configure(ctx context.Context, token string) (BotStatus, error)
- func (m *Manager) Edit(ctx context.Context, chatID, messageID string, msg actions.Message) error
- func (m *Manager) Name() string
- func (m *Manager) Remove(ctx context.Context) (BotStatus, error)
- func (m *Manager) Send(ctx context.Context, chatID string, msg actions.Message) (string, error)
- func (m *Manager) Serve(ctx context.Context) error
- func (m *Manager) SetEngine(e *actions.Engine)
- func (m *Manager) Status(ctx context.Context) BotStatus
- func (m *Manager) String() string
- func (m *Manager) Username() string
Constants ¶
const Name = "telegram"
Name is the channel name stored in channel links.
Variables ¶
var ErrNotRunning = errors.New("telegram is not set up")
ErrNotRunning is returned when there is no bot to send through.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is the Telegram channel.
func New ¶
New creates the adapter. serverURL overrides the Bot API URL (tests). SetEngine must be called before Serve.
func (*Adapter) Serve ¶
Serve long-polls until ctx is cancelled. The library reconnects with backoff on network errors; Telegram keeps updates for 24 h meanwhile.
type BotStatus ¶
type BotStatus struct {
Configured bool `json:"configured"`
Source string `json:"source,omitempty" enum:"env,settings" doc:"env: set by EXHALE_TELEGRAM_TOKEN and not editable in the web"`
Username string `json:"username,omitempty" doc:"the bot's @username, without @"`
Name string `json:"name,omitempty" doc:"the bot's display name"`
Running bool `json:"running"`
}
BotStatus describes the bot for the settings UI.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the Telegram adapter. It implements actions.Channel and the platform service interface.
func NewManager ¶
NewManager returns a manager. envToken (may be empty) wins over a token saved from the web; apiURL overrides the Bot API URL (tests).
func (*Manager) Configure ¶
Configure checks a token with Telegram, saves it and switches the bot to it. It returns the new status.
func (*Manager) Serve ¶
Serve runs the bot for the current token and restarts it when the token changes, until ctx ends.