Skip to main content

telegram-send

Version pyversions License

Telegram-send is a command-line tool to send messages and files over Telegram to your account or to a channel. It provides a simple interface that can be easily called from other programs.

Table of Contents

Usage

To send a message:

telegram-send "hello, world"

To send a file:

telegram-send --file document.pdf

To send an image with an optional caption:

telegram-send --image photo.jpg --caption "The Moon at night"

Telegram-send integrates into your file manager (Thunar, Nautilus and Nemo):

Install

Install telegram-send system-wide with pip:

sudo pip3 install telegram-send

Or if you want to install it for a single user:

pip3 install telegram-send

If installed for a single user you need to add ~/.local/bin to their path:

echo 'PATH="$HOME/.local/bin:$PATH"' >> ~/.profile

(This will be in effect on the next login, do a . ~/.profile for the impatient.)

And finally configure it with telegram-send --configure if you want to send to your account, or with telegram-send --configure-channel to send to a channel.

Use the --config option to use multiple configurations. For example to set up sending to a channel in a non-default configuration: telegram-send --config channel.conf --configure-channel. Then always specify the config file to use it: telegram-send --config channel.conf "hello".

Examples

Here are some examples to get a taste of what is possible with telegram-send.

alert on completion of shell commands

Receive an alert when long-running commands finish with the tg alias, based on Ubuntu’s built-in alert. Put the following in your ~/.bashrc:

alias tg='telegram-send "$([ $? = 0 ] && echo "" || echo "error: ") $(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*tg$//'\'')"'

And then use it like sleep 10: tg.

To automatically receive notifications for long running commands, use ntfy with the Telegram backend.

periodic messages with cron

We can combine telegram-send with cron to periodically send messages. Here we will set up a cron job to send the Astronomy Picture of the Day to the astropod channel.

Create a bot by talking to the BotFather, create a public channel and add your bot as administrator to the channel. You will need to explicitly search for your bot’s username when adding it. Then run telegram-send --configure-channel --config astropod.conf. We will use the apod.py script that gets the daily picture and calls telegram-send to post it to the channel.

We create a cron job /etc/cron.d/astropod with the content:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
0 1 * * * telegram ~/apod.py --config ~/astropod.conf

Make sure the file ends with a newline. Cron will then execute the script every day at 1:00 as the user telegram. Join the astropod channel to see the result.

supervisor process state notifications

Supervisor controls and monitors processes. It can start processes at boot, restart them if they fail and also report on their status. Supervisor-alert is a simple plugin for supervisor that sends messages on process state updates to an arbitrary program. Using it with telegram-send (by using the --telegram option), you can receive notifications whenever one of your processes exits.

Uninstall

sudo telegram-send --clean
sudo pip3 uninstall telegram-send

Or if you installed it for a single user:

telegram-send --clean
pip3 uninstall telegram-send

Release files for telegram-send 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telegram-send 0.7.1
File Size Uploaded
telegram-send-0.7.1.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-send 0.7.1
File Interpreter ABI Platform
telegram_send-0.7.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.3 kB

Release files / telegram-send-0.7.1.tar.gz

Download URL telegram-send-0.7.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec45f1055b759b8e65198587bf909419e1b4f715e90f7e3a1bde3bd6ed742820
BLAKE2b-256 checksum
How to use checksums
574187bf222fa529928f6887fd019b01c4e600ccaf15050dc28cb67361260514
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / telegram_send-0.7.1-py2.py3-none-any.whl

Download URL telegram_send-0.7.1-py2.py3-none-any.whl
Size 10.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
41448c73edc10346f902cf725b8e3ed9a95254e5780fce3b956800bfcc4a9f17
BLAKE2b-256 checksum
How to use checksums
78606a83253d4072cec18795588e3ca26cfaca02c67d6715dda1bb015da4d5ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.39.2

2 release files

0.39.1

2 release files

0.39

2 release files

0.38

2 release files

0.37

2 release files

0.36

2 release files

0.35

2 release files

0.34

2 release files

0.33.2

2 release files

0.33.1

2 release files

0.33

2 release files

0.32

2 release files

0.31

2 release files

0.30

2 release files

0.29

2 release files

0.28

2 release files

0.27

2 release files

0.26

2 release files

0.25

2 release files

0.24

2 release files

0.23

2 release files

0.22

2 release files

0.21

2 release files

0.20

2 release files

0.19

2 release files

0.18.1

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

This release

0.7.1 This release

2 release files

0.7

2 release files

0.6

3 release files

0.5

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page