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 |
|---|---|---|
-p NAME |
--profile NAME |
Profile to use (overrides TG_PROFILE env var) |
-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 |
Profiles (-p / --profile)
Profiles let you send to different bots or chats without changing your default config.
# Set up a named profile
# Send using a profile
# Select a profile via environment variable
TG_PROFILE=work
# Profile-specific subcommands
--profile is a global flag accepted before or after the subcommand:
Attach files (tg attach)
Send one or more files as Telegram document attachments. Shell globbing works as expected.
# Single file
# Multiple files
# Glob pattern
# Silent attachment
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 attach
Send files as document attachments. Accepts one or more file paths; shell globbing is handled by the shell before tg sees the arguments.
tg config show
Print configuration status without revealing secrets. When called without --profile, also lists all named profiles:
# Config path: /home/user/.config/tg/config.toml
# Config file: present
# Chat ID: 123456789
# Secret Service: available
# Token: configured (Secret Service)
#
# Available profiles:
# personal: Chat ID: 111222333, Token: configured (Secret Service)
# work: Chat ID: 987654321, Token: configured (Secret Service)
# Inspect a specific profile
# Profile: work
# Config path: /home/user/.config/tg/config.toml
# ...
tg config reset
Delete the config and keyring token for a profile so you can run setup again. Without --profile, resets the default:
# Reset a named profile only (other profiles are unaffected)
Configuration
tg stores bot tokens in Secret Service (GNOME Keyring / KWallet) when available.
If unavailable, it falls back to plaintext in ~/.config/tg/config.toml and prints a warning.
All profiles share a single config file. The default profile lives at the top level; named profiles are under [profiles.<name>]:
# Default profile
= 123456789
# token = "..." # plaintext fallback only
[]
= 987654321
[]
= 111222333
Keyring entries follow the same pattern — "telegram-bot-token" for the default, "telegram-bot-token-<name>" for named profiles.
To reconfigure a profile, run tg [--profile NAME] config reset then tg [--profile NAME] setup.
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.
- The macro reads
TG_PROFILEat runtime to select a profile. - For explicit error handling or custom parse/silent/profile 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/