| Server IP : 54.233.248.239 / Your IP : 172.28.1.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/irazasyed/telegram-bot-sdk/src/ |
Upload File : |
<?php
namespace Telegram\Bot;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\ResponseInterface;
use Telegram\Bot\Exceptions\TelegramResponseException;
use Telegram\Bot\Exceptions\TelegramSDKException;
/**
* Class TelegramResponse.
*
* Handles the response from Telegram API.
*/
class TelegramResponse
{
/**
* @var null|int The HTTP status code response from API.
*/
protected $httpStatusCode;
/**
* @var array The headers returned from API request.
*/
protected $headers;
/**
* @var string The raw body of the response from API request.
*/
protected $body;
/**
* @var array The decoded body of the API response.
*/
protected $decodedBody = [];
/**
* @var string API Endpoint used to make the request.
*/
protected $endPoint;
/**
* @var TelegramRequest The original request that returned this response.
*/
protected $request;
/**
* @var TelegramSDKException The exception thrown by this request.
*/
protected $thrownException;
/**
* Gets the relevant data from the Http client.
*
* @param TelegramRequest $request
* @param ResponseInterface|PromiseInterface $response
*/
public function __construct(TelegramRequest $request, $response)
{
if ($response instanceof ResponseInterface) {
$this->httpStatusCode = $response->getStatusCode();
$this->body = $response->getBody();
$this->headers = $response->getHeaders();
$this->decodeBody();
} elseif ($response instanceof PromiseInterface) {
$this->httpStatusCode = null;
} else {
throw new \InvalidArgumentException(
'Second constructor argument "response" must be instance of ResponseInterface or PromiseInterface'
);
}
$this->request = $request;
$this->endPoint = (string) $request->getEndpoint();
}
/**
* Return the original request that returned this response.
*
* @return TelegramRequest
*/
public function getRequest()
{
return $this->request;
}
/**
* Gets the HTTP status code.
* Returns NULL if the request was asynchronous since we are not waiting for the response.
*
* @return null|int
*/
public function getHttpStatusCode()
{
return $this->httpStatusCode;
}
/**
* Gets the Request Endpoint used to get the response.
*
* @return string
*/
public function getEndpoint()
{
return $this->endPoint;
}
/**
* Return the bot access token that was used for this request.
*
* @return string|null
*/
public function getAccessToken()
{
return $this->request->getAccessToken();
}
/**
* Return the HTTP headers for this response.
*
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Return the raw body response.
*
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* Return the decoded body response.
*
* @return array
*/
public function getDecodedBody()
{
return $this->decodedBody;
}
/**
* Checks if response is an error.
*
* @return bool
*/
public function isError()
{
return isset($this->decodedBody['ok']) && ($this->decodedBody['ok'] === false);
}
/**
* Throws the exception.
*
* @throws TelegramSDKException
*/
public function throwException()
{
throw $this->thrownException;
}
/**
* Instantiates an exception to be thrown later.
*/
public function makeException()
{
$this->thrownException = TelegramResponseException::create($this);
}
/**
* Returns the exception that was thrown for this request.
*
* @return TelegramSDKException
*/
public function getThrownException()
{
return $this->thrownException;
}
/**
* Converts raw API response to proper decoded response.
*/
public function decodeBody()
{
$this->decodedBody = json_decode($this->body, true);
if ($this->decodedBody === null) {
$this->decodedBody = [];
parse_str($this->body, $this->decodedBody);
}
if (!is_array($this->decodedBody)) {
$this->decodedBody = [];
}
if ($this->isError()) {
$this->makeException();
}
}
}