Telegram allows the commands to be updated using setMyCommands
. I can successfully update the commands in realtime based on the user input using a python API, pyTelegramBotAPI
.
However, the problem is the user has to exit the chat with the bot and then come back to the chat again to see the new commands (by typing /
).
Is there any way that I can have the bot update the list of commands in realtime with the user still in the chat?
2
Answers
So I tried it with telegram client (on linux and on android) and the commands do not change unless the user re-enters the chat. This I think is because the telegram-client only loads the commands when the user enters the chat.
But I also tried this with telegram web and found that the commands changed immidiately after I changed the command sets from BotFather. The webapp actually did load the command set without me leaving the chat, after sending a single message/command
So its definitely a problem with the telegram-client.
Actually it is possible to do this real time if you set the scope to chat with specific user. There is parameter scope in set_my_commands function. By default set_my_commands affects all the chats of your bot. However, you can provide telegram.BotCommandScopeChat as a value of scope param. See the code below, it updates the command menu immediately without need to switch chats.