Tiny asyncio-based telgram bot-api wrapper library. Checkout siotelegram as next step of io/logic splitting.
- aiotg is framework, not library and have no proxy support.
- Raw api calls translation is better for understanding and will not break if telegram api will be changed.
snake_case
- Simple as telegram api is.
- Works with any json provider (
aiohttp
(default),aiorequests
, etc.) snake_case
api converted to telegramcamelCase
.- Polling
offset
handled for you viaget_updates
method. - Handling timeout between requests automatically (via
pause
keyword-only argument). - Source code is short and simple.
python -m pip install aiotelegram
import aiotelegram
async def ...(...):
api = aiotelegram.Api(token)
while True:
response = await api.get_updates()
if not response["ok"]:
...
else:
for update in response["result"]:
...
await asyncio.sleep(delay)
async def ...(...):
await api.send_message(
chat_id=123456,
text="*foobar*",
parse_mode="Markdown",
)
aiotelegram.Api(token, *, json_provider=None, loop=None, pause=0.05)
-
token (str): bot-api token
-
json_provider (callable): async json provider. Default provider based on
aiohttp
. Example:async def json_provider(url, *, data, loop): # getting json return json
- url (str): https address to get
- data (dict): same as
data
foraiohttp
andrequests
- loop (asyncio.BaseEventLoop): event loop to use
-
loop (asyncio.BaseEventLoop): loop to use
-
pause (int/float): delay between requests in seconds