This is a simple project to send messages to a Telegram chat using a CLI.
The motivation was: I hate waiting for long processes to run, so I can pipe the result of the command to my telegram with this CLI and get notified when it's done, having a way to glance at the result. Meanwhile, I can do other things.
If the message is bigger than what is allowed by Telegram (4096), it will be split into multiple messages.
To work, we need two environment variables: TELEGRAM_API_TOKEN
and TELEGRAM_CHAT_ID
.
Setting Environment Variables on Windows
- Search for 'Environment Variables' in your Start Menu.
- Click on 'Edit the system environment variables.'
- Click on 'Environment Variables' at the bottom right corner.
- Under 'System Variables', click on the 'New' button.
- In the 'Variable name' field, enter
TELEGRAM_API_TOKEN
and in the 'Variable value' field, enter your telegram API token. Click 'OK'. - Repeat the process for the
TELEGRAM_CHAT_ID
variable.
These changes will take effect the next time you open a command prompt.
Setting Environment Variables on Linux
- Open your terminal.
- Use the
export
command to add your environment variables. Replaceyour_telegram_api_token
andyour_telegram_chat_id
with your actual values:export TELEGRAM_API_TOKEN=your_telegram_api_token export TELEGRAM_CHAT_ID=your_telegram_chat_id
- To make these changes permanent, add these lines to your
~/.bashrc
,~/.bash_profile
, or~/.profile
file, and then source it:echo 'export TELEGRAM_API_TOKEN=your_telegram_api_token' >> ~/.bashrc echo 'export TELEGRAM_CHAT_ID=your_telegram_chat_id' >> ~/.bashrc source ~/.bashrc
Setting Environment Variables on MacOS
- Open your terminal.
- Use the
export
command to add your environment variables. Replaceyour_telegram_api_token
andyour_telegram_chat_id
with your actual values:export TELEGRAM_API_TOKEN=your_telegram_api_token export TELEGRAM_CHAT_ID=your_telegram_chat_id
- To make these changes permanent, add these lines to your
~/.bash_profile
or~/.zshrc
file (depending on your default shell), and then source it:echo 'export TELEGRAM_API_TOKEN=your_telegram_api_token' >> ~/.bash_profile echo 'export TELEGRAM_CHAT_ID=your_telegram_chat_id' >> ~/.bash_profile source ~/.bash_profile
For zsh
:
echo 'export TELEGRAM_API_TOKEN=your_telegram_api_token' >> ~/.zshrc
echo 'export TELEGRAM_CHAT_ID=your_telegram_chat_id' >> ~/.zshrc
source ~/.zshrc
Please replace your_telegram_api_token
and your_telegram_chat_id
with your actual values. The commands should be run without the angle brackets.
tme.exe Hello World
Will send:
Hello World
tme.exe "Hello World"
Will send:
Hello World
dir | tme.exe
Will send:
Volume in drive C is vault
Volume Serial Number is FX42-6667
Directory of C:\path\to\this\project\Telegram.Cli\Telegram.Cli\bin\Debug\net6.0
23/05/2023 22:59 <DIR> .
23/05/2023 22:59 <DIR> ..
23/05/2023 22:59 401 tme.deps.json
23/05/2023 23:03 14.336 tme.dll
23/05/2023 23:03 148.992 tme.exe
23/05/2023 23:03 12.660 tme.pdb
23/05/2023 22:59 147 tme.runtimeconfig.json
5 File(s) 176.536 bytes
2 Dir(s) 9.889.064.771.584 bytes free