简体   繁体   中英

How to send a Telegram message to a username using bot api or telegram api?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM