Skip to main content

telegram-cli

PyPI Changelog Tests License

Python CLI tool and library for sending messages to Telegram

Installation

Install this tool using pip:

pip install telegram-cli

Usage

Basic

For sending a simple text message to a user o group, run:

export TELEGRAM_TOKEN='bot123456:de4dbeefde4dbeefde4dbeefde4dbeefde4dbeef' 

$ tgm message send --text 'Hello' --chat-id 123456
message-id: 676

Text from a stream (file or stdin)

For sending the content of a text file as message text:

# you have a text file with a message you want to send
echo "hey dude" > message.txt 

# (1) use the `--text-file` option
tgm message send --chat-id 123456 --text-file message.txt 

# (2) use `<`
tgm message send --chat-id 123456 < message.txt 

# (3) use `|`
cat message.txt | tgm message send --chat-id 123456
# or
echo "hey dude, it's me again" | tgm message send --chat-id 123456 

# (4) type your message and send it by typing `CTRL+D`
tgm message send --chat-id 123456
Hey dude, yeah it's me again!
<CTRL+D>

Parse modes

For using one of the supported parse modes (MarkdownV2 or HTML) of the entities in the message, run:

tgm message send --parse-mode "MarkdownV2" --text '**Hello**' --chat-id 123456

tgm message send --parse-mode "HTML" --text '<b>Hello</b>' --chat-id 123456

See the available formatting options to learn how to use --parse-mode.

For help, run:

telegram-cli --help

You can also use:

python -m telegram_cli --help

Send a file document

You can also send file documents:

# use the `--file` option for any kind of file.
tgm message send-document --chat-id 123456 --file report.pdf   

# use the `--caption` option to add a caption to your document.
tgm message send-document --chat-id 123456 --file report.pdf --caption "Here is the last report."

Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

cd telegram-cli
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Add new tests with Telegram API calls

The pytest-recording pytest plugin records all HTTP requests and responses as a "cassette" in the tests/cassettes/ folder.

When you add a new test, you must run pytest using the --record-mode option. Here's an example:

pytest --record-mode=once test_send_message_document.py

The --record-mode has multiple values:

  • once writes the HTTP traffic in a cassette once if there isn't an existing cassette for the test. If a cassette already exists, it uses its content for the test without sending any network traffic.
  • rewrite executes and rewrites all HTTP requests, even when a cassette already exists.

Metadata

Release files for telegram-cli 0.3.0

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-cli 0.3.0
File Size Uploaded Provenance Actions
telegram_cli-0.3.0.tar.gz 9.1 kB Without provenance Details for telegram_cli-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for telegram-cli 0.3.0
File Interpreter ABI Platform Actions
telegram_cli-0.3.0-py3-none-any.whl Python 3 none any Details for telegram_cli-0.3.0-py3-none-any.whl

Total release size: 18.3 kB

Release files / telegram_cli-0.3.0.tar.gz

Download URL telegram_cli-0.3.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4c2cf01d145dace2c51f13898668bce9eb1c49d3bdc0b846e217a372828b0254
BLAKE2b-256 checksum
How to use checksums
1f3bf395cd3290f328d6d955caaf147e5e90ee404d5f27e9c1e373ab64e5ac04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release files / telegram_cli-0.3.0-py3-none-any.whl

Download URL telegram_cli-0.3.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d30a24142af29a8ad4adebfadfbc52c748fc74fd13c1ffec81f0c84b2b2452ff
BLAKE2b-256 checksum
How to use checksums
9436aad07b05f930f6385505ea96cabc12205dd3aa7f829fea7fda34beb14c4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Security for telegram-cli 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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