To install the tg
crate, ensure you have the nightly version of Rust (1.82+). You can install the crate via cargo
with the following command:
cargo install tg
The tg
tool allows you to interact with a Telegram bot to send messages, get bot information, and list channels configured in your configuration file.
Create a configuration file at ~/.config/tg.toml
(or specify a different path with the --config
option) with the following structure:
[channels]
channel1 = "1234305221"
channel2 = "-1001234305221"
group_and_topic = "1234305221/7"
Each entry under [channels]
represents a Telegram channel or group. Channels are specified by their ID, and groups are specified by their ID followed by a thread ID separated by a /
.
Ensure you have set the TELEGRAM_BOT_KEY
environment variable with your Telegram bot API key:
export TELEGRAM_BOT_KEY="your_bot_api_key"
Send a message to a specified channel:
tg send -c channel2 "Today I'm feeling blue" "//this is still a part of the message"
Retrieve information about the bot:
tg bot-info
List all the channels defined in the configuration file:
tg list-channels
An example of aliases to use with it. I myself gen them through this, then remove ones I don't intend to use often.
tg gen-aliases
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
This repository follows my best practices.