I’m developing a Telegram bot menu using python-telegram-bot. Although the bot initializes without errors, it remains silent. See revised sample code below.
from telegram import ReplyKeyboardMarkup, KeyboardButton
from telegram.ext import Updater, CommandHandler
from functools import wraps
BOT_TOKEN = '#####'
VALID_USERS = ['userA', 'userB']
ADMIN_USERS = ['adminA']
def admin_required(func):
@wraps(func)
def wrapper(update, context, *args, **kwargs):
if update.effective_user.username not in ADMIN_USERS:
update.message.reply_text('Admin access required.')
return
return func(update, context, *args, **kwargs)
return wrapper
def user_required(func):
@wraps(func)
def wrapper(update, context, *args, **kwargs):
if update.effective_user.username not in VALID_USERS:
update.message.reply_text('Access denied.')
return
return func(update, context, *args, **kwargs)
return wrapper
@user_required
def initiate(update, context):
update.message.reply_text(display_menu(), reply_markup=generate_menu())
def generate_menu():
buttons = [
[KeyboardButton('Start Option', callback_data='opt1')],
[KeyboardButton('Refresh', callback_data='opt2')],
[KeyboardButton('Activate', callback_data='opt3')]
]
return ReplyKeyboardMarkup(buttons)
def display_menu():
return 'Select an option from the menu:'
updater = Updater(BOT_TOKEN, use_context=True)
updater.dispatcher.add_handler(CommandHandler('initiate', initiate))
updater.start_polling()
updater.idle()