Skip to main content

telegram-messager

Simplest util to send messages to Telegram.

Usage

Python

from telegram_messager import TelegramMessager

TM = TelegramMessager(token='token', chatid='chatid')
TM.send_text('message')

CLI

$ tgmg -h 

usage: tgmg [-h] [--text TEXT] [--files FILES [FILES ...]] [--token TOKEN] [--token-file TOKEN_FILE]
            [--token-env-var TOKEN_ENV_VAR] [--chat CHAT] [--chat-file CHAT_FILE] [--chat-env-var CHAT_ENV_VAR]

Simplest tool to send messages using Telegram HTTP API

optional arguments:
  -h, --help            show this help message and exit
  --text TEXT, -s TEXT  text to send (default: )
  --files FILES [FILES ...], -f FILES [FILES ...]
                        documents to send (default: None)
  --token TOKEN, -t TOKEN
                        bot token (default: None)
  --token-file TOKEN_FILE
                        bot token file to read token from; will be used if no --token specified (default: None)
  --token-env-var TOKEN_ENV_VAR
                        bot token environment variable name to read from; will be used if neither --token nor --token-file
                        specified (default: TELEGRAM_MESSAGER_BOT_TOKEN)
  --chat CHAT, -c CHAT  chat id (default: None)
  --chat-file CHAT_FILE
                        chat id file to read the value from (default: None)
  --chat-env-var CHAT_ENV_VAR
                        chat id environment variable name to read from (default: TELEGRAM_MESSAGER_CHAR_ID)

How to create bot and channel for it

  1. Create a bot by BotFather, get its TOKEN
  2. Make public channel with @SomeChannelName, add this bot as admin
  3. Get this ChatId by visiting https://api.telegram.org/botTOKEN/sendMessage?chat_id=@SomeChannelName&text=123 (with replaces):
TOKEN=t
CHANNEL=c
curl "https://api.telegram.org/bot${TOKEN}/sendMessage?chat_id=${CHANNEL}&text=123" | jq '.result.chat.id'
  1. Make channel private (if necessary)
  2. Now u can send messages to this channel by command curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d chat_id=ChatId -d text="your message"

Metadata

Release files for telegram-messager 0.2.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-messager 0.2.1
File Size Uploaded
telegram_messager-0.2.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-messager 0.2.1
File Interpreter ABI Platform
telegram_messager-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / telegram_messager-0.2.1.tar.gz

Download URL telegram_messager-0.2.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
360a2172725d11f9834435006808437dbf99d6ebf2baafb513fbdd56770c610a
BLAKE2b-256 checksum
How to use checksums
18b228499763ead8ab1d6160c257e768508032f5108b9ba02c3f78909cb3bbfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.19

Release files / telegram_messager-0.2.1-py3-none-any.whl

Download URL telegram_messager-0.2.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de72844ca21f43f882b95e369f677167d7b304a970069d46a97becd434fc6c75
BLAKE2b-256 checksum
How to use checksums
39a026102673320cdce04da8df8df0850aae7977ae019f34ac565ceb80efdd12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.19

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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