From 71dc0b5bb61801243b67779790f34761a6586e76 Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 14 Feb 2023 21:11:46 -0500 Subject: [PATCH] Added \TgBotLib\Objects\Telegram > WebhookInfo --- src/TgBotLib/Objects/Telegram/WebhookInfo.php | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 src/TgBotLib/Objects/Telegram/WebhookInfo.php diff --git a/src/TgBotLib/Objects/Telegram/WebhookInfo.php b/src/TgBotLib/Objects/Telegram/WebhookInfo.php new file mode 100644 index 0000000..aea00c2 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/WebhookInfo.php @@ -0,0 +1,190 @@ +url; + } + + /** + * True, if a custom certificate was provided for webhook certificate checks + * + * @return bool + */ + public function hasCustomCertificate(): bool + { + return $this->has_custom_certificate; + } + + /** + * Number of updates awaiting delivery + * + * @return int + */ + public function getPendingUpdateCount(): int + { + return $this->pending_update_count; + } + + /** + * Optional. Currently used webhook IP address + * + * @return string|null + */ + public function getIpAddress(): ?string + { + return $this->ip_address; + } + + /** + * Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook + * + * @return int|null + */ + public function getLastErrorDate(): ?int + { + 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|null + */ + public function getLastErrorMessage(): ?string + { + return $this->last_error_message; + } + + /** + * Optional. Unix time of the most recent error that happened when trying to synchronize available updates with + * Telegram datacenters + * + * @return int|null + */ + public function getLastSynchronizationErrorDate(): ?int + { + return $this->last_synchronization_error_date; + } + + /** + * Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery + * + * @return int|null + */ + public function getMaxConnections(): ?int + { + return $this->max_connections; + } + + /** + * Optional. A list of update types the bot is subscribed to. Defaults to all update types except chat_member + * + * @return string[]|null + */ + public function getAllowedUpdates(): ?array + { + return $this->allowed_updates; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'url' => $this->url, + 'has_custom_certificate' => $this->has_custom_certificate, + 'pending_update_count' => $this->pending_update_count, + 'ip_address' => $this->ip_address, + 'last_error_date' => $this->last_error_date, + 'last_error_message' => $this->last_error_message, + 'last_synchronization_error_date' => $this->last_synchronization_error_date, + 'max_connections' => $this->max_connections, + 'allowed_updates' => $this->allowed_updates, + ]; + } + + /** + * Constructs the object from an array + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->url = $data['url'] ?? null; + $object->has_custom_certificate = $data['has_custom_certificate'] ?? false; + $object->pending_update_count = $data['pending_update_count'] ?? false; + $object->ip_address = $data['ip_address'] ?? null; + $object->last_error_date = $data['last_error_date'] ?? null; + $object->last_error_message = $data['last_error_message'] ?? null; + $object->last_synchronization_error_date = $data['last_synchronization_error_date'] ?? null; + $object->max_connections = $data['max_connections'] ?? null; + $object->allowed_updates = $data['allowed_updates'] ?? null; + + return $object; + } + } \ No newline at end of file