Skip to content

QuickestPossible🍕

MohammadReza edited this page May 9, 2022 · 5 revisions

Explanation

This is almost the quickest way you can setup an handler and listen for updates.

Code

import asyncio

from telegrambots.custom import (
    TelegramBot,
    Dispatcher,
    MessageContext,
    message_filters as mf,
)


bot = TelegramBot("BOT_TOKEN")
dp = Dispatcher(bot)


@dp.add.handlers.via_decorator.message(mf.regex("^/start") & mf.private)
async def starting(context: MessageContext):
    await context.reply_text("Started")


async def main():
    async with bot:
        me = await bot.get_me()
        print(me.pretty_str())

        print("Streaming updates ...")
        # For now you should fetch updates manually and feed them to dispatcher.
        async for update in bot.stream_updates(["message"]):
            await dp.feed_update(update)


if __name__ == "__main__":
    asyncio.run(main())

Here we have funny usage examples of Custom-TelegramBots. with the taste of some fast foods 🍿.

Clone this wiki locally