First define your button by callback data:
import telegram
HELP_BUTTON_CALLBACK_DATA = 'A unique text for help button callback data'
help_button = telegram.InlineKeyboardButton(
text='Help me', # text that show to user
callback_data=HELP_BUTTON_CALLBACK_DATA # text that send to bot when user tap button
)
Show help button to user in start command or another way:
def command_handler_start(bot, update):
chat_id = update.message.from_user.id
bot.send_message(
chat_id=chat_id,
text='Hello ...',
reply_markup=telegram.InlineKeyboardMarkup([help_button]),
)
Define help command handler:
def command_handler_help(bot, update):
chat_id = update.message.from_user.id
bot.send_message(
chat_id=chat_id,
text='Help text for user ...',
)
Handle callback data:
def callback_query_handler(bot, update):
cqd = update.callback_query.data
#message_id = update.callback_query.message.message_id
#update_id = update.update_id
if cqd == HELP_BUTTON_CALLBACK_DATA:
command_handler_help(bot, update)
# elif cqd == ... ### for other buttons
At last add handlers to your bot and start polling
update = telegram.ext.Updater('BOT_TOKEN')
bot = update.bot
dp = update.dispatcher
print('Your bot is --->', bot.username)
dp.add_handler(telegram.ext.CommandHandler('start', command_handler_start))
dp.add_handler(telegram.ext.CommandHandler('help', command_handler_help))
dp.add_handler(telegram.ext.CallbackQueryHandler(callback_query_handler))
update.start_polling()