Telegram Bot API:getChatMember 为有效用户抛出 USER_ID_INVALID [英] Telegram Bot API: getChatMember throws USER_ID_INVALID for valid user

查看:55
本文介绍了Telegram Bot API:getChatMember 为有效用户抛出 USER_ID_INVALID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一个特定的 User 是否存在于一个超级组中,以便跟踪那些离开的人.

I'm trying to find out if a specific User is present in a supergroup, in order to keep track of those who left.

为此,我为每个 User 调用 Bot API 方法 getChatMember 并检查它们的状态是 Left 还是 .但是,我注意到(最近?)我收到了许多 有效 用户的 USER_ID_INVALID 错误,这些用户要么在超级组中,要么在过去然后离开了.我还确认这些帐户在 Telegram 上仍然有效.

For that, I'm calling the Bot API method getChatMember for each User and checking if their status is either Left or Kicked. However, I noticed that (recently?) I'm getting USER_ID_INVALID errors for many valid users that are either in the supergroup or have been in the past and then left. I also confirmed that those accounts are still active on Telegram.

这是我发送的 HTTP 请求:

Here's the HTTP request I'm sending:

POST https://api.telegram.org/botXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX/getChatMember HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Content-Length: 46
Host: api.telegram.org

{"chat_id":-0000000000000,"user_id":000000000}

这是我得到的回复:

HTTP/1.1 400 Bad Request
Server: nginx/1.12.2
Date: Fri, 20 Apr 2018 04:17:32 GMT
Content-Type: application/json
Content-Length: 74
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection

{"ok":false,"error_code":400,"description":"Bad Request: USER_ID_INVALID"}

无论我怎么看,它对我来说都是一个完全有效的请求.而且我无法在引发此错误的用户之间找到共同模式.

Any way I look at it, it looks like a perfectly valid request to me. And I haven't been able to find a common pattern between the users that throw this error.

我在这里遗漏了什么?

正如@sean 指出的那样,让其中一个用户向机器人发送消息,机器人私下修复了该特定用户的错误.但我绝对确定该用户以前曾被见过,因为我就是这样得到他的用户 ID 的.什么可能导致机器人忘记"他,我将如何防止将来发生这种情况?

As @sean pointed out, having one of those users message the bot privately fixed the error for that particular user. But I'm absolutely sure that user was seen before because that's how I got his user ID. What could have caused the bot "forget" about him and how would I prevent this from happening in the future?

推荐答案

这个错误意味着你的机器人之前没有见过这个用户.

This error means your bot haven't seen this user before.

例如,我的用户 ID 是 109780439,您可以尝试 getChatMember@PublicTestGroup,它应该响应 400 错误.

For instance, my user ID is 109780439, you can try getChatMember with @PublicTestGroup, it should response with 400 error.

然后,转发任何我的消息(例如,this)到你的机器人,你会看到不同的结果:)

And then, forward ANY of my message (e.g., this) to your bot, you will see the different result :)

这篇关于Telegram Bot API:getChatMember 为有效用户抛出 USER_ID_INVALID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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