Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from aiogram import Bot, Dispatcher, executor, types
- from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardMarkup, KeyboardButton
- from settings import API_TOKEN
- logging.basicConfig(level=logging.DEBUG)
- bot = Bot(token=API_TOKEN)
- dp = Dispatcher(bot)
- @dp.message_handler(commands=['start', 'help'])
- async def send_welcome(message: types.Message):
- markup = ReplyKeyboardMarkup().add(
- KeyboardButton("ГЛАВНАЯ КНОПКА")
- )
- await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.", reply_markup=markup)
- await message.answer(f"Your id is {message.from_user.id}")
- logging.info(f"{message.from_user.username}: {message.text}")
- @dp.message_handler(regexp='(^cat[s]?$|puss)')
- async def cats(message: types.Message):
- await message.reply(text='Cats are here 😺')
- logging.info(f"{message.from_user.username}: {message.text}")
- @dp.message_handler()
- async def echo(message: types.Message):
- markup = InlineKeyboardMarkup().add(
- InlineKeyboardButton("Кнопка1", callback_data="but_1"),
- InlineKeyboardButton("Кнопка2", callback_data="but_2"),
- InlineKeyboardButton("JBT", callback_data="jbt"),
- )
- await message.answer(message.text, reply_markup=markup)
- logging.info(f"{message.from_user.username}: {message.text}")
- @dp.callback_query_handler(text_startswith="but_")
- async def but_pressed(call: types.CallbackQuery):
- logging.info(f"{call.from_user.username}: {call.data}")
- markup = ReplyKeyboardMarkup(resize_keyboard=True)
- markup.add(
- KeyboardButton("ГЛАВНАЯ КНОПКА"),
- )
- markup.row(
- KeyboardButton("Кнопка3", request_location=True),
- )
- markup.insert("Кнопка4")
- await call.message.answer(text=f"You pressed {call.data}", reply_markup=markup)
- await call.answer()
- if __name__ == '__main__':
- executor.start_polling(dp, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment