I am using Java library for Telegram Bots Api: https://github.com/rubenlagus/TelegramBots
The thing I’m wondering about — is it possible to detect when bot is removed from user contact list?
I would like to handle this event to delete user settings (such as language) from database, so next time user adds my bot, he can specify settings from scratch and not stucking on selected previously.
SOLUTION FOUND
I described my solution below.
3
Answers
Ok, I think I have found a possible solution.
Hope, it will help to somebody.
There's no need to handle bot removing, instead of this you can handle bot's restart, because first message bot receives everytime after user clears history or re-adds removed bot — is /start command. So receiveing /start command is a good point to reset previous settings and let user to specify them again.
Also see the discussion above: Telegram Bot — reset user settings on chat removing / clearing
This is not possible because you won’t receive a notification when user removes the bot. The only error you get is when you try to send a message to a user that has blocked the bot.
While /start is working solution to recognize that user has restarted dialog with bot, now (September 2022) there is a way to get a disconnect message.
⚠️ I’m using another library and language, however shure that it’s an API feature, not depending on language (i’m using: C# nuget Telegram.Bot ver 18.0.0)
When user click to "Stop and block bot":
Telegram sends an update message (
Telegram.Bot.Types.Update
) withChatMemberUpdated
info (MyChatMember
field) – datails on person , see example: