To find out the chat ID in question, you need to access the method getUpdates
of the Telegram API.
Using Guzzle himself would look like this:
$cli = new \GuzzleHttp\Client([
'base_uri' => sprintf('https://api.telegram.org/bot%s/', static::TOKEN),
]);
$response = $cli->get('getUpdates');
print_r(json_decode((string) $response->getBody(), true));
The result will be to simulate this:
Array
(
[ok] => 1
[result] => Array
(
[0] => Array
(
[update_id] => 26020178
[message] => Array
(
[message_id] => 113
[from] => Array
(
[id] => 9999999999
[is_bot] =>
[first_name] => Nick
[last_name] => Qualquer
[username] => nickqualquer
[language_code] => pt-br
)
[chat] => Array
(
[id] => 9999999999
[first_name] => Nick
[last_name] => Qualquer
[username] => nickqualquer
[type] => private
)
[date] => 1536859308
[text] => UM TEXTO DE EXEMPLO
[entities] => Array
(
[0] => Array
(
[offset] => 0
[length] => 43
[type] => url
)
)
)
)
)
)
The place with the value 9999999999
is the chat ID and you should use as a parameter chat_id
in the call for sendMessage
.
In my case, I left the same saved in a configuration file, since the value is constant.
Observing: You may need to send a message to your user’s BOT so you can see the chat ID appearing in the list shown above.