from aiogram import Dispatcher, Bot, types, executor
import asyncio
from aiogram.types import *
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton
@dp.callback_query_handler(text="btn1")
async def btn1(call: CallbackQuery):
photo = open("img.png", "rb")
msg = await call.message.answer_photo(photo=photo, caption="Прикреплённый к фото текст кнопки 1")
keyboard = call.message.reply_markup
btn1 = InlineKeyboardButton(text="Инлайн кнопка1 (Свернуть)", callback_data=f"{msg.message_id}_btn1")
keyboard["inline_keyboard"][0][0] = btn1
await call.message.edit_reply_markup(keyboard)
@dp.callback_query_handler(text="btn2")
async def btn2(call: CallbackQuery):
photo = open("img.png", "rb")
msg = await call.message.answer_photo(photo=photo, caption="Прикреплённый к фото текст кнопки 2")
keyboard = call.message.reply_markup
btn2 = InlineKeyboardButton(text="Инлайн кнопка2 (Свернуть)", callback_data=f"{msg.message_id}_btn2")
keyboard["inline_keyboard"][1][0] = btn2
await call.message.edit_reply_markup(keyboard)
@dp.callback_query_handler(text="btn3")
async def btn3(call: CallbackQuery):
photo = open("img.png", "rb")
msg = await call.message.answer_photo(photo=photo, caption="Прикреплённый к фото текст кнопки 3")
keyboard = call.message.reply_markup
btn3 = InlineKeyboardButton(text="Инлайн кнопка2 (Свернуть)", callback_data=f"{msg.message_id}_btn3")
keyboard["inline_keyboard"][2][0] = btn3
await call.message.edit_reply_markup(keyboard)
@dp.callback_query_handler(regexp=r"[\d]+_btn1")
async def btn1_pthotodel(call: CallbackQuery):
await bot.delete_message(call.message.chat.id, int(call.data.split("_")[0]))
keyboard = call.message.reply_markup
btn1 = InlineKeyboardButton(text="Инлайн кнопка1", callback_data="btn1")
keyboard["inline_keyboard"][0][0] = btn1
await call.message.edit_reply_markup(keyboard)
@dp.callback_query_handler(regexp=r"[\d]+_btn2")
async def btn1_pthotodel(call: CallbackQuery):
await bot.delete_message(call.message.chat.id, int(call.data.split("_")[0]))
keyboard = call.message.reply_markup
btn2 = InlineKeyboardButton(text="Инлайн кнопка2", callback_data="btn2")
keyboard["inline_keyboard"][1][0] = btn2
await call.message.edit_reply_markup(keyboard)
@dp.callback_query_handler(regexp=r"[\d]+_btn3")
async def btn1_pthotodel(call: CallbackQuery):
await bot.delete_message(call.message.chat.id, int(call.data.split("_")[0]))
keyboard = call.message.reply_markup
btn3 = InlineKeyboardButton(text="Инлайн кнопка3", callback_data="btn3")
keyboard["inline_keyboard"][2][0] = btn3
await call.message.edit_reply_markup(keyboard)