telegram

package
v0.42.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MessageChunkLimit = 3500

MessageChunkLimit is the largest chunk the adapter will send, in bytes of rendered HTML.

Telegram's own cap is 4096 characters of the entity-stripped text, counted in UTF-16 code units. Counting raw HTML bytes over-counts against that, which is conservative and costs only the occasional extra message.

Exported because the dispatcher's activity log builds Telegram HTML and chunks it itself, against this same number. Sharing the constant keeps the two from drifting apart, which is all it does — they previously carried the same literal with nothing tying them together.

It does not make the two budgets equivalent, and nothing here should be read as saying the activity log is bounded because it shares this constant. That path measures its accumulated lines, then appends an approval section budgeted in unescaped runes which HTML escaping can expand several times over, and it forwards the result with an explicit parse mode — which this adapter sends unchunked by contract. A single message over Telegram's cap is the outcome, and the fix belongs where the length is decided, not here.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

func New

func New(token string, allowedUsers []int64, logger *slog.Logger, voiceOpts *VoiceOpts) (*Adapter, error)

func (*Adapter) EditMessage added in v0.30.5

func (a *Adapter) EditMessage(_ context.Context, externalID, messageID string, msg adapter.OutgoingMessage) error

EditMessage edits both the text and inline keyboard of an existing Telegram message. Implements adapter.MessageEditor. When msg.Buttons is empty, the existing keyboard is removed.

func (*Adapter) EditText added in v0.16.10

func (a *Adapter) EditText(_ context.Context, externalID, messageID, text, parseMode string) error

EditText edits an existing Telegram message. Implements adapter.MessageEditor.

func (*Adapter) IsAllowed

func (a *Adapter) IsAllowed(userID int64) bool

IsAllowed checks if a user ID is in the allowed list.

func (*Adapter) IsDebug added in v0.16.10

func (a *Adapter) IsDebug(chatID int64) bool

IsDebug reports whether the given chat has debug mode enabled.

func (*Adapter) IsDebugByExternalID added in v0.16.10

func (a *Adapter) IsDebugByExternalID(externalID string) bool

IsDebugByExternalID is a convenience wrapper that parses an ExternalID string.

func (*Adapter) Name

func (a *Adapter) Name() string

func (*Adapter) RegisterSkillCommands added in v0.28.0

func (a *Adapter) RegisterSkillCommands(skillCmds []SkillCommand)

RegisterSkillCommands updates the Telegram bot's command menu to include both the built-in commands and the provided skill command triggers. Call this after adapter construction and skill loading, before Start.

func (*Adapter) Send

func (a *Adapter) Send(ctx context.Context, msg adapter.OutgoingMessage) error

func (*Adapter) SendAndGetID added in v0.16.10

func (a *Adapter) SendAndGetID(ctx context.Context, msg adapter.OutgoingMessage) (string, error)

SendAndGetID sends a message and returns the Telegram message ID as a string. Implements adapter.MessageEditor.

func (*Adapter) SendTyping added in v0.15.0

func (a *Adapter) SendTyping(_ context.Context, externalID string) error

func (*Adapter) SetCallbackResolver

func (a *Adapter) SetCallbackResolver(r adapter.CallbackResolver)

SetCallbackResolver sets the resolver used to handle inline keyboard button clicks (callback queries). Call this after adapter construction, before Start.

func (*Adapter) Start

func (a *Adapter) Start(ctx context.Context, incoming chan<- adapter.IncomingMessage) error

func (*Adapter) Stop

func (a *Adapter) Stop() error

type SkillCommand added in v0.28.0

type SkillCommand struct {
	Command     string
	Description string
}

SkillCommand represents a skill's command trigger for registration.

type VoiceOpts

type VoiceOpts struct {
	STT            voice.STTProvider
	TTS            voice.TTSProvider
	TTSVoice       string
	AutoVoiceReply bool
}

VoiceOpts configures optional voice (STT/TTS) support for the adapter.

Jump to

Keyboard shortcuts

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