I have the following code snippet:
public function createClient() {
$botToken = getenv('TELEGRAM_TOKEN');
$apiEndpoint = 'https://api.telegram.org/bot' . $botToken . '/';
$client = new Client(['base_uri' => $apiEndpoint]);
return $client;
}
public function fetchBotInfo() {
$client = $this->createClient();
$result = $client->get('/getMe');
dd($result);
}
However, instead of receiving the expected user object as outlined in the documentation, I am getting a ‘response’ object.
Response {#188 ▼
-reasonPhrase: "OK"
-statusCode: 200
-effectiveUrl: "https://core.telegram.org/bots"
-headers: array:9 [▼
"server" => array:1 [▶]
"date" => array:1 [▶]
"content-type" => array:1 [▶]
"content-length" => array:1 [▶]
"connection" => array:1 [▶]
"pragma" => array:1 [▶]
"cache-control" => array:1 [▶]
"x-frame-options" => array:1 [▶]
"strict-transport-security" => array:1 [▶]
]
-body: Stream {#189 ▼
-stream: :stream {@280 ▶}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
}
}
Is there a way to extract the user object from this response? I am working with PHP 5.4, Guzzle version 5.3, and Laravel 5.0.
Additionally, I attempted to use the getBody() method along with getBody()->getContents() but met with issues. The getBody() method only shows the stream details, while getContents() returns an unexpected HTML document. JSON decoding fails with error code 4 (JSON_ERROR_SYNTAX). Shouldn’t the response be in JSON format?