Skip to content
This repository has been archived by the owner. It is now read-only.
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

aiotg

Telegram Bot API wrapper for aiohttp.

Build Status

Features

Library Installation

pip install git+https://github.com/eigenein/aiotg.git

You may want to state the library in requirements.txt:

git+https://github.com/eigenein/aiotg.git

Getting Started

Low-level API

Receiving updates:

offset = 0
async with aiotg.Telegram(token) as telegram:  # type: aiotg.Telegram
    while True:
        updates = await telegram.get_updates(offset, limit=100, timeout=5)
        if not updates:
            continue
        for update in updates:
            logging.debug("Got update: %s", update)
        offset = updates[-1].id + 1

High-level API

Define a class to receive bot updates:

class SimpleBot(aiotg.Bot):
    async def on_update(self, telegram: aiotg.Telegram, update: aiotg.Update):
        logging.info("Received update: %r", update)

Then use one of the runners to start receiving updates:

Long-polling Runner

token = "…"  # Telegram bot API token
connector = aiohttp.TCPConnector(family=socket.AF_INET, verify_ssl=False)
telegram = aiotg.Telegram(token, connector=connector)
runner = aiotg.LongPollingRunner(telegram, SimpleBot())

asyncio.get_event_loop().run_until_complete(runner.run())

Webhook Runner

Not implemented yet.

Running module or package as a bot

To avoid writing boilerplate code to set up logging, connection and runner – you can simply run aiotg command with the fully-qualified class name:

aiotg --token <TOKEN> aiotg.SimpleBot

See aiotg --help for more options.

Pattern Matching

Not implemented yet.

States

Not implemented yet.

Examples

These bots are built with aiotg:

Source Code

The project is hosted on GitHub.

Please feel free to submit an issue if you have found a bug or have some suggestion in order to improve the library.

Dependencies

Releases

No releases published

Languages

You can’t perform that action at this time.