I am programming telegram-bot on Python, using aiogram and I need to delete user from database, when he delete the chat of the bot. I know that bot must receive some update, after user delete the chat of the bot. But my bot doesn’t receive nothing messages about it. I tried sending a message to the user who deleted the bot hoping to get an error and then process it and remove the user from the database but the messages are still sent without error. Also I read about method sendChatAction, that can solve it, but I didn’t find good examples with it. Any idea? P.S. I don’t need advice how to delete user from database, I want to know how to get errors with info that user deleted the chat of the bot, that I can process(exception handling)
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
2
Answers
Maybe it will help someone. I use Flask-SQLAlchemy for working with database and aiogram for bot-development. Make sure that you import this "from aiogram.utils.exceptions import BotBlocked" for handling exception about blocking bot by user.
You can use the
Update.my_chat_member
updates. Those will tell you when a user blocks your bot. Note that your bot does not get notified if the user simply clears the chat history or deletes the chat with your bot without blocking the bot.