Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Asynchronous Python API for building Telegram bots

Project Description

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()

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:

...
channel = bot.channel("@yourchannel")
private = bot.private("1111111")

async def greeter():
    await channel.send_text("Hello from channel!")
    await private.send_text("Why not greet personally?")
...

Examples

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.

Release History

Release History

This version
History Node

0.9.2

History Node

0.9.1

History Node

0.9.0

History Node

0.8.1

History Node

0.8.0

History Node

0.7.22

History Node

0.7.21

History Node

0.7.20

History Node

0.7.19

History Node

0.7.18

History Node

0.7.17

History Node

0.7.16

History Node

0.7.15

History Node

0.7.14

History Node

0.7.13

History Node

0.7.12

History Node

0.7.11

History Node

0.7.10

History Node

0.7.9

History Node

0.7.8

History Node

0.7.7

History Node

0.7.6

History Node

0.7.5

History Node

0.7.4

History Node

0.7.3

History Node

0.7.2

History Node

0.7.1

History Node

0.7.0

History Node

0.6.5

History Node

0.6.4

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
aiotg-0.9.2.tar.gz (10.4 kB) Copy SHA256 Checksum SHA256 Source Jun 5, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting