1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use serde::{Deserialize, Serialize};
/// Describes the current status of a webhook.
/// # Documentation
/// <https://core.telegram.org/bots/api#webhookinfo>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct WebhookInfo {
/// Webhook URL, may be empty if webhook is not set up
pub url: Box<str>,
/// `true`, if a custom certificate was provided for webhook certificate checks
pub has_custom_certificate: bool,
/// Number of updates awaiting delivery
pub pending_update_count: i64,
/// Currently used webhook IP address
#[serde(skip_serializing_if = "Option::is_none")]
pub ip_address: Option<Box<str>>,
/// Unix time for the most recent error that happened when trying to deliver an update via webhook
#[serde(skip_serializing_if = "Option::is_none")]
pub last_error_date: Option<i64>,
/// Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
#[serde(skip_serializing_if = "Option::is_none")]
pub last_error_message: Option<Box<str>>,
/// Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters
#[serde(skip_serializing_if = "Option::is_none")]
pub last_synchronization_error_date: Option<i64>,
/// The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
#[serde(skip_serializing_if = "Option::is_none")]
pub max_connections: Option<i64>,
/// A list of update types the bot is subscribed to. Defaults to all update types except `chat_member`
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_updates: Option<Box<[Box<str>]>>,
}
impl WebhookInfo {
/// Creates a new `WebhookInfo`.
///
/// # Arguments
/// * `url` - Webhook URL, may be empty if webhook is not set up
/// * `has_custom_certificate` - `true`, if a custom certificate was provided for webhook certificate checks
/// * `pending_update_count` - Number of updates awaiting delivery
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<T0: Into<Box<str>>, T1: Into<bool>, T2: Into<i64>>(
url: T0,
has_custom_certificate: T1,
pending_update_count: T2,
) -> Self {
Self {
url: url.into(),
has_custom_certificate: has_custom_certificate.into(),
pending_update_count: pending_update_count.into(),
ip_address: None,
last_error_date: None,
last_error_message: None,
last_synchronization_error_date: None,
max_connections: None,
allowed_updates: None,
}
}
/// Webhook URL, may be empty if webhook is not set up
#[must_use]
pub fn url<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.url = val.into();
self
}
/// `true`, if a custom certificate was provided for webhook certificate checks
#[must_use]
pub fn has_custom_certificate<T: Into<bool>>(mut self, val: T) -> Self {
self.has_custom_certificate = val.into();
self
}
/// Number of updates awaiting delivery
#[must_use]
pub fn pending_update_count<T: Into<i64>>(mut self, val: T) -> Self {
self.pending_update_count = val.into();
self
}
/// Currently used webhook IP address
#[must_use]
pub fn ip_address<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.ip_address = Some(val.into());
self
}
/// Currently used webhook IP address
#[must_use]
pub fn ip_address_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.ip_address = val.map(Into::into);
self
}
/// Unix time for the most recent error that happened when trying to deliver an update via webhook
#[must_use]
pub fn last_error_date<T: Into<i64>>(mut self, val: T) -> Self {
self.last_error_date = Some(val.into());
self
}
/// Unix time for the most recent error that happened when trying to deliver an update via webhook
#[must_use]
pub fn last_error_date_option<T: Into<i64>>(mut self, val: Option<T>) -> Self {
self.last_error_date = val.map(Into::into);
self
}
/// Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
#[must_use]
pub fn last_error_message<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.last_error_message = Some(val.into());
self
}
/// Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
#[must_use]
pub fn last_error_message_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.last_error_message = val.map(Into::into);
self
}
/// Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters
#[must_use]
pub fn last_synchronization_error_date<T: Into<i64>>(mut self, val: T) -> Self {
self.last_synchronization_error_date = Some(val.into());
self
}
/// Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters
#[must_use]
pub fn last_synchronization_error_date_option<T: Into<i64>>(mut self, val: Option<T>) -> Self {
self.last_synchronization_error_date = val.map(Into::into);
self
}
/// The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
#[must_use]
pub fn max_connections<T: Into<i64>>(mut self, val: T) -> Self {
self.max_connections = Some(val.into());
self
}
/// The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
#[must_use]
pub fn max_connections_option<T: Into<i64>>(mut self, val: Option<T>) -> Self {
self.max_connections = val.map(Into::into);
self
}
/// A list of update types the bot is subscribed to. Defaults to all update types except `chat_member`
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn allowed_updates<T: Into<Box<[Box<str>]>>>(mut self, val: T) -> Self {
self.allowed_updates = Some(
self.allowed_updates
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into())
.collect(),
);
self
}
/// A list of update types the bot is subscribed to. Defaults to all update types except `chat_member`
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn allowed_update<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.allowed_updates = Some(
self.allowed_updates
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
self
}
/// A list of update types the bot is subscribed to. Defaults to all update types except `chat_member`
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn allowed_updates_option<T: Into<Box<[Box<str>]>>>(mut self, val: Option<T>) -> Self {
self.allowed_updates = val.map(Into::into);
self
}
}