2017-11-19 1 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으로 유지되고 두 번째 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을 사용하고 있으므로 한 번에 하나의 명령을 캡처하는 데만 사용됩니다.

ConversationHandler을 사용하여 원하는 작업을 수행 할 수 있습니다. 예제 스크립트 herehere을 읽어보십시오. 또한 핸들러 here에 대한 자세한 내용을 볼 수 있습니다.

관련 문제