Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from aiogram.contrib.fsm_storage.memory import MemoryStorage
- from aiogram import Bot, Dispatcher, types
- from aiogram.types import ChatType
- from aiogram.dispatcher.filters.state import State, StatesGroup
- from aiogram.dispatcher import FSMContext
- from aiogram.utils import executor
- bot = Bot(token=BOT_TOKEN)
- storage = MemoryStorage()
- dp = Dispatcher(bot, storage=storage)
- class States(StatesGroup):
- first = State()
- second = State()
- @dp.message_handler(lambda msg: ChatType.is_group_or_super_group(msg), commands=['start'], state='*')
- async def command_start_handler_group(message: types.Message):
- markup = types.InlineKeyboardMarkup(row_width=2)
- markup.insert(types.InlineKeyboardButton(text='Button 1', callback_data='button1'))
- markup.insert(types.InlineKeyboardButton(text='Button 2', callback_data='button2'))
- await bot.send_message(message.chat.id, text='Hi there!', reply_markup=markup)
- @dp.callback_query_handler(text='button1', state='*')
- async def callback_button1_handler(cb: types.CallbackQuery):
- await States.first.set()
- new_text = cb.message.text + '\n' + cb.from_user.full_name
- await cb.message.edit_text(text=new_text, reply_markup=cb.message.reply_markup)
- @dp.callback_query_handler(text='button2', state=States.first)
- async def callback_button2_handler(cb: types.CallbackQuery, state: FSMContext):
- print('Get to callback_button2_handler()')
- new_text = cb.message.text.replace('\n' + cb.from_user.full_name, '')
- await cb.message.edit_text(text=new_text, reply_markup=cb.message.reply_markup)
- await state.finish()
- if __name__ == '__main__':
- executor.start_polling(dp, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement