Is it possible to check, via an API, whether somebody has deleted the Bot Chat in Telegram?
My test : Currently if a user deletes a chat, new messages will not stop sending to user.
Is it possible to check, via an API, whether somebody has deleted the Bot Chat in Telegram?
My test : Currently if a user deletes a chat, new messages will not stop sending to user.
4
Answers
Nope. Only by getting error while sending user something.
Even calling sendChatAction method does not return error if user blocked the chat:
You can get
getChat
method (https://core.telegram.org/bots/api#getchat). If user stop and block bot, this method return403
statusSomeone in other answers suggested to use getChat method.
Do not use it for two reasons:
So what can you do? You can use send methods and I would suggest you to use sendChatAction so you won’t bother users.
You can handle exceptions and check the code of the error returned (403 is the error for this case). Furthermore at the moment I write this answer if the user blocked the bot the returned string contains the word “blocked”, while if he deleted the account the string contains the word “deactivated”.
For example for my bot I developed a function that is automatically runned on intervals, it has a for loop and try to sendChatAction to every users. I check the code of the error (403 is for this) and I check the text of the error. If it contains “blocked” I just mark the user as blocked in the database because I want to keep preferences, otherwise if it contains “deactivated“ I delete the user from the database.
I did this to have stats about how many users my bot has and how many of them didn’t block the bot.
If you want to do something like this also remember to add a sleep in the for loop because you can use only 30 sendChatAction per second before of hitting limits.
This Resolved by new telegram update:
March 9, 2021
Bot API 5.1
Added two new update types
Added updates about member status changes in chats, represented by the class ChatMemberUpdated and the fields my_chat_member and chat_member in the Update class. The bot must be an administrator in the chat to receive chat_member updates about other chat members. By default, only my_chat_member updates about the bot itself are received.
Change log link : https://core.telegram.org/bots/api#march-9-2021