如何使用BOT API或Telegram API向用户名发送电报消息?
嗨,我正在尝试构建一个网站登录系统,用户可以使用电报登录。我想实现此工作流程:
- 用户选择要通过电报登录/注册。
- 用户输入其用户名(@examplejoe)。
- 通过我的电报机器人(@examplebot)发送了6位验证代码。
- 用户将接收到的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:
- User selects to login/sign up via telegram.
- User enters their username (@ExampleJoe).
- A 6-digit verification code is sent to them via my Telegram bot (@ExampleBot).
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
机器人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.