Aiotg

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:

Then you can create a new bot in few lines:

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

Note

Type annotations are not required but will help your editor/IDE to provide code completion.

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:

But what if you just want to write a quick integration and don’t need to provide a conversational interface? We’ve got you covered! You can send messages (or any other media) by constructing a Chat object with user_id or channel name. We even saved you some extra keystrokes by providing handy Channel constructors:

Examples¶

  • Async IO
  • Send image
  • Post to channel
  • Webhooks mode
  • Sender id

For a real world example, take a look at WhatisBot or Music Catalog Bot.

For more information on how to use the project, see the project’s documentation. Have a question? Ask it on project’s Telegram chat.

Reference¶

Bot Interface¶

Chat Interface¶

Leave a Reply

Your email address will not be published. Required fields are marked *