Files
Luna/Documentation/Luna AI Assistant/Channels/Telegram Channel.md
T
darman 9929941748 Add project documentation and reference materials
Include Luna AI Assistant design docs covering channels, configuration,
core architecture, memory, scheduler, and skills. Add reference docs
from OpenClaw and ZeroClaw projects, plus Mistral and OpenAI API specs.
2026-04-04 04:14:06 +02:00

40 lines
1.8 KiB
Markdown

# Telegram Channel
The Telegram integration consists of two classes: `TelegramChannel` (the `IChannel` implementation) and `TelegramAdapter` (the hosted service that manages channel lifecycles). Both live in the `Luna.Channels.Telegram` namespace.
## TelegramChannel
Handles interaction with the Telegram Bot API, implementing the `IChannel` interface defined in [[Channels]].
### Message Splitting
Telegram enforces a 4096-character limit per message. `TelegramChannel` automatically splits long responses into sequential chunks that respect this limit.
### Streaming
Rather than forwarding every `ChatStreamUpdate` individually (which would hit Telegram's rate limits), the channel accumulates streaming updates and sends them in periodic batches.
### Typing Indicators
Uses `KeepTypingAsync` to maintain a "typing..." indicator in the Telegram chat while the AI generates a response. This runs as a background loop until the response completes.
### User Filtering
`RaiseMessageReceived` filters incoming updates by `AllowedUserIds` (configured via `TelegramOptions` in [[Configuration]]). Messages from unauthorized users or with empty content are silently dropped.
## TelegramAdapter
An `IHostedService` and `IUpdateHandler` that polls Telegram for updates using long polling.
### Lifecycle
1. On startup, begins polling the Telegram Bot API.
2. For each incoming update, identifies the chat ID.
3. Creates a new `TelegramChannel` instance for each unique chat (if one doesn't already exist).
4. Registers the channel with `IChannelManager` from [[Channels]].
5. Routes the update to the appropriate `TelegramChannel`.
### Configuration
Configured via `TelegramOptions` (see [[Configuration]]), which includes:
- `BotToken` — Telegram Bot API token.
- `AllowedUserIds` — Whitelist of Telegram user IDs permitted to interact with Luna.
## Namespace
`Luna.Channels.Telegram`