skip to Main Content

I’m building a telegram bot using pyTelegramBotAPI libraries, I wanted to know if there is a way to know when a user deletes a chat with my bot, so the bot will not send more messages towards that specific id.
reading the telegram API I found nothing, can you help me?

2

Answers


  1. As I know, there is no way. When you chat with a friend, is there any way to know that he/she has deleted the chat page of you? NO.

    Telegram bot is completely similar to simple chat in this case up to
    this date. It doesn’t have considered in Telegram Bot API up to this
    date.

    Login or Signup to reply.
  2. EDIT: Bot API 5.1 introduces a new update type represented by ChatMemberUpdated class.

    When a user blocks your bot you will now receive an update looking like this:

    {
       "update_id":111627970,
       "my_chat_member":{
          "chat":{...},
          "from":{...},
          "date":1116140500,
          "old_chat_member":{...},
          "new_chat_member":{
             "user":{...},
             "status":"kicked",
             "until_date":0
          }
       }
    }
    

    Handle this update accordingly. It has all relevant information to let you exclude a user, who has blocked your bot.

    Old answer:

    Sadly you can’t know when a user has deleted a chat with your bot.

    You can keep sending messages though. Eventually the user will block your bot.

    Trying to send a message to a user who has blocked your bot will give you HTTP status code error 403.

    403: Forbidden: bot was blocked by the user

    Only then you can safely delete a user’s chat_id from your list.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search