Reputation: 31
I have a telegram bot that handles plain text store the text , do something with it , and return result. the output is correct, However, I want the bot to reply to command messages like "/start" "/help" differently. I achieved that as well successfully ,the thing is, once /start is done for example, it produce the desired output,and it goes ahead and process the text as if it was plain text (not desired in command case). Here is some of the code below for example ,
@bot.message_handler(commands=['start'])
def send_welcome(message):
msg = bot.reply_to(message, """\
Hi there, I am Humobot.
What do you want to verify?
""")
bot.register_next_step_handler(msg,bot.set_update_listener(handle_messages))
##.... similar functions for /help and functions to process the info in message....
def handle_messages(messages):
for message in messages:
# Do something with the message
bot.send_message(chat_id=message.chat.id,
text="Hold on Humo is running for you, he is still new and can barely walk")
process_check_info(message)
bot.set_update_listener(handle_messages)
bot.polling()
bot.enable_save_next_step_handlers(delay=2)
bot.load_next_step_handlers()
bot.polling()
I feel the problem is in line bot.register_next_step_handler(msg,bot.set_update_listener(handle_messages))
my callable function is set_update_listener(handle_messages), I am not sure how to tell the bot just wait for the next message and then if it was command process it as command ONLY and if it is plain text process it as text ONLY (the latter part, is actually working fine)
I hope the question is clear.
Upvotes: 0
Views: 1306
Reputation: 31
i have solved my problem after looking around , and the error was due to
bot.set_update_listener(handle_messages)
bot.polling()
bot.enable_save_next_step_handlers(delay=2)
bot.load_next_step_handlers()
had to be deleted.
Upvotes: 1