Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- import config
- from telegram import InlineKeyboardButton, InlineKeyboardMarkup
- from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
- level=logging.INFO)
- def build_menu(buttons,
- n_cols):
- menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)]
- return menu
- def start(bot, update):
- keyboard = [[InlineKeyboardButton("Москва", callback_data='1'),
- InlineKeyboardButton("Option 2", callback_data='2')],
- [InlineKeyboardButton("Option 3", callback_data='3')]]
- reply_markup = InlineKeyboardMarkup(keyboard)
- update.message.reply_text('Добро пожаловать в наш магазин ! :\n➖ ➖ ➖ ➖ ➖ ➖ ➖ ➖ ➖ ➖ ➖ \n Выбери свой город ⬇️', reply_markup=reply_markup)
- def button(bot, update):
- query = update.callback_query
- if query.data == "1":
- bot.delete_message(chat_id=query.message.chat_id,
- message_id=query.message.message_id)
- button_list = [
- InlineKeyboardButton("col 1",callback_data='1'),
- InlineKeyboardButton("col 2",callback_data='2'),
- InlineKeyboardButton("row 2", callback_data='3')
- ]
- reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=2))
- bot.send_message(query.message.chat_id, "A two-column menu", reply_markup=reply_markup)
- elif query.data == "3":
- bot.delete_message(chat_id=query.message.chat_id,
- message_id=query.message.message_id)
- start(bot, update)
- def help(bot, update):
- update.message.send_me("Use /start to test this bot.")
- def error(bot, update, error):
- logging.warning('Update "%s" caused error "%s"' % (update, error))
- # Create the Updater and pass it your bot's token.
- updater = Updater(config.token)
- updater.dispatcher.add_handler(CommandHandler('start', start))
- updater.dispatcher.add_handler(CallbackQueryHandler(button))
- updater.dispatcher.add_handler(CommandHandler('help', help))
- updater.dispatcher.add_error_handler(error)
- # Start the Bot
- updater.start_polling()
- # Run the bot until the user presses Ctrl-C or the process receives SIGINT,
- # SIGTERM or SIGABRT
- updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement