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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
use serde::{Deserialize, Serialize};
use crate::{
api::{Method, Payload, PayloadError},
types::{Integer, Message, StarAmount},
};
/// Approves a suggested post in a direct messages chat.
///
/// The bot must have the 'can_post_messages' administrator right in the corresponding channel chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct ApproveSuggestedPost {
chat_id: Integer,
message_id: Integer,
send_date: Option<Integer>,
}
impl ApproveSuggestedPost {
/// Creates a new `ApproveSuggestedPost`.
///
/// # Arguments
///
/// * `chat_id` - Unique identifier for the target direct messages chat
/// * `message_id` - Identifier of a suggested post message to approve
pub fn new(chat_id: Integer, message_id: Integer) -> Self {
Self {
chat_id,
message_id,
send_date: None,
}
}
/// Sets a new send date.
///
/// # Arguments
///
/// * `value` - Point in time (Unix timestamp) when the post is expected to be published.
///
/// Omit if the date has already been specified when the suggested post was created.
///
/// If specified, then the date must be not more than 2678400 seconds (30 days) in the future.
pub fn with_send_date(mut self, value: Integer) -> Self {
self.send_date = Some(value);
self
}
}
impl Method for ApproveSuggestedPost {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("approveSuggestedPost", self)
}
}
/// Declines a suggested post in a direct messages chat.
///
/// The bot must have the 'can_manage_direct_messages' administrator right in the corresponding channel chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct DeclineSuggestedPost {
chat_id: Integer,
message_id: Integer,
comment: Option<String>,
}
impl DeclineSuggestedPost {
/// Creates a new `DeclineSuggestedPost`.
///
/// # Arguments
///
/// * `chat_id` - Unique identifier for the target direct messages chat
/// * `message_id` - Identifier of a suggested post message to decline
pub fn new(chat_id: Integer, message_id: Integer) -> Self {
Self {
chat_id,
message_id,
comment: None,
}
}
/// Sets a new comment.
///
/// # Arguments
///
/// * `value` - Comment for the creator of the suggested post; 0-128 characters.
pub fn with_comment<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.comment = Some(value.into());
self
}
}
impl Method for DeclineSuggestedPost {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("declineSuggestedPost", self)
}
}
/// Describes a service message about the approval of a suggested post.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SuggestedPostApproved {
/// Date when the post will be published.
pub send_date: Integer,
/// Amount paid for the post.
pub price: Option<SuggestedPostPrice>,
/// Message containing the suggested post.
///
/// Note that the Message object in this field will not contain the reply_to_message field
/// even if it itself is a reply.
pub suggested_post_message: Option<Box<Message>>,
}
/// Describes a service message about the failed approval of a suggested post.
///
/// Currently, only caused by insufficient user funds at the time of approval.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SuggestedPostApprovalFailed {
/// Expected price of the post.
pub price: SuggestedPostPrice,
/// Message containing the suggested post whose approval has failed.
///
/// Note that the Message object in this field will not contain the reply_to_message field
/// even if it itself is a reply.
pub suggested_post_message: Option<Box<Message>>,
}
/// Describes a service message about the rejection of a suggested post.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct SuggestedPostDeclined {
/// Comment with which the post was declined.
pub comment: Option<String>,
/// Message containing the suggested post.
///
/// Note that the Message object in this field will not contain the reply_to_message field
/// even if it itself is a reply.
pub suggested_post_message: Option<Box<Message>>,
}
/// Contains information about a suggested post.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct SuggestedPostInfo {
/// State of the suggested post.
pub state: SuggestedPostState,
/// Proposed price of the post.
///
/// If the field is omitted, then the post is unpaid.
pub price: Option<SuggestedPostPrice>,
/// Proposed send date of the post.
///
/// If the field is omitted, then the post can be published at any time within 30 days
/// at the sole discretion of the user or administrator who approves it.
pub send_date: Option<Integer>,
}
/// Describes a service message about a successful payment for a suggested post.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SuggestedPostPaid {
/// Currency in which the payment was made.
///
/// Currently, one of “XTR” for Telegram Stars or “TON” for toncoins
pub currency: String,
/// The amount of the currency that was received by the channel in nanotoncoins; for payments in toncoins only.
pub amount: Option<Integer>,
/// The amount of Telegram Stars that was received by the channel; for payments in Telegram Stars only.
pub star_amount: Option<StarAmount>,
/// Message containing the suggested post.
///
/// Note that the Message object in this field will not contain the reply_to_message field even if it itself is a reply.
pub suggested_post_message: Option<Box<Message>>,
}
/// Contains parameters of a post that is being suggested by the bot.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct SuggestedPostParameters {
/// Proposed price for the post.
///
/// If the field is omitted, then the post is unpaid.
pub price: Option<SuggestedPostPrice>,
/// Proposed send date of the post.
///
/// If specified, then the date must be between 300 second and 2678400 seconds (30 days) in the future.
///
/// If the field is omitted, then the post can be published at any time within 30 days
/// at the sole discretion of the user who approves it.
pub send_date: Option<Integer>,
}
impl SuggestedPostParameters {
/// Sets a new price.
///
/// # Arguments
///
/// * `value` - Proposed price for the post.
pub fn with_price(mut self, value: SuggestedPostPrice) -> Self {
self.price = Some(value);
self
}
/// Sets a new send date.
///
/// # Arguments
///
/// * `value` - Proposed send date of the post.
pub fn with_send_date(mut self, value: Integer) -> Self {
self.send_date = Some(value);
self
}
}
/// Desribes price of a suggested post.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct SuggestedPostPrice {
/// The amount of the currency that will be paid for the post in the smallest units of the currency
/// i.e. Telegram Stars or nanotoncoins.
///
/// Currently, price in Telegram Stars must be between 5 and 100000,
/// and price in nanotoncoins must be between 10000000 and 10000000000000.
pub amount: Integer,
/// Currency in which the post will be paid.
///
/// Currently, must be one of “XTR” for Telegram Stars or “TON” for toncoins.
pub currency: String,
}
impl SuggestedPostPrice {
/// Creates a new `SuggestedPostPrice`.
///
/// # Arguments
///
/// * `amount` - The amount of the currency that will be paid for the post in the smallest units of the currency.
/// * `currency` - Currency in which the post will be paid.
pub fn new<T>(amount: Integer, currency: T) -> Self
where
T: Into<String>,
{
Self {
amount,
currency: currency.into(),
}
}
}
/// Describes a service message about a payment refund for a suggested post.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SuggestedPostRefunded {
/// Reason for the refund.
pub reason: SuggestedPostRefundReason,
/// Message containing the suggested post.
///
/// Note that the Message object in this field will not contain the reply_to_message field
/// even if it itself is a reply.
pub suggested_post_message: Option<Box<Message>>,
}
/// Reason for the refund.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SuggestedPostRefundReason {
/// The post was deleted within 24 hours of being posted
/// or removed from scheduled messages without being posted.
PostDeleted,
/// The payer refunded their payment.
PaymentRefunded,
}
/// State of a suggested post.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SuggestedPostState {
/// The post is approved.
Approved,
/// The post is declined.
Declined,
/// The post is waiting for approval.
Pending,
}