How to use the aiogram.executor.start_polling function in aiogram

To help you get started, we’ve selected a few aiogram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiogram / aiogram / examples / echo_bot.py View on Github external
with open("data/cats.jpg", "rb") as photo:
        await bot.send_photo(
            message.chat.id,
            photo,
            caption="Cats is here 😺",
            reply_to_message_id=message.message_id,
        )


@dp.message_handler()
async def echo(message: types.Message):
    await bot.send_message(message.chat.id, message.text)


if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)
github aiogram / aiogram / examples / inline_bot.py View on Github external
loop = asyncio.get_event_loop()
bot = Bot(token=API_TOKEN, loop=loop)
dp = Dispatcher(bot)


@dp.inline_handler()
async def inline_echo(inline_query: types.InlineQuery):
    input_content = types.InputTextMessageContent(inline_query.query or "echo")
    item = types.InlineQueryResultArticle(
        id="1", title="echo", input_message_content=input_content
    )
    await bot.answer_inline_query(inline_query.id, results=[item], cache_time=1)


if __name__ == "__main__":
    executor.start_polling(dp, loop=loop, skip_updates=True)
github aiogram / aiogram / examples / admin_filter_example.py View on Github external
# checks multiple chats
@dp.message_handler(is_chat_admin=[-1001241113577, -320463906])
async def handle_multiple(msg: types.Message):
    await msg.answer("You are an admin of multiple chats!")


# checks current chat
@dp.message_handler(is_chat_admin=True)
async def handler3(msg: types.Message):
    await msg.answer("You are an admin of the current chat!")


if __name__ == '__main__':
    executor.start_polling(dp)
github aiogram / aiogram / examples / callback_data_factory_simple.py View on Github external
await bot.edit_message_text(
        f'You voted {callback_data_action}! Now you have {likes_count} vote[s].',
        query.from_user.id,
        query.message.message_id,
        reply_markup=get_keyboard(),
    )


@dp.errors_handler(exception=MessageNotModified)  # handle the cases when this exception raises
async def message_not_modified_handler(update, error):
    return True


if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)
github aiogram / aiogram / examples / i18n_example.py View on Github external
_ = i18n.gettext


@dp.message_handler(commands=["start"])
async def cmd_start(message: types.Message):
    # Simply use `_('message')` instead of `'message'` and never use f-strings for translatable texts.
    await message.reply(_("Hello, <b>{user}</b>!").format(user=message.from_user.full_name))


@dp.message_handler(commands=["lang"])
async def cmd_lang(message: types.Message, locale):
    await message.reply(_("Your current language: <i>{language}</i>").format(language=locale))


if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)
github aiogram / aiogram / examples / media_group.py View on Github external
# More local files and more cats!
    media.attach_photo(types.InputFile("data/cats.jpg"), "More cats!")

    # You can also use URL's
    # For example: get random puss:
    media.attach_photo("http://lorempixel.com/400/200/cats/", "Random cat.")

    # And you can also use file ID:
    # media.attach_photo('', 'cat-cat-cat.')

    # Done! Send media group
    await message.reply_media_group(media=media)


if __name__ == "__main__":
    executor.start_polling(dp, loop=loop, skip_updates=True)
github aiogram / aiogram / examples / id_filter_example.py View on Github external
await bot.send_message(msg.chat.id, "Hello, checking with chat_id=")
    raise SkipHandler  # just for demo


@dp.message_handler(user_id=user_id_required, chat_id=chat_id_required)
async def handler3(msg: types.Message):
    await msg.reply("Hello from user= & chat_id=", reply=False)


@dp.message_handler(user_id=[user_id_required, 42])  # TODO: You can add any number of ids here
async def handler4(msg: types.Message):
    await msg.reply("Checked user_id with list!", reply=False)


if __name__ == '__main__':
    executor.start_polling(dp)
github aiogram / aiogram / examples / check_user_language.py View on Github external
locale = message.from_user.locale

    await message.reply(
        md.text(
            md.bold("Info about your language:"),
            md.text(" 🔸", md.bold("Code:"), md.italic(locale.locale)),
            md.text(" 🔸", md.bold("Territory:"), md.italic(locale.territory or "Unknown")),
            md.text(" 🔸", md.bold("Language name:"), md.italic(locale.language_name)),
            md.text(" 🔸", md.bold("English language name:"), md.italic(locale.english_name)),
            sep="\n",
        )
    )


if __name__ == "__main__":
    executor.start_polling(dp, loop=loop, skip_updates=True)