Не обрабатывается CallbackQuery.
handlers.py
@dp.callback_query_handler(Text(startswith="delete_"))
async def delete_vin(query: types.CallbackQuery):
print("DATA:: " + query.data)
vin_num = query.data.split('_')[1]
session = Session()
vin = session.query(Vin).filter(Vin.vin_number == vin_num).first()
if vin:
for i in range(1, 6):
filename = f"photos/{vin.vin_number}-{i}.jpg"
if os.path.exists(filename):
os.remove(filename)
session.delete(vin)
session.commit()
else:
await query.message.answer(VIN_NOT_FOUND)
session.close()
await query.message.edit_text(VIN_DEL_SUCCESS)
await query.answer()
@dp.callback_query_handler(Text(startswith="block_"))
async def block_user(query: types.CallbackQuery):
print("DATA::" + query.data)
vin_num = query.data.split('_')[1]
session = Session()
vin = session.query(Vin).filter(Vin.vin_number == vin_num).first()
if vin:
user = session.query(User).filter(vin.creator_id == User.tg_id).first()
if user:
user.blocked = True
session.commit()
else:
await query.message.answer(USER_NOT_FOUND)
else:
await query.message.answer(VIN_NOT_FOUND)
session.close()
await query.message.edit_text(USER_DEL_SUCCES)
await query.answer()
keyboards.py
from aiogram import types
def get_vin_keyboard(vin):
buttons = [
types.InlineKeyboardButton(text="Удалить VIN", callback_data="delete_"+vin.vin_number),
types.InlineKeyboardButton(text="Заблокировать пользователя", callback_data="block_"+vin.vin_number),
]
keyboard = types.InlineKeyboardMarkup(row_width=1)
keyboard.add(*buttons)
return keyboard
error:
INFO:aiogram.contrib.middlewares.logging:Process update [ID:896669958]: [success] (in 178 ms)
INFO:aiogram.contrib.middlewares.logging:Received callback query [ID:1829996991623792879] from user [ID:426079377] for message [ID:195] in chat [private:426079377] with data: block_123 originally posted by user [ID:5467227336]
INFO:aiogram.contrib.middlewares.logging:Unhandled callback query [ID:1829996991623792879] from user [ID:426079377] for message [ID:195] in chat [private:426079377] with data: block_123 originally posted by user [ID:5467227336]
INFO:aiogram.contrib.middlewares.logging:Process update [ID:896669959]: [success] (in 1 ms)
если перезапустить бота и снова нажать на старую кнопку, она заработает.