H
H
Hazrat Hajikerimov2015-07-16 15:02:41
PHP
Hazrat Hajikerimov, 2015-07-16 15:02:41

Telegram Bot: requires a user ID, where can I get it?

I'm a bit confused trying to use the Telegram Bot API. I'm trying to send a message to the user using the method:

$telegram = new telegramBot("121681**:AAHOjf*****ROYb03utzRf91ECBd8");
$telegram->sendMessage('@febox', 'Hello World!');

And it throws an error:
{"ok":false,"error_code":400,"description":"Error: Bad Request: wrong chat id"}

I found information that it is necessary to prescribe the user id in chat_id, but how to find it out? I didn't find anything in my telegram other than @febox.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kolotilin, 2015-07-16
@hazratgs

Write to the bot, he will receive json in which, in addition to the message, there will be a chat_id of the one who wrote.
Example:

{  
   "update_id":600028960,
   "message":{  
      "message_id":1,
      "from":{  
         "id":57350918,
         "first_name":"Евгений",
         "last_name":"Колотилин",
         "username":"iswitch"
      },
      "chat":{  
         "id":57350918,
         "first_name":"Евгений",
         "last_name":"Колотилин",
         "username":"iswitch"
      },
      "date":1437049435,
      "text":"test message"
   }
}

D
Dmitry Entelis, 2015-07-16
@DmitriyEntelis

I will add Evgeny Kolotilin - even if you substitute id from an external source - the user will not see messages from the bot until he writes to him for the first time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question