Ratatoskr
A lightweight Telegram <-> process bridge written in Rust, designed to stream Telegram updates over stdout and accept responses via a named pipe.

π Features
- Uses
teloxidefor Telegram bot integration - Streams inbound Telegram updates as newline-delimited JSON to stdout
- Reads outbound
OutgoingMessageJSON lines from a named pipe (PIPE_OUTBOUND_PATH) and delivers them to Telegram - Minimal, event-driven, and broker-freeβgreat for chaining with shell pipelines
π¦ Prerequisites
- Rust
- A Telegram bot token from @BotFather
- A handler that reads JSONL from stdin and writes JSONL responses to a named pipe
βοΈ Setup
-
Clone the repository:
Alternatively, you can download the source code directly from the GitHub repository.
-
Set environment variables:
TELEGRAM_BOT_TOKEN(required)PIPE_OUTBOUND_PATH(optional, default:./ratatoskr_out.pipe)
You can place these in a
.envfile or export them in your shell. A.env.examplefile is provided as a template.Using direnv (recommended):
# Edit .envrc with your configurationOr using a .env file:
# Edit .env with your configuration -
Build and run the bot:
Or simply:
π Development
For development with auto-reload:
To run tests:
Pipe mode (broker-free)
Run Ratatoskr and stream Telegram updates into your handler:
PIPE_OUTBOUND_PATH=/tmp/ratatoskr_out.pipe TELEGRAM_BOT_TOKEN=... |
Behavior:
- Incoming Telegram updates are printed as JSONL (one JSON object per line) to stdout.
- Your handler reads that stream, emits JSONL
OutgoingMessageobjects to the named pipe, and Ratatoskr sends them to Telegram.
Quick black-box check (service running)
With Ratatoskr running in pipe mode and CHAT_ID set to your chat:
You should receive "Hello from pipe test" in the target chat.
π€ Unified Message Types
Ratatoskr uses a unified message type system for consistent handling of all communications. For detailed documentation, see Unified Message Types.
π§ Client Type Generation
Ratatoskr provides TypeScript definitions that can be used with quicktype to generate client types in your preferred programming language:
# Install quicktype
# Generate Python types
# Generate Java types
# Generate Go types
Supported languages include Python, Java, C#, Go, Rust, Kotlin, Swift, Dart, and more. For complete instructions and examples, see Type Generation Guide.
You can also use the provided generation script:
Incoming message stream (stdout)
All messages from Telegram are wrapped in the unified IncomingMessage type:
Telegram Message Example
Callback Query Example
Edited Message Example
Outgoing messages read from PIPE_OUTBOUND_PATH
All messages to Telegram use the unified OutgoingMessage type:
Typing Indicator Example
This message will cause the bot to display the "typing..." indicator in the specified chat, letting users know the bot is busy processing.
Text Message Example
Image Message Example
Supported Message Types
- TextMessage - Send text with optional formatting and buttons
- ImageMessage - Send images from local filesystem
- DocumentMessage - Send documents/files from local filesystem
- EditMessage - Edit previously sent messages
- DeleteMessage - Delete messages from chat
- TypingMessage - Show typing indicator (bot is busy)
Legacy Format Support
The old message format is still supported for backwards compatibility:
For complete documentation, see Unified Message Types. For practical examples and usage patterns, see Examples. For troubleshooting common issues, see Troubleshooting Guide.
π§ Why Ratatoskr?
Inspired by the mythical squirrel that relays messages across realms, Ratatoskr is built to relay messages between users and intelligent systems, using simple pipe-based messaging as the backbone.
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the BSD 3-Clause License - see the LICENSE.md file for details.