telegram

package
v0.4.0 Latest Latest
Warning

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

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

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

View Source
const Name = "telegram"

Name is the channel name stored in channel links.

Variables

View Source
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

func New(token, serverURL string, svc *app.Service, log *slog.Logger) (*Adapter, error)

New creates the adapter. serverURL overrides the Bot API URL (tests). SetEngine must be called before Serve.

func (*Adapter) Edit

func (a *Adapter) Edit(ctx context.Context, chatID, messageID string, m actions.Message) error

Edit replaces a message in place.

func (*Adapter) Name

func (a *Adapter) Name() string

func (*Adapter) Send

func (a *Adapter) Send(ctx context.Context, chatID string, m actions.Message) (string, error)

Send posts a message and returns its id.

func (*Adapter) Serve

func (a *Adapter) Serve(ctx context.Context) error

Serve long-polls until ctx is cancelled. The library reconnects with backoff on network errors; Telegram keeps updates for 24 h meanwhile.

func (*Adapter) SetEngine

func (a *Adapter) SetEngine(e *actions.Engine)

SetEngine wires the action layer (which itself needs the adapter).

func (*Adapter) String

func (a *Adapter) String() string

func (*Adapter) Username

func (a *Adapter) Username() string

Username is the bot's @username without the @ ("" until known), used for t.me deep links.

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

func NewManager(envToken, apiURL string, svc *app.Service, log *slog.Logger) *Manager

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

func (m *Manager) Configure(ctx context.Context, token string) (BotStatus, error)

Configure checks a token with Telegram, saves it and switches the bot to it. It returns the new status.

func (*Manager) Edit

func (m *Manager) Edit(ctx context.Context, chatID, messageID string, msg actions.Message) error

Edit edits through the running bot.

func (*Manager) Name

func (m *Manager) Name() string

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context) (BotStatus, error)

Remove forgets a token saved from the web and stops the bot.

func (*Manager) Send

func (m *Manager) Send(ctx context.Context, chatID string, msg actions.Message) (string, error)

Send posts through the running bot.

func (*Manager) Serve

func (m *Manager) Serve(ctx context.Context) error

Serve runs the bot for the current token and restarts it when the token changes, until ctx ends.

func (*Manager) SetEngine

func (m *Manager) SetEngine(e *actions.Engine)

SetEngine wires the action layer.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context) BotStatus

Status reports whether a bot is configured and running.

func (*Manager) String

func (m *Manager) String() string

func (*Manager) Username

func (m *Manager) Username() string

Username is the running bot's @username ("" if none).

Jump to

Keyboard shortcuts

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