如何获取特定用户的 Telegram chat_id? [英] How to obtain Telegram chat_id for a specific user?

查看:269
本文介绍了如何获取特定用户的 Telegram chat_id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Telegram bot API 中获取用户 chat_id?文档说:

How to obtain user chat_id in Telegram bot API? The documentation says:

整数 |消息接收者的唯一标识符 - 用户或群聊 ID

Integer | Unique identifier for the message recipient — User or GroupChat id

推荐答案

您通过 getUpdates 或您的 webhook 收到的消息更新将包含特定消息的聊天 ID.它将包含在 message.chat.id 键下.

The message updates you receive via getUpdates or your webhook will contain the chat ID for the specific message. It will be contained under the message.chat.id key.

这似乎是您能够检索聊天 ID 的唯一方法.因此,如果您想在机器人发起对话的地方编写一些内容,您可能必须将与用户相关的聊天 ID 存储在某种键->值存储中,例如 MemCache 或 Redis.

This seems like the only way you are able to retrieve the chat ID. So if you want to write something where the bot initiates the conversation you will probably have to store the chat ID in relation to the user in some sort of key->value store like MemCache or Redis.

我相信他们的文档在这里提出了类似的建议,https://core.telegram.org/bots#deep-链接示例.您可以使用深层链接发起对话,而无需用户先输入消息.

I believe their documentation suggests something similar here, https://core.telegram.org/bots#deep-linking-example. You can use deep-linking to initiate a conversation without requiring the user to type a message first.

这篇关于如何获取特定用户的 Telegram chat_id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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