Skip to main content

Simple and fast client to call rest-api endpoints `api.telegram.org` using `aiohttp` package.

Project description

Telegram Bot API - Python SDK (using aiohttp)

pytest asyncio, aiohttp Chat on Telegram Last Release

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

  1. 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.

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

python-telegram-bot-api-0.0.7.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

python_telegram_bot_api-0.0.7-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file python-telegram-bot-api-0.0.7.tar.gz.

File metadata

  • Download URL: python-telegram-bot-api-0.0.7.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for python-telegram-bot-api-0.0.7.tar.gz
Algorithm Hash digest
SHA256 a25dd5d1bb2b1a5b155506accc68791274787173373276bb4d18822b73966e93
MD5 6c3484f30a5797eefffa6404222c7ed4
BLAKE2b-256 bec0951d4e828b22430feb466cf1c57398c50bc0214e1e5e85b7fff4a3bf5146

See more details on using hashes here.

File details

Details for the file python_telegram_bot_api-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: python_telegram_bot_api-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for python_telegram_bot_api-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1775186caefd5906b27e321013873f3a30fce3f56ebcb2fef50e52ac577bbdbc
MD5 89b71fddee71169af79a3947a45fb6f0
BLAKE2b-256 32305e6054ba7373fccfe1ee7f67428d720920be5ae75c9d626ec00fe0539944

See more details on using hashes here.

Supported by

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