Разбираюсь в aiogram пытаюсь реализовать inline button, но почему ту они не работают, хендлер написан, но реакции все равно нет. Бот состоит из нескольких файлов.
main:
import asyncio
import config.bot_init
from aiogram import Bot, Dispatcher, types
from aiogram.types import BotCommand
from aiogram.contrib.fsm_storage.memory import MemoryStorage
async def set_commands(bot: Bot):
commands = [
BotCommand(command="/tshirt", description="Заказать блюда"),
BotCommand(command="/cancel", description="Отменить текущее действие")
]
await bot.set_my_commands(commands)
async def main():
bot = Bot(token=config.bot_init.BOT_TOKEN)
config.bot_init.dp = Dispatcher(bot, storage=MemoryStorage())
dp = config.bot_init.dp
print(config.bot_init.dp)
from handler.Tshirt import register_handlers_tshirt
from handler.common import register_handlers_common
register_handlers_common(dp)
register_handlers_tshirt(dp)
await set_commands(bot)
await dp.start_polling()
if __name__ == '__main__':
asyncio.run(main())
Tshirt:
from aiogram import Dispatcher, types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.dispatcher.filters import Text
import config.bot_init
available_tshirt_names = ["красная", "белая", "зеленая", "черная", "синяя"]
available_tshirt_sizes = ["XS", "S", "M", "L", "XL"]
class OrderTshirt(StatesGroup):
waiting_for_tshirt_name = State()
waiting_for_tshirt_size = State()
def register_handlers_tshirt(dp: Dispatcher):
dp.register_message_handler(tshirt_start, commands="tshirt", state="*")
dp.register_message_handler(tshirt_chosen, state=OrderTshirt.waiting_for_tshirt_name)
dp.register_message_handler(tshirt_size_chosen, state=OrderTshirt.waiting_for_tshirt_size)
@config.bot_init.dp.callback_query_handler(text_startswith="names_tshirt:")
async def tshirt_call(call: types.CallbackQuery):
name_tshirt = call.data.split(":")[1]
print(name_tshirt)
async def tshirt_start(message: types.Message):
# keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard = types.InlineKeyboardMarkup()
for name in available_tshirt_names:
keyboard.add(types.InlineKeyboardButton(
text=name,
callback_data=f"names_tshirt:{name}"))
await message.answer("Выберите футболку:", reply_markup=keyboard)
print('next')
await OrderTshirt.waiting_for_tshirt_name.set()
def register_handlers_tshirt(dp: Dispatcher):
dp.register_message_handler(tshirt_start, commands="tshirt", state="*")
dp.register_message_handler(tshirt_chosen, state=OrderTshirt.waiting_for_tshirt_name)
dp.register_message_handler(tshirt_size_chosen, state=OrderTshirt.waiting_for_tshirt_size)
Что у меня не так в программе реализовано?