Skip to main content

Simplest util to send messages and documents to Telegram

Project description

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"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_messager-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_messager-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file telegram_messager-0.2.0.tar.gz.

File metadata

  • Download URL: telegram_messager-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.19

File hashes

Hashes for telegram_messager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 86b59404c582236d9df51b8fa9c0425d362ae084078312e54baec7be339562b2
MD5 e23bfb9f31b224cd88bc204b86b6e889
BLAKE2b-256 060f5aca156cedbf6c06ed38427882c7326ccdf38b1918ce20126d26a32a4844

See more details on using hashes here.

File details

Details for the file telegram_messager-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_messager-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 334db6776874eec37a38aafaab0862f5248ab6b4ccc2921a86f10beb28ecf2b8
MD5 657eaa7d50c28b2199df7b6d62ea088c
BLAKE2b-256 13a30d0418f091812ecfab0c5917b02fda66857d2b4ded4ca1996939d0d4d9c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page