I'm trying to create a telegram bot using python-telegram-bot. For this bot I'm using ConversationHandler
. The question is that when I change the code and re-run it, the bot waits until the user enters the command (e.g. /start
) to jump into the entry_points
. Is there any way to go to the entry_points
without entering the command? If not, is there a way to send all users a message to notify them to enter the command?

- 486
- 3
- 10
- 17
3 Answers
telegram.ext.ConversationHandler has an attribute persistent
. You can set persistent=True, name='example_name'
. And your updater should have persistence
field set.

- 101
- 3
Is there any way to go to the entry_points without entering the command? - You need some event for bot to recognize that it needs to invoke conversation handler. You can make it to react to just any message with a Handler, for example MessageHandler, but then you will need to check a message and decide whether bot in fact needs to continue reacting to it or simply ignore. The problem with it is that bot will do some work for each message user typed. If it is what you want then go for it, otherwise it's just a lot of overhead and that's why it's common to use commands so that bot only reacts to selected message.
Is there a way to send all users a message to notify them to enter the command? - Unfortunately bots can not initiate conversations with users, so you will need some other way to do it. /start command is global command in Telegram that indicates to start interaction with a user. From docs: Users will see a Start button when they first open a conversation with your bot. Maybe you can set welcome message in your group by using /setdescription or /setabouttext commands to provide more info if you want.

- 990
- 9
- 18
-
Thanks for the answer. For the first part: it was also the only solution came into my mind but I was wondering if there's a method in the API to do that. For the second part: By "users" I meant the the users that have an open conversation with the bot. So the bot has the chat_id. But I need the "bot" and "update" object to send a message while as far as I don't have them outside the handlers. – Amir Aug 06 '18 at 19:48
-
1the ConversationHandler stores the state of the conversation, not the api, so there is not method in the api to do that and there is also no method in the library. you don't need the update object to send a message, you can just send them with `bot.send_message` when you have a list of your users. – Thorbijoern Aug 07 '18 at 07:31
you could store the states of the ConversationHandler for each user in a db or so and when you restart the bot you could then insert the state again into the handler, but it's likely not as easy...
if i understand you right, you want to notify users after the update/restart... but that's also a bit tricky because the bot api limits how many messages you can send in a certain time (there is no method to just send it to all), so you would have to stretch these notifications over some time...

- 356
- 2
- 11