Using Guzzle with Telegram Bot API 'getMe' Method: How to Retrieve User Information

New sample code below. The Telegram API returns a Response object rather than direct user information. How can I properly extract the user data?

public function initializeClient() {
    $botToken = getenv('BOT_TOKEN');
    $endpoint = 'https://api.telegram.org/bot' . $botToken . '/';
    return new Client(['base_uri' => $endpoint]);
}

public function retrieveBotDetails() {
    $client = $this->initializeClient();
    $result = $client->get('/getMe');
    var_dump($result);
}

In my experience, the best approach is to decode the JSON response from the API rather than trying to work directly with the Guzzle response object. I solved it by using json_decode on the body of the response like this: $data = json_decode($response->getBody(), true);. This gives you an associative array from which you can extract the user data. I also recommend adding error checking to confirm that the API call succeeded and that the necessary fields are present in the decoded array.