tg-rs
⚠️ This is a potentially dangerous vibe coded project. Use at your own risk.
Send yourself Telegram messages from the command line.
|
Install
Requires Rust. Clone the repo and build:
Setup
Run the interactive setup once. You will need a Telegram bot token, you can create one via @BotFather.
Usage
tg [OPTIONS] [MESSAGE...]
tg <SUBCOMMAND>
Send a message
# Positional args (joined with spaces)
# From stdin
|
|
If no message args are given, tg reads from stdin until EOF.
Options
| Flag | Long | Description |
|---|---|---|
-e |
Interpret escape sequences (\n, \t, \\) |
|
-n |
Strip trailing newline from input | |
-m MODE |
--parse-mode MODE |
Telegram formatting: markdown or html |
-i |
--interactive |
Stream stdin updates by editing one message (max 1/s) |
-f |
--interactive-frequency SECONDS |
Seconds between interactive updates (default: 1) |
-s |
--silent |
Send without device notification |
-q |
--quiet |
Suppress non-error output |
-h |
--help |
Show help |
-V |
--version |
Show version |
Escape sequences (-e)
Telegram formatting (-m)
# MarkdownV2
# HTML
Note: MarkdownV2 requires special characters to be escaped. See the Telegram docs for details.
tgautomatically escapes these characters for you
Silent notifications (-s)
Sends the message without triggering a sound or notification banner on the recipient's device. Useful for low-priority automated alerts:
Combining flags
# Multiline silent message
# Piped log with no notification
|
# HTML alert
Interactive updates (-i)
Use interactive mode for progress-like output. The first update sends a message, then further updates edit that same message with a max rate of 1 update per second.
Use --interactive-frequency (-f) to change the update interval.
# Example progress stream
|
# Update every 2 seconds
|
# ASCII progress bar stream (bash)
for; do
filled=;
empty=;
;
;
done |
Listen mode (tg listen)
Listen for new incoming messages in the configured chat and write them to stdout. Listening stops when /eof is received.
Subcommands
tg setup
Run the interactive setup to configure your chat ID. Only needed once.
tg listen
Listen for new incoming messages in the configured chat and write them to stdout until /eof is received.
tg config show
Print the config file path and its current contents:
# Config path: /home/user/.config/tg/config.toml
# chat_id = 123456789
tg config reset
Delete the config file so you can run setup again:
Configuration
Config is stored at ~/.config/tg/config.toml:
= "123456:ABC-your-token-here"
= 123456789
Both values are written during tg setup. To change either, run tg config reset and go through setup again.
Examples
# Send a quick note
# Results from a script
|
# Multiline message
# Bold alert via HTML
Library Macro
The crate exports a telegram! macro for quick fire-and-forget sends in Rust code:
use telegram;
async
Notes:
telegram!uses Markdown parse mode and non-silent notifications.- With default features,
telegram!is non-blocking and does not need.await. - Non-blocking behavior is controlled by the
non-blockingfeature. - If
non-blockingis disabled,telegram!uses a blocking send path. - Send failures are printed to stderr.
- For explicit error handling or custom parse/silent options, use
send_tg_message(...)directly.
Blocking API
If you want a synchronous API, call send_tg_message_blocking(...):
use ;
Feature Flags
[]
= { = "0.1", = false }
- Enable
non-blockingto maketelegram!usetokio::spawn. - Disable
non-blockingto maketelegram!use blocking sends.
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to https://unlicense.org/