Name | aiotg JSON |
Version |
2.0.0
JSON |
| download |
home_page | |
Summary | Asynchronous Python API for building Telegram bots |
upload_time | 2023-03-12 20:46:20 |
maintainer | |
docs_url | None |
author | |
requires_python | |
license | |
keywords |
asyncio
telegram
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
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 chatbase.com
- Automatic handling of Telegram API throttling or timeouts
Install it with pip:
.. code:: sh
pip install aiotg
Then you can create a new bot in few lines:
.. code:: python
from aiotg import Bot, Chat
bot = Bot(api_token="...")
@bot.command(r"/echo (.+)")
def echo(chat: 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.
.. 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:
.. code:: python
import aiohttp
from aiotg import Bot, Chat
bot = Bot(api_token="...")
@bot.command("bitcoin")
async def bitcoin(chat: Chat, match):
url = "https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD"
async with aiohttp.ClientSession() as session:
response = await session.get(url)
info = await response.json()
await chat.send_text(str(info["averages"]["day"]))
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:
.. code:: python
...
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
---------------
- `Async IO <https://github.com/szastupov/aiotg/blob/master/examples/async.py>`__
- `Send image <https://github.com/szastupov/aiotg/blob/master/examples/getimage.py>`__
- `Post to channel <https://github.com/szastupov/aiotg/blob/master/examples/post_to_channel.py>`__
- `Webhooks mode <https://github.com/szastupov/aiotg/blob/master/examples/webhook.py>`__
- `Sender id <https://github.com/szastupov/aiotg/blob/master/examples/whoami.py>`__
For a real world example, take a look at
`WhatisBot <https://github.com/szastupov/whatisbot/blob/master/main.py>`__ or `Music Catalog Bot <https://github.com/szastupov/musicbot>`__.
For more information on how to use the project, see the project's `documentation <http://szastupov.github.io/aiotg/index.html>`__.
Raw data
{
"_id": null,
"home_page": "",
"name": "aiotg",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "asyncio,telegram",
"author": "",
"author_email": "Stepan Zastupov <stepan.zastupov@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/cf/de/ed3aaeae5956eb5e2ff98698d07cce0246009ed6654840e45bd376fc4266/aiotg-2.0.0.tar.gz",
"platform": null,
"description": "aiotg\n=====\n\nAsynchronous Python API for building Telegram bots, featuring:\n\n- Easy and declarative API\n- Hassle-free setup - no need for SSL certificates or static IP\n- Built-in support for analytics via chatbase.com\n- Automatic handling of Telegram API throttling or timeouts\n\nInstall it with pip:\n\n.. code:: sh\n\n pip install aiotg\n\nThen you can create a new bot in few lines:\n\n.. code:: python\n\n from aiotg import Bot, Chat\n\n bot = Bot(api_token=\"...\")\n\n @bot.command(r\"/echo (.+)\")\n def echo(chat: Chat, match):\n return chat.reply(match.group(1))\n\n bot.run()\n\nNow run it with a proper API\\_TOKEN and it should reply to /echo commands.\n\n.. note:: Type annotations are not required but will help your editor/IDE to provide code completion.\n\nThe example above looks like a normal synchronous code but it actually returns a coroutine.\nIf you want to make an external request (and that's what bots usually do) just use aiohttp and async/await syntax:\n\n.. code:: python\n\n import aiohttp\n from aiotg import Bot, Chat\n\n bot = Bot(api_token=\"...\")\n\n @bot.command(\"bitcoin\")\n async def bitcoin(chat: Chat, match):\n url = \"https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD\"\n async with aiohttp.ClientSession() as session:\n response = await session.get(url)\n info = await response.json()\n await chat.send_text(str(info[\"averages\"][\"day\"]))\n\n bot.run()\n\n\nBut what if you just want to write a quick integration and don't need to provide a conversational interface? We've got you covered!\nYou 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:\n\n.. code:: python\n\n ...\n channel = bot.channel(\"@yourchannel\")\n private = bot.private(\"1111111\")\n\n async def greeter():\n await channel.send_text(\"Hello from channel!\")\n await private.send_text(\"Why not greet personally?\")\n ...\n\n\nExamples\n---------------\n\n- `Async IO <https://github.com/szastupov/aiotg/blob/master/examples/async.py>`__\n- `Send image <https://github.com/szastupov/aiotg/blob/master/examples/getimage.py>`__\n- `Post to channel <https://github.com/szastupov/aiotg/blob/master/examples/post_to_channel.py>`__\n- `Webhooks mode <https://github.com/szastupov/aiotg/blob/master/examples/webhook.py>`__\n- `Sender id <https://github.com/szastupov/aiotg/blob/master/examples/whoami.py>`__\n\nFor a real world example, take a look at\n`WhatisBot <https://github.com/szastupov/whatisbot/blob/master/main.py>`__ or `Music Catalog Bot <https://github.com/szastupov/musicbot>`__.\n\nFor more information on how to use the project, see the project's `documentation <http://szastupov.github.io/aiotg/index.html>`__.\n",
"bugtrack_url": null,
"license": "",
"summary": "Asynchronous Python API for building Telegram bots",
"version": "2.0.0",
"split_keywords": [
"asyncio",
"telegram"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b483e183c14ac3aa8a5852fc48b56d7872cc904614040f002e023b68a4c960ea",
"md5": "ea181e275d641746922837727f8f4d8e",
"sha256": "05f7f7cccff9dc25e86d54efbfda862032c08302be41d2d207675a61802ac11e"
},
"downloads": -1,
"filename": "aiotg-2.0.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "ea181e275d641746922837727f8f4d8e",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 13717,
"upload_time": "2023-03-12T20:46:18",
"upload_time_iso_8601": "2023-03-12T20:46:18.989343Z",
"url": "https://files.pythonhosted.org/packages/b4/83/e183c14ac3aa8a5852fc48b56d7872cc904614040f002e023b68a4c960ea/aiotg-2.0.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cfdeed3aaeae5956eb5e2ff98698d07cce0246009ed6654840e45bd376fc4266",
"md5": "114c01df8a69d381cda0f91f0fc2b7fc",
"sha256": "9932f117d3faaf10ee6b36c580ffa033d4a3311b0d54dcbd261cb93e8bae3b1e"
},
"downloads": -1,
"filename": "aiotg-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "114c01df8a69d381cda0f91f0fc2b7fc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12305,
"upload_time": "2023-03-12T20:46:20",
"upload_time_iso_8601": "2023-03-12T20:46:20.696060Z",
"url": "https://files.pythonhosted.org/packages/cf/de/ed3aaeae5956eb5e2ff98698d07cce0246009ed6654840e45bd376fc4266/aiotg-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-12 20:46:20",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "aiotg"
}