用户删除机器人的聊天时如何删除 Telegram 用户 ID [英] How to delete a Telegram user id when user delete the chat of the bot

查看:149
本文介绍了用户删除机器人的聊天时如何删除 Telegram 用户 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pyTelegramBotAPI 库构建电报机器人,我想知道是否有办法知道用户何时删除了与我的机器人的聊天,以便机器人不会向该特定 ID 发送更多消息.阅读电报API我什么也没找到,你能帮我吗?

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?

推荐答案

Bot API 5.1 引入了一种由 ChatMemberUpdated 类.

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.

旧答案:

遗憾的是,您无法知道用户何时删除了与您的机器人的聊天.

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.

尝试向阻止您的机器人的用户发送消息时,您会收到 HTTP 状态代码错误 403.

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

403: Forbidden: bot 被用户阻止

403: Forbidden: bot was blocked by the user

只有这样,您才能安全地从列表中删除用户的 chat_id.

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

这篇关于用户删除机器人的聊天时如何删除 Telegram 用户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆