如何使用BOT API或Telegram API向用户名发送电报消息?

发布于 2025-01-28 02:16:16 字数 327 浏览 4 评论 0原文

嗨,我正在尝试构建一个网站登录系统,用户可以使用电报登录。我想实现此工作流程:

  1. 用户选择要通过电报登录/注册。
  2. 用户输入其用户名(@examplejoe)。
  3. 通过我的电报机器人(@examplebot)发送了6位验证代码。
  4. 用户将接收到的6位代码输入到我的网站中,并被允许输入。

我对步骤2-3有问题,其中我的机器人只能以其用户名向他们发送直接消息(不在组聊天中)。我知道电报bot API中的sendmessage方法需要一个chat_id,并且user_id也是合适的。但是,我不知道如何仅使用用户的用户名来获取user_id。

Hi I am trying to build a website login system where users are able to log in using their telegram. I would like to achieve this workflow:

  1. User selects to login/sign up via telegram.
  2. User enters their username (@ExampleJoe).
  3. A 6-digit verification code is sent to them via my Telegram bot (@ExampleBot).
  4. The user enters the received 6-digit code into my website and is allowed to enter.

I have issues with steps 2-3 where my bot can send them a direct message (not in a group chat) with only their username. I am aware that sendMessage method in the Telegram bot API requires a chat_id and that a user_id is also suitable. However, I do not know how to get the user_id with just the user's username.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞旧 2025-02-04 02:16:16

机器人API不可能。您必须为此使用UserBot。但是请注意,TG提供了本机 login widget 您可以使用。

That's not possible with the Bot API. You'd have to use a userbot for that. Note however, that TG provides a native login widget that you can use instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文