Skip to main content

AioTele is a Python module for building Telegram bots using asyncio. It offers an intuitive API for handling updates, commands, and messaging, supporting both long polling and webhooks for scalable, high-performance bots.

Project description

AioTele is a new library written in pure python with asynchrony, this project was released quite recently but has basic functionality

An example of a bot on AioTele:

from aiotele.bot import Bot
from aiotele.keyboards import Button, MarkupButton, MarkupButtonInline, InlineButton
from aiotele import html, LEAVE_TRANSITION, JOIN_TRANSITION, JOIN_TRANSITION
from aiotele.types import MessageObject, CommandObject, CallbackQuery, NewChatMember, LeaveChatMember
from aiotele.exceptions import ValidationError, TelegramBadRequest
import asyncio

TOKEN = "YOU_TOKEN"
bot = Bot(TOKEN)

@bot.chat_member(LEAVE_TRANSITION)
async def leave_chat_member(leave_member: LeaveChatMember):
    await leave_member.reply(f"Bye {leave_member.leave_member.full_name}! was deleted by the administrator {leave_member.from_user.full_name}!")

@bot.chat_member(JOIN_TRANSITION)
async def new_chat_member(new_member: NewChatMember):
    await new_member.answer(f"Hello {new_member.new_member.full_name}! Added you {new_member.old_member.full_name}!")

@bot.my_chat_member(JOIN_TRANSITION)
async def bot_join_chat_member(new_member: NewChatMember):
    await new_member.answer(f"Thank you for adding me to the chat. {new_member.old_member.full_name}!")

@bot.message_handler("inline", prefix="!/.")
async def start(msg: MessageObject, command: CommandObject):
    markup = MarkupButtonInline()
    markup.add(InlineButton("Start", "start"))
    markup.add(InlineButton("Start2", "start2"))
    await msg.answer(f"Hello {html.link(value=msg.from_user.full_name, link=f'tg://user?id={msg.from_user.id}')}!", reply_markup=markup.keyboards)

@bot.message_handler("usual", prefix="!/.")
async def start(msg: MessageObject, command: CommandObject):
    await bot.send_photo(chat_id=msg.chat.id, url_photo="https://i.ytimg.com/an_webp/gxnqVXilX0I/mqdefault_6s.webp?du=3000&sqp=CIq-wr0G&rs=AOn4CLBKglLYZ0fdfIScCNqeRFrmk47mpA")
    markup = MarkupButton(one_time_keyboard=True)
    markup.add(Button("Start"))
    await msg.reply(f"Hello {html.link(value=msg.from_user.full_name, link=f'tg://user?id={msg.from_user.id}')}!", reply_markup=markup.keyboards)

@bot.message_handler("Start")
async def start(msg: MessageObject, command: CommandObject):
    new_name: str = "Chat GPT-2"
    try:
        await bot.set_bot_name(new_name)
        await msg.answer(f"The bot's name has been successfully changed to: {new_name}")
    except (ValidationError, TelegramBadRequest) as e:
        await msg.answer(f"An error has occurred: {e}")

@bot.message_handler()
async def start(msg: MessageObject, command: CommandObject):
    """
    An example of processing messages that the bot does not know about:
    ```
    await msg.reply(f"I don't know such a command!")
    if msg.reply_to_message != None:
        await msg.reply_to_message.reply(f"I don't know such a command!")
    ```
    """
    await msg.reply(f"I don't know such a command!")
    if msg.reply_to_message != None:
        await msg.reply_to_message.reply(f"I don't know such a command!")

@bot.callback_handler()
async def start(callback: CallbackQuery):
    if callback.data == "start":
        """
        Example of using dice:
        ```
        dice = await callback.message.answer_dice("🎲")
        await callback.message.answer(f"The number dropped out: {dice.value}")
        await callback.message.answer(f"Emotion: {dice.emoji}")
        ```
        """
        await callback.message.answer(f"Details of the user who clicked the button:\nName: {callback.entities.from_user.full_name}\nID: {callback.entities.from_user.id}\nLanguage: {callback.entities.from_user.language_code}\nBot: {callback.entities.from_user.is_bot}")
        await callback.answer(text="You clicked the button!", show_alert=True)

async def main():
    await bot.delete_webhook(True)
    await bot.run()

asyncio.run(main())

Project details


Download files

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

Source Distribution

aiotele-0.1.3.tar.gz (11.6 kB view details)

Uploaded Source

File details

Details for the file aiotele-0.1.3.tar.gz.

File metadata

  • Download URL: aiotele-0.1.3.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for aiotele-0.1.3.tar.gz
Algorithm Hash digest
SHA256 db57a345413a1e8eaaede1b7348e7d6c5de008ed26e5dd483bca5c6a58d1845c
MD5 e5e3bc866a5b1595e69c6dcdea039a44
BLAKE2b-256 ae31497a5d4d54ab2ee4ce99a12ec3e079806db7eea63d7ce3623eb7055fa409

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page