So I’ve made a bot using @BotFather and I messaged it from my account. Then I found out the id of my account using @userinfobot and sent this request:
https://api.telegram.org/botTOKEN/sendMessage?chat_id=id&text=test
and it works fine ok:true
.
However if I try to use my @username instead of id:
https://api.telegram.org/botTOKENg/sendMessage?chat_id=@username&text=test
I get an error:
{
"ok": false,
"error_code": 400,
"description": "Bad Request: chat not found"
}
Looking at my past code, the @
method used to work for me before. Have things changed?
3
Answers
You have to use the id, you cannot use the username.
Giving the username as parameter does only work for public channels.
Have a look at the Telegram Bot API documentation:
you can’t send message with username you should to use of bot updates and get from_user or effective_user then access to id (chat_id)
after user doing some action in your bot now you can find and send every thing you want
you need to change: chat_id = @myname fro a number de id.
example: chat_ id = 43672587.
this number you get.
1.- enter telegram
2.- search @userinfobot and enter
3.-In automatic you get you id