Skip to main content

Asynchronous Python API for building Telegram bots

Project description

https://travis-ci.org/szastupov/aiotg.svg?branch=master

Asynchronous Python API for building Telegram bots, featuring:

  • Easy and declarative API

  • Hassle-free setup - no need for SSL certificates or static IP

  • Built-in support for analytics via botan.io

  • Automatic handling of Telegram API throttling or timeouts

Install it with pip:

pip install aiotg

Then you can create a new bot in few lines:

from aiotg import Bot

bot = Bot(api_token="...")

@bot.command(r"/echo (.+)")
def echo(chat, match):
    return chat.reply(match.group(1))

bot.run()

Now run it with a proper API_TOKEN and it should reply to /echo commands.

The example above looks like a normal synchronous code but it actually returns a coroutine. If you want to make an external request (and that’s what bots usually do) just use aiohttp and async/await syntax:

import aiohttp
from aiotg import Bot

bot = Bot(api_token="...")

@bot.command("bitcoin")
async def bitcoin(chat, match):
    url = "https://api.bitcoinaverage.com/ticker/global/USD/"
    async with aiohttp.get(url) as s:
        info = await s.json()
        await chat.send_text(info["24h_avg"])

bot.run()

For a more complete example, take a look at WhatisBot or Music Catalog Bot.

Have a question? Ask it on project’s Telegram chat.

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

aiotg-0.7.8.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

aiotg-0.7.8-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file aiotg-0.7.8.tar.gz.

File metadata

  • Download URL: aiotg-0.7.8.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiotg-0.7.8.tar.gz
Algorithm Hash digest
SHA256 4fbcfefcface505ac7cddcfe96c20d08da54e3215c2336f9500c42f99098691d
MD5 1af69b1b38754365d5a9d346357a52b7
BLAKE2b-256 5468c563df7218b84eefd7349e9bbfe3643b3ba4ea8733c899ee742f2ec011ce

See more details on using hashes here.

Provenance

File details

Details for the file aiotg-0.7.8-py3-none-any.whl.

File metadata

File hashes

Hashes for aiotg-0.7.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bef1089d2fcdbcd114ff2bb3d9523ea3c70522450f6d6fb5f94c356feca4e579
MD5 3c37059846d95afe380c934c889b9ad7
BLAKE2b-256 87240cc282a5443faa7ffaa4fb13c517e8f866411589734571d5adef4d7ff372

See more details on using hashes here.

Provenance

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