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

查看:369
本文介绍了电报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还是Kicked.但是,我注意到(最近?)我收到了许多有效用户的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,您可以使用@PublicTestGroup尝试getChatMember,它应该会显示 400错误.

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

然后转发我的邮件的任何(例如,)到您的机器人,您将看到不同的结果:)

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

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

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