diff --git a/src/Entities/ServerResponse.php b/src/Entities/ServerResponse.php index a6ee33f52..982fe8e4c 100644 --- a/src/Entities/ServerResponse.php +++ b/src/Entities/ServerResponse.php @@ -69,6 +69,9 @@ public function __construct(array $data, $bot_name) } elseif (isset($data['result']['user'])) { //Response from getChatMember $this->result = new ChatMember($data['result']); + } elseif (isset($data['result']['has_custom_certificate'])) { + //Response from getWebhookInfo + $this->result = new WebhookInfo($data['result']); } else { //Response from sendMessage $this->result = new Message($data['result'], $bot_name); diff --git a/src/Entities/WebhookInfo.php b/src/Entities/WebhookInfo.php new file mode 100644 index 000000000..a17a0a033 --- /dev/null +++ b/src/Entities/WebhookInfo.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +use Longman\TelegramBot\Exception\TelegramException; + +class WebhookInfo extends Entity +{ + protected $url; // String Webhook URL, may be empty if webhook is not set up + protected $has_custom_certificate; // Boolean True, if a custom certificate was provided for webhook certificate checks + protected $pending_update_count; // Integer Number of updates awaiting delivery + protected $last_error_date; // Integer Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook + protected $last_error_message; // String Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook + + public function __construct(array $data) + { + $this->url = isset($data['url']) ? $data['url'] : null; + $this->has_custom_certificate = isset($data['has_custom_certificate']) ? $data['has_custom_certificate'] : null; + $this->pending_update_count = isset($data['pending_update_count']) ? $data['pending_update_count'] : null; + $this->last_error_date = isset($data['last_error_date']) ? $data['last_error_date'] : null; + $this->last_error_message = isset($data['last_error_message']) ? $data['last_error_message'] : null; + } + + /** + * Webhook URL, may be empty if webhook is not set up. + * + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * True, if a custom certificate was provided for webhook certificate checks. + * + * @return bool + */ + public function getHasCustomCertificate() + { + return $this->has_custom_certificate; + } + + /** + * Number of updates awaiting delivery. + * + * @return int + */ + public function getPendingUpdateCount() + { + return $this->pending_update_count; + } + + /** + * Optional. + * Unix time for the most recent error that happened when trying to deliver an update via webhook. + * + * @return int + */ + public function getLastErrorDate() + { + return $this->last_error_date; + } + + /** + * Optional. + * Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook. + * + * @return string + */ + public function getLastErrorMessage() + { + return $this->last_error_message; + } +} diff --git a/src/Request.php b/src/Request.php index 2e3632771..e4e110371 100644 --- a/src/Request.php +++ b/src/Request.php @@ -81,6 +81,7 @@ class Request 'editMessageText', 'editMessageCaption', 'editMessageReplyMarkup', + 'getWebhookInfo', ]; /** @@ -842,4 +843,14 @@ public static function sendToActiveChats( return $results; } + + /** + * Use this method to get current webhook status. + * + * @return Entities\ServerResponse + */ + public static function getWebhookInfo() + { + return self::send('getWebhookInfo', []); + } }