tgbsms - Telegram Bot Short Message Service
tgbsms is a simple Python utility for sending short messages and/or images via Telegram using the Telegram Bot API.
Features
- Automatically trims text to fit Telegram's maximum length
- Supports sending text and images
- Compatible with HTML, Markdown, and MarkdownV2 parse modes
Installation
You can install tgbsms directly from PyPI using pip:
pip install tgbsms
Usage
To send a message using tgbsms, you can use the send_message function. Here's an example:
from tgbsms import ParseMode
from tgbsms import send_message
send_message(
text="__message__",
image=open("image.png", "rb"),
parse_mode=ParseMode.MarkdownV2,
telegram_chat_id="<chat_id>",
telegram_bot_token="<your_bot_token>",
)
Parameters
| Parameter | Description | Optional |
|---|---|---|
| text | The message to send (string). If the message exceeds 4000 characters, it will be cropped. | Yes. If there is an image passed to function |
| image | file-like object, BytesIO, or URL (ыек) representing the image to send | Yes. If there is a text passed to function |
| parse_mode | One of ParseMode.HTML, ParseMode.Markdown, or ParseMode.MarkdownV2 (from enums) |
Yes. Defaults to HTML |
| telegram_bot_token | Your bot's token provided by BotFather. | Yes. If you export environment variable TELEGRAM_BOT_TOKEN |
| telegram_chat_id | The chat ID where the message will be sent. Can be an integer or string. | Yes. If you export environment variable TELEGRAM_CHAT_ID |
Environment Variables
If you prefer not to pass the telegram_bot_token and telegram_chat_id directly, you can set them as environment variables:
TELEGRAM_BOT_TOKEN: Your Telegram bot's token.TELEGRAM_CHAT_ID: The chat ID for the message.
Once the environment variables are set, the function can be used without passing these parameters directly
export TELEGRAM_BOT_TOKEN="<your_bot_token>"
export TELEGRAM_CHAT_ID="<chat_id>"
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for tgbsms 1.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tgbsms-1.3.5.tar.gz | 4.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tgbsms-1.3.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / tgbsms-1.3.5.tar.gz
| Download URL | tgbsms-1.3.5.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
338f89cd871eb7ed70bea8d9f157ad32ddf3d7f1be63fb4673af8fd5909ac056
|
|
BLAKE2b-256 checksum How to use checksums |
ae5cc434b44a36a5063243d6255232db105dd45b4462845b7bc6a1e430d7a3f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.6
|
Release files / tgbsms-1.3.5-py3-none-any.whl
| Download URL | tgbsms-1.3.5-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7ed5a9e34afe0b6cd56bd2401f9179aa614d03a415f6a8f0b918779cc2051ac
|
|
BLAKE2b-256 checksum How to use checksums |
faaaebbdddde26f269bca2a77254e47dc2cdf3a7ce1a12403a3d01e7d27e8823
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.6
|
Security for tgbsms 1.3.5
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.