pyTelegramBotAPI icon indicating copy to clipboard operation
pyTelegramBotAPI copied to clipboard

How to prevent register_next_step_handler() by @bot.message_handler()?

Open Pestov opened this issue 9 years ago • 9 comments

Hi there! So I have a someone scenario (or steps continuity) in my bot. I need to prevent executing the next step if a command was called. I tried to clear message_subscribers_next_step and _pre_message_subscrubers_next_step. Moreover, I found clear_step_handler() method in branch master. But it doesn't work. Cleaning was processed in @bot.message_handler(), but executing next step continues anyway. How can I solve my problem?

Pestov avatar Oct 26 '17 18:10 Pestov

Does anybody help me? I will explain my problem in other words.

I have the /menu handler. This command allows show main menu and set the next step process_menu(). But what if I mistype command name and actually I need /support. So I type /support command and it gives me a choice to the next step depending on the response. Then I type /menu again. In menu handler I wrote the following code:

bot.message_subscribers_next_step[message.chat.id] = 
bot.pre_message_subscribers_next_step[message.chat.id] = [] 

Hence I get 2 callbacks from menu_handler() and process_support_type(). It's known that command handlers works first and I cleaned message_subscribers lists but it doesn't work. Why??? Also I tried to clean TeleBot.worker_pool with close() method in util.ThreadPool but I get error because of I don't understand how all of that work.

@eternnoir @pevdh @MasterGroosha I would be very grateful for any help for my issue.

Pestov avatar Oct 31 '17 15:10 Pestov

Install it from master and check.

0xVK avatar Nov 05 '17 05:11 0xVK

Hi, may i know how do i implement the exec command handlers? because once i get in a step_handler, there is no way that i could stop it.

voonfoo avatar Nov 18 '18 13:11 voonfoo

@voonfoo98 I suggest implementing a simple finite state machine yourself, it's much more efficient and controlable

MasterGroosha avatar Nov 18 '18 13:11 MasterGroosha

@MasterGroosha hey thanks! However, do you have any idea or working examples on how to implement FSM into the bot?

voonfoo avatar Nov 18 '18 13:11 voonfoo

@voonfoo98 I do, but only in Russian: https://groosha.gitbooks.io/telegram-bot-lessons/chapter11.html

There were some fan-made translations into English, though I'm not sure they are complete.

MasterGroosha avatar Nov 18 '18 13:11 MasterGroosha

how can I handle registering the next step handler in telebot using a class base in python??

nimeshtntra avatar Jul 05 '22 13:07 nimeshtntra

self.bot.register_next_step_handler(msg, self.process_message_custom)

Badiboy avatar Jul 05 '22 14:07 Badiboy

self.bot.register_next_step_handler(msg, self.process_message_custom)

Its not working

nimeshtntra avatar Jul 06 '22 04:07 nimeshtntra