Telegram toolkit
Project description
telegramtk
Telegram toolkit
This package provides easy (and sync) access for the Telegram Bot API.
Installation
pip install telegramtk
Setup
First of all you must create a Telegram bot and grab the bot token.
import telegramtk
telegramtk.init('<your-telegram-bot-token-here>')
Send message
import telegramtk
telegramtk.send_message(to, msg)
Notes:
to
is the recipient and must be a chat id (integer value) or a known name (string value).msg
is the message (string value) and can be "Markdown" formatted.
Error handling
If an error ocurred during the request to the Telegram API, an exception is raised. You can find this exception at:
import telegramtk
from telegramtk.exceptions import TelegramError
try:
telegramtk.send_message(to, msg)
except TelegramError as err:
handle_error(err)
Escape markdown
It's common to send Markdown content through Telegram, but sometimes we want to escape Markdown symbols in order to avoid syntax errors when parsing.
For that end, you might use the following function:
from telegramtk.utils import escape_markdown
>>> escape_markdown('Just some *Markdown* _stuff_ [here](https://example.com/)')
'Just some \\*Markdown\\* \\_stuff\\_ \\[here\\]\\(https://example\\.com/\\)'
💡 Source: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/helpers.py#L45
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
telegramtk-0.0.8.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for telegramtk-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c79d162425474776e51f8e79e4b4458525efab2ef6d3f057cf632c7e28643031 |
|
MD5 | 4a003223b794dbc9801404148b1a4873 |
|
BLAKE2b-256 | 81bc373cb163a2c2588b6b06c8acfc41d4ce07edb34538506dc72f2458f5b35c |