tgbotxx  1.1.6.9
Telegram Bot C++ Library
WebhookInfo.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 namespace tgbotxx {
7  struct WebhookInfo {
8  WebhookInfo() = default;
9  explicit WebhookInfo(const nl::json& json) {
10  fromJson(json);
11  }
12 
14  std::string url;
15 
18 
20  std::int32_t pendingUpdateCount{};
21 
23  std::string ipAddress;
24 
26  std::time_t lastErrorDate{};
27 
29  std::string lastErrorMessage;
30 
33 
35  std::int32_t maxConnections{};
36 
38  std::vector<std::string> allowedUpdates;
39 
40 
43  nl::json toJson() const {
44  nl::json json = nl::json::object();
45  OBJECT_SERIALIZE_FIELD(json, "url", url);
46  OBJECT_SERIALIZE_FIELD(json, "has_custom_certificate", hasCustomCertificate);
47  OBJECT_SERIALIZE_FIELD(json, "pending_update_count", pendingUpdateCount);
48  OBJECT_SERIALIZE_FIELD(json, "ip_address", ipAddress);
49  OBJECT_SERIALIZE_FIELD(json, "last_error_date", lastErrorDate);
50  OBJECT_SERIALIZE_FIELD(json, "last_error_message", lastErrorMessage);
51  OBJECT_SERIALIZE_FIELD(json, "last_synchronization_error_date", lastSynchronizationErrorDate);
52  OBJECT_SERIALIZE_FIELD(json, "max_connections", maxConnections);
53  OBJECT_SERIALIZE_FIELD(json, "allowed_updates", allowedUpdates);
54  return json;
55  }
56 
58  void fromJson(const nl::json& json) {
59  OBJECT_DESERIALIZE_FIELD(json, "url", url, "", false);
60  OBJECT_DESERIALIZE_FIELD(json, "has_custom_certificate", hasCustomCertificate, false, false);
61  OBJECT_DESERIALIZE_FIELD(json, "pending_update_count", pendingUpdateCount, 0, false);
62  OBJECT_DESERIALIZE_FIELD(json, "ip_address", ipAddress, "", true);
63  OBJECT_DESERIALIZE_FIELD(json, "last_error_date", lastErrorDate, 0, true);
64  OBJECT_DESERIALIZE_FIELD(json, "last_error_message", lastErrorMessage, "", true);
65  OBJECT_DESERIALIZE_FIELD(json, "last_synchronization_error_date", lastSynchronizationErrorDate, 0, true);
66  OBJECT_DESERIALIZE_FIELD(json, "max_connections", maxConnections, 0, true);
67  OBJECT_DESERIALIZE_FIELD(json, "allowed_updates", allowedUpdates, std::vector<std::string>(), true);
68  }
69  };
70 }
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition: Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition: Object.hpp:44
Definition: Api.hpp:14
Describes the current status of a webhook. https://core.telegram.org/bots/api#webhookinfo.
Definition: WebhookInfo.hpp:7
std::string url
Webhook URL, may be empty if webhook is not set up.
Definition: WebhookInfo.hpp:14
WebhookInfo(const nl::json &json)
Definition: WebhookInfo.hpp:9
std::int32_t maxConnections
Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update deli...
Definition: WebhookInfo.hpp:35
std::int32_t pendingUpdateCount
Number of updates awaiting delivery.
Definition: WebhookInfo.hpp:20
std::time_t lastSynchronizationErrorDate
Optional. Unix time of the most recent error that happened when trying to synchronize available updat...
Definition: WebhookInfo.hpp:32
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: WebhookInfo.hpp:58
std::string ipAddress
Optional. Currently used webhook IP address.
Definition: WebhookInfo.hpp:23
bool hasCustomCertificate
True, if a custom certificate was provided for webhook certificate checks.
Definition: WebhookInfo.hpp:17
nl::json toJson() const
Serializes this object to JSON.
Definition: WebhookInfo.hpp:43
std::string lastErrorMessage
Optional. Error message in human-readable format for the most recent error that happened when trying ...
Definition: WebhookInfo.hpp:29
std::vector< std::string > allowedUpdates
Optional. A list of update types the bot is subscribed to. Defaults to all update types except chat_m...
Definition: WebhookInfo.hpp:38
std::time_t lastErrorDate
Optional. Unix time for the most recent error that happened when trying to deliver an update via webh...
Definition: WebhookInfo.hpp:26