且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用我的电报机器人使用他们的用户名向某人发送消息

更新时间:2023-11-19 12:30:28

您不能使用 @username 形式的用户名向用户发送消息,您只能向频道发送消息您的机器人是其管理员的用户名.Telegram bot api 使用 chat_id 标识符来发送消息.如果想实现用户的chat_id,可以使用telegram-cli,但这一点也不容易,因为那个项目已经停产了,你应该自己调试.在您的情况下,您应该执行以下命令:

You can't send message to users using their username that is in form of @username, you can just send messages to channel usernames which your bot is administrator of it. Telegram bot api uses chat_id identifier for sending messages. If you want to achieve chat_id of users, you can use telegram-cli, but it's not easy at all because that project is discontinued and you should debug it yourself. in your case you should do following command:

> resolve_username vahid_mas

输出将是这样的:

{
  "user": {
    "username": "Vahid_Mas",
    "id": "$010000006459670b02c0c7fd66d44708",
    "last_name": "",
    "peer_type": "user",
    "print_name": "Vahid",
    "flags": 720897,
    "peer_id": 191322468,
    "first_name": "Vahid",
    "phone": "xxxxxxx"
  },
  "online": false,
  "event": "online-status",
  "state": -1,
  "when": "2017-01-22 17:43:16"
}