Posted on :: Tags: , , ,

There is a small Python command-line program called telegram-send that allows you to send messages to your Telegram account.

First, you need to register a new bot with @BotFather and get an API token. Then, run pip3 install --user telegram-send and prepare a config file at ~/.config/telegram-send.conf:

[telegram]
token = <TOKEN_YOU_GET_FROM_BOT_FATHER>
chat_id = <CHAT_OR_USER_ID>

You’ll need to start a conversation with the bot and find your user ID (which is identical to the chat ID for the conversation you start with the bot).

After that, you can send yourself messages from the CLI like this:

telegram-send "Hello Telegram."

You can also send Markdown-formatted messages, audio, stickers, and more using various command-line options:

usage: telegram-send [-h] [--format {text,markdown,html}] [--stdin] [--pre]
                     [--disable-web-page-preview] [--silent] [-c]
                     [--configure-channel] [--configure-group]
                     [-f FILE [FILE ...]] [-i IMAGE [IMAGE ...]]
                     [-s STICKER [STICKER ...]]
                     [--animation ANIMATION [ANIMATION ...]]
                     [--video VIDEO [VIDEO ...]] [--audio AUDIO [AUDIO ...]]
                     [-l LOCATION [LOCATION ...]]
                     [--caption CAPTION [CAPTION ...]] [--config CONF] [-g]
                     [--file-manager] [--clean] [--timeout TIMEOUT]
                     [--version]
                     [message [message ...]]