клавиатура python-telegram-bot не отображается - PullRequest
0 голосов
/ 05 марта 2019

Я пытаюсь создать бота для управления каналами, а клавиатура (channel_markup в коде) для выбора каналов не появляется.Теперь эта клавиатура жестко запрограммирована, но позже я хочу представить для канала используемую клавиатуру.

    from telegram import ReplyKeyboardMarkup
    from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler, ConversationHandler)
    from Post import Post</p>

<code>   MENU, CHANNEL = range(2)

   menu_markup = ReplyKeyboardMarkup([['POST', 'HTML']], one_time_keyboard=True, resize_keyboard=True)

   def error(update, context):
       """Log Errors caused by Updates."""
       logger.warning('Update "%s" caused error "%s"', update, error)


   def start(bot, update, user_data):
       reply_text = 'Hi!'
       update.message.reply_text(reply_text, reply_markup=menu_markup)
       return MENU


   def new_post(bot, update, user_data):
       user_data['post'] = Post()
       channel_markup = ReplyKeyboardMarkup([['Test1', 'Test2']], 
                 one_time_keyboard=True, resize_keyboard=True)
       update.message.reply_text(text="Select channel", 
       replyMarkup=channel_markup)
       return CHANNEL


   def channel_choice(bot, update, user_data):
       channel = update.message.text
       user_data['post'].channel = channel
       update.message.reply_text('Hi', reply_markup=menu_markup)
       return MENU


   def test_bot(args):
       pass


   def main():
       updater = Updater("TOKEN")
       dp = updater.dispatcher
       conv_handler = ConversationHandler(

           entry_points=[CommandHandler('start', start, pass_user_data=True)],

           states={
               MENU: [RegexHandler('^POST$', new_post, pass_user_data=True)],

               CHANNEL: [RegexHandler('^Test1$', channel_choice, pass_user_data=True)]
           },

           fallbacks=[RegexHandler('^fallbacks$', test_bot)])

       dp.add_handler(conv_handler)

       # log all errors
       dp.add_error_handler(error)

       # Start the Bot
       updater.start_polling()

       # Run the bot until you press Ctrl-C or the process receives SIGINT,
       # SIGTERM or SIGABRT. This should be used most of the time, since
       # start_polling() is non-blocking and will stop the bot gracefully.
       updater.idle()
</code>

1 Ответ

0 голосов
/ 05 апреля 2019

Заменить replyMarkup на reply_markup.

enter image description here

...