Telegram Bot API - Python SDK (using aiohttp)
Simple and fast client to call rest-api endpoints api.telegram.org using aiohttp package.
View at: https://pypi.org/project/python-telegram-bot-api/
How to install
pip3 install python-telegram-bot-api
Usage
Main example:
import asyncio
from api_tgbot import TgBot, TgException
TGBOT_TOKEN = "12345:YOUR_TOKEN"
APP_HOSTNAME = "https://YOUR_HOSTNAME.ngrok.io"
CHAT_ID = 123456789 # your chat id
client_tgbot = TgBot(token=TGBOT_TOKEN)
async def main_async():
try:
response = await client_tgbot.setWebhook("{hostname}/tgbot/wh".format(hostname=APP_HOSTNAME))
assert type(response) == bool
assert response == True
except TgException as e:
print(e)
try:
sent_msg = await client_tgbot.sendMessage(CHAT_ID, "Hello from Telegram Bot!")
assert sent_msg.chat.id == CHAT_ID
print(sent_msg.text)
except TgException as e:
print(e)
if __name__ == "__main__":
asyncio.run_until_complete(main_async())
Simple JSON-Example if you are not interested in pydantic models and want to use dict in answers:
import asyncio
from api_tgbot import TgBotJson
TGBOT_TOKEN = "12345:YOUR_TOKEN"
APP_HOSTNAME = "https://YOUR_HOSTNAME.ngrok.io"
CHAT_ID = 123456789 # your chat id
client_tgbot = TgBotJson(token=TGBOT_TOKEN)
async def main_async():
response = await client_tgbot.setWebhook("{hostname}/tgbot/wh".format(hostname=APP_HOSTNAME))
print(response.status) # 200
print(response.payload) # {'ok': True, 'result': True, 'description': 'Webhook was set'}
response = await client_tgbot.sendMessage(CHAT_ID, "Hello from Telegram Bot!")
print(response.status) # 200
print(response.payload) # {'ok': True, 'result': {'message_id': 786, 'from': {'id': ... } ... }
if __name__ == "__main__":
asyncio.run_until_complete(main_async())
Docs
- How to publish pypi package Medium article in Russian
Dependencies
This package depends on devtud / pygramtic >= 0.2.0 package.
Disclaimer
This project and its author is neither associated, nor affiliated with Telegram in anyway. See License section for more details.
License
This project is released under the GNU LESSER GENERAL PUBLIC LICENSE License.
Metadata
Release files for python-telegram-bot-api 0.0.7
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 | Actions |
|---|---|---|---|---|
| python-telegram-bot-api-0.0.7.tar.gz | 7.2 kB | Without provenance | Details for python-telegram-bot-api-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_telegram_bot_api-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for python_telegram_bot_api-0.0.7-py3-none-any.whl |
Total release size: 23.1 kB
Release files / python-telegram-bot-api-0.0.7.tar.gz
| Download URL | python-telegram-bot-api-0.0.7.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a25dd5d1bb2b1a5b155506accc68791274787173373276bb4d18822b73966e93
|
|
BLAKE2b-256 checksum How to use checksums |
bec0951d4e828b22430feb466cf1c57398c50bc0214e1e5e85b7fff4a3bf5146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.2.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5
|
Release files / python_telegram_bot_api-0.0.7-py3-none-any.whl
| Download URL | python_telegram_bot_api-0.0.7-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1775186caefd5906b27e321013873f3a30fce3f56ebcb2fef50e52ac577bbdbc
|
|
BLAKE2b-256 checksum How to use checksums |
32305e6054ba7373fccfe1ee7f67428d720920be5ae75c9d626ec00fe0539944
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.2.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5
|
Security for python-telegram-bot-api 0.0.7
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.