Regexp commands filter example
regexp_commands_filter_example.py
1from aiogram import Bot, types
2from aiogram.dispatcher import Dispatcher, filters
3from aiogram.utils import executor
4
5
6bot = Bot(token='BOT_TOKEN_HERE', parse_mode=types.ParseMode.HTML)
7dp = Dispatcher(bot)
8
9
10@dp.message_handler(filters.RegexpCommandsFilter(regexp_commands=['item_([0-9]*)']))
11async def send_welcome(message: types.Message, regexp_command):
12 await message.reply(f"You have requested an item with id <code>{regexp_command.group(1)}</code>")
13
14
15@dp.message_handler(commands='start')
16async def create_deeplink(message: types.Message):
17 bot_user = await bot.me
18 bot_username = bot_user.username
19 deeplink = f'https://t.me/{bot_username}?start=item_12345'
20 text = (
21 f'Either send a command /item_1234 or follow this link {deeplink} and then click start\n'
22 'It also can be hidden in a inline button\n\n'
23 'Or just send <code>/start item_123</code>'
24 )
25 await message.reply(text, disable_web_page_preview=True)
26
27
28if __name__ == '__main__':
29 executor.start_polling(dp, skip_updates=True)