2017-11-19 10 views
0

ユーザーからの応答を受け取り、必要に応じて再度尋ねるボットを作成しようとしています。問題はその後です:ユーザーからの更新メッセージを受信できません

update.reply_text("Did you report all you working hour on freshdesk for this week?, ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)) 

私は新しいアップデートを取得できません。メッセージテキストは最初のprintには/startのままで、2番目のprintはまったく動作しません。

ユーザーからの応答を正しく取得するにはどうすればよいですか? ReplyMarkupに関連する問題はありますか?

def check_the_week(bot, update): 
    agent_username = update.message.from_user['username'] 
    parameters = {"username": agent_username} 
    url = "{}/weekly_hours/".format(API_URL) 
    report = get_request_forwarder(url=url, method="GET", parameters=parameters)["messages"] 
    reply_keyboard = [['YES', 'NO']] 
    bot.send_message(
     chat_id=update.message.chat_id, 
     text=report, 
     reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)) # sends the total nr of hours 
    print update.message.text 
    update.reply_text("Did you report all you working hour on freshdesk for this week?", 
        ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)) 
    print update.message.text 
    if update.message.text == "YES": 
     update.message.reply_text(text="Are you sure?",       reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)) 

    # Asks confirmation 
     if update.message.text == "YES": 
      update.message.reply_text(text="Thank you for reporting your working hours in time!") 

     elif update.message.text == "NO": 
      update.message.reply_text(text="Please, check you time reports and add missing") 

    elif update.message.text == "NO": 
     update.message.reply_text(text="Please, check you time reports and add missing") 


def main(): 
    # Create the EventHandler and pass it your bot's token. 
    updater = Updater(TELEGRAM_TOKEN) 
    j = updater.job_queue 
    # # Get the dispatcher to register handlers 
    dp = updater.dispatcher 
    # # Start the Bot 

    dp.add_handler(CommandHandler("start", check_the_week)) 
    # Send information to manager by command 

    updater.start_polling() 
    updater.idle() 
    print("bot started") 

if __name__ == '__main__': 
    main() 

答えて

1

CommandHandlerを使用しているため、一度に1つのコマンドをキャプチャするためにのみ使用されます。

あなたがしたいことは、ConversationHandlerを使って達成することができます。スクリプト例herehereを読んでください。また、ハンドラhereの詳細を読むことができます。

関連する問題