rustigram-types 0.9.10

Telegram Bot API type definitions for rustigram
Documentation
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
use crate::chat::Chat;
use crate::file::PhotoSize;
use crate::gifts::{Gift, UniqueGift};
use crate::message::MessageEntity;
use crate::user::User;
use serde::{Deserialize, Serialize};

/// A portion of a price — label and amount in the smallest currency unit.
///
/// For Telegram Stars (`XTR`) the amount is in whole Stars.
/// For fiat currencies (e.g. `USD`) the amount is in cents.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LabeledPrice {
    /// Portion label shown to the user.
    pub label: String,
    /// Price in the smallest currency units.
    pub amount: i64,
}

/// An invoice for a payment inside a message.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Invoice {
    /// Product name.
    pub title: String,
    /// Product description.
    pub description: String,
    /// Unique bot deep-linking parameter for the invoice.
    pub start_parameter: String,
    /// Three-letter ISO 4217 currency code.
    pub currency: String,
    /// Total price in the smallest currency unit.
    pub total_amount: i64,
}

/// A shipping address provided by the user during checkout.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShippingAddress {
    /// Two-letter ISO 3166-1 alpha-2 country code.
    pub country_code: String,
    /// State, if applicable.
    pub state: String,
    /// City name.
    pub city: String,
    /// First line of the street address.
    pub street_line1: String,
    /// Second line of the street address.
    pub street_line2: String,
    /// Post code.
    pub post_code: String,
}

/// Information about an order collected from the user during checkout.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderInfo {
    /// User's name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// User's phone number.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone_number: Option<String>,
    /// User's email address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
    /// User's shipping address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shipping_address: Option<ShippingAddress>,
}

/// One shipping option offered to the user during payment.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShippingOption {
    /// Shipping option identifier.
    pub id: String,
    /// Shipping option title.
    pub title: String,
    /// List of price portions.
    pub prices: Vec<LabeledPrice>,
}

/// Confirmation that a payment was completed successfully.
///
/// Delivered inside a [`Message`](crate::message::Message) after the buyer
/// confirms checkout.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SuccessfulPayment {
    /// Three-letter ISO 4217 currency code.
    pub currency: String,
    /// Total price in the smallest currency unit.
    pub total_amount: i64,
    /// Bot-specified invoice payload.
    pub invoice_payload: String,
    /// Identifier of the shipping option chosen by the user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shipping_option_id: Option<String>,
    /// Order info provided by the user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_info: Option<OrderInfo>,
    /// Telegram payment charge identifier.
    pub telegram_payment_charge_id: String,
    /// Provider payment identifier.
    pub provider_payment_charge_id: String,
    /// Expiration date of the subscription, as a Unix timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subscription_expiration_date: Option<i64>,
    /// `true` if the payment is recurring.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_recurring: Option<bool>,
    /// `true` if this is the first payment for a subscription.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_first_recurring: Option<bool>,
}

/// Information about a refunded payment.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RefundedPayment {
    /// Three-letter ISO 4217 currency code, or `"XTR"` for Stars.
    pub currency: String,
    /// Total refunded price in the smallest currency unit.
    pub total_amount: i64,
    /// Bot-specified invoice payload.
    pub invoice_payload: String,
    /// Telegram payment charge identifier.
    pub telegram_payment_charge_id: String,
    /// Provider payment refund identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub provider_payment_charge_id: Option<String>,
}

/// An incoming shipping query from a user.
///
/// Delivered when the invoice has `is_flexible = true`. Respond with
/// [`answerShippingQuery`](https://core.telegram.org/bots/api#answershippingquery).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShippingQuery {
    /// Unique query identifier.
    pub id: String,
    /// The user who sent the query.
    pub from: User,
    /// Bot-specified invoice payload.
    pub invoice_payload: String,
    /// User-specified shipping address.
    pub shipping_address: ShippingAddress,
}

/// An incoming pre-checkout query.
///
/// Sent immediately before the payment confirmation screen. You must respond
/// with [`answerPreCheckoutQuery`](https://core.telegram.org/bots/api#answerprecheckoutquery)
/// within **10 seconds**.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PreCheckoutQuery {
    /// Unique query identifier.
    pub id: String,
    /// The user who sent the query.
    pub from: User,
    /// Three-letter ISO 4217 currency code.
    pub currency: String,
    /// Total price in the smallest currency unit.
    pub total_amount: i64,
    /// Bot-specified invoice payload.
    pub invoice_payload: String,
    /// Identifier of the shipping option chosen by the user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shipping_option_id: Option<String>,
    /// Order info provided by the user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_info: Option<OrderInfo>,
}

/// An amount of Telegram Stars.
///
/// `amount` is the integer Star count. `nanostar_amount` is a fractional
/// component in nanostar units (1 Star = 1,000,000,000 nanostars), present
/// only in certain transaction contexts.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StarAmount {
    /// Integer Star amount.
    pub amount: u64,
    /// Fractional amount in nanostar units (1 Star = 1,000,000,000 nanostars).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nanostar_amount: Option<u32>,
}

// ─── Revenue withdrawal ───────────────────────────────────────────────────────

/// The state of a revenue withdrawal operation.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RevenueWithdrawalState {
    /// The withdrawal is in progress.
    Pending,
    /// The withdrawal succeeded.
    Succeeded {
        /// Date the withdrawal was completed in Unix time.
        date: i64,
        /// HTTPS URL to view the transaction details.
        url: String,
    },
    /// The withdrawal failed and the transaction was refunded.
    Failed,
}

// Affiliate

/// Information about the affiliate that received a commission via this transaction.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AffiliateInfo {
    /// The bot or user that received the affiliate commission, if applicable.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub affiliate_user: Option<User>,
    /// The chat that received the affiliate commission, if applicable.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub affiliate_chat: Option<Chat>,
    /// Stars received per 1000 Stars received by the affiliate program sponsor.
    pub commission_per_mille: i64,
    /// Integer amount of Stars received from the transaction; can be negative for refunds.
    pub amount: i64,
    /// Fractional nanostar amount; from -999,999,999 to 999,999,999.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nanostar_amount: Option<i32>,
}

// Transaction partners

/// The source or recipient of a Star transaction.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TransactionPartner {
    /// A transaction with a user.
    User(Box<TransactionPartnerUser>),
    /// A transaction with a chat.
    Chat(Box<TransactionPartnerChat>),
    /// The affiliate program that issued the commission.
    AffiliateProgram(Box<TransactionPartnerAffiliateProgram>),
    /// A withdrawal transaction with Fragment.
    Fragment(Box<TransactionPartnerFragment>),
    /// A withdrawal transaction to the Telegram Ads platform.
    TelegramAds,
    /// A transaction for paid broadcasting.
    TelegramApi(Box<TransactionPartnerTelegramApi>),
    /// A transaction with an unknown source or recipient.
    Other,
}

/// A transaction with a user.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionPartnerUser {
    /// Type of the transaction.
    ///
    /// One of `"invoice_payment"`, `"paid_media_payment"`, `"gift_purchase"`,
    /// `"premium_purchase"`, or `"business_account_transfer"`.
    pub transaction_type: String,
    /// The user involved in the transaction.
    pub user: User,
    /// Affiliate commission information; available for invoice and paid media payments.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub affiliate: Option<AffiliateInfo>,
    /// Bot-specified invoice payload; available for `"invoice_payment"` only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invoice_payload: Option<String>,
    /// Duration of the paid subscription; available for `"invoice_payment"` only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subscription_period: Option<i64>,
    /// Paid media bought by the user; available for `"paid_media_payment"` only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paid_media: Option<Vec<serde_json::Value>>,
    /// Bot-specified paid media payload; available for `"paid_media_payment"` only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paid_media_payload: Option<String>,
    /// The gift sent to the user; available for `"gift_purchase"` only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gift: Option<Gift>,
    /// Months of Premium gifted; available for `"premium_purchase"` only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub premium_subscription_duration: Option<i64>,
}

/// A transaction with a chat.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionPartnerChat {
    /// The chat involved in the transaction.
    pub chat: Chat,
    /// The gift sent to the chat by the bot.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gift: Option<Gift>,
}

/// The affiliate program that issued the commission received via this transaction.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionPartnerAffiliateProgram {
    /// The bot that sponsored the affiliate program, if applicable.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sponsor_user: Option<User>,
    /// Stars received by the bot per 1000 Stars received by the program sponsor.
    pub commission_per_mille: i64,
}

/// A withdrawal transaction with Fragment.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionPartnerFragment {
    /// State of the transaction if it is outgoing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub withdrawal_state: Option<RevenueWithdrawalState>,
}

/// A transaction for paid broadcasting.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionPartnerTelegramApi {
    /// Number of successful requests that exceeded regular limits and were billed.
    pub request_count: i64,
}

// Star transactions

/// A list of Telegram Star transactions.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StarTransactions {
    /// The list of transactions.
    pub transactions: Vec<StarTransaction>,
}

/// A single Telegram Star transaction.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StarTransaction {
    /// Unique transaction identifier.
    pub id: String,
    /// Number of Telegram Stars transferred.
    pub amount: u64,
    /// Number of 1/1000000000 shares of Telegram Stars transferred.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nanostar_amount: Option<u32>,
    /// Date the transaction was created, as a Unix timestamp.
    pub date: i64,
    /// Source of an incoming transaction.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<TransactionPartner>,
    /// Receiver of an outgoing transaction.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub receiver: Option<TransactionPartner>,
}

// Gifts

/// Types of gifts that can be gifted to a user or chat.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AcceptedGiftTypes {
    /// `true` if unlimited regular gifts are accepted.
    pub unlimited_gifts: bool,
    /// `true` if limited regular gifts are accepted.
    pub limited_gifts: bool,
    /// `true` if unique gifts or gifts upgradable to unique for free are accepted.
    pub unique_gifts: bool,
    /// `true` if a Telegram Premium subscription is accepted.
    pub premium_subscription: bool,
    /// `true` if transfers of unique gifts from channels are accepted.
    pub gifts_from_channels: bool,
}

/// A regular gift owned by a user or chat.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OwnedGiftRegular {
    /// Information about the regular gift.
    pub gift: Gift,
    /// Unique identifier of the gift for the bot; for business account gifts only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub owned_gift_id: Option<String>,
    /// Sender of the gift if it is a known user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sender_user: Option<User>,
    /// Date the gift was sent, as a Unix timestamp.
    pub send_date: i64,
    /// Text of the message added to the gift.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,
    /// Special entities in the text.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub entities: Option<Vec<MessageEntity>>,
    /// `true` if only the gift receiver can see the sender and text.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_private: Option<bool>,
    /// `true` if the gift is displayed on the account's profile page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_saved: Option<bool>,
    /// `true` if the gift can be upgraded to a unique gift.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_be_upgraded: Option<bool>,
    /// `true` if the gift was refunded and is no longer available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub was_refunded: Option<bool>,
    /// Stars that can be claimed instead of the gift.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub convert_star_count: Option<i64>,
    /// Stars prepaid for the ability to upgrade the gift.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prepaid_upgrade_star_count: Option<i64>,
    /// `true` if the upgrade was purchased after the gift was sent.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_upgrade_separate: Option<bool>,
    /// Unique number reserved for this gift when upgraded.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unique_gift_number: Option<i64>,
}

/// A unique gift owned by a user or chat.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OwnedGiftUnique {
    /// Information about the unique gift.
    pub gift: UniqueGift,
    /// Unique identifier of the gift for the bot; for business account gifts only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub owned_gift_id: Option<String>,
    /// Sender of the gift if it is a known user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sender_user: Option<User>,
    /// Date the gift was sent, as a Unix timestamp.
    pub send_date: i64,
    /// `true` if the gift is displayed on the account's profile page.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_saved: Option<bool>,
    /// `true` if the gift can be transferred to another owner.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_be_transferred: Option<bool>,
    /// Stars required to transfer the gift.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transfer_star_count: Option<i64>,
    /// Unix timestamp when the gift can next be transferred.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_transfer_date: Option<i64>,
}

/// A gift received and owned by a user or chat.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OwnedGift {
    /// A regular owned gift.
    Regular(Box<OwnedGiftUnique>),
    /// A unique owned gift.
    Unique(Box<OwnedGiftUnique>),
}

/// A paginated list of gifts owned by a user or chat.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OwnedGifts {
    /// Total number of gifts owned by the user or chat.
    pub total_count: i64,
    /// The list of gifts.
    pub gifts: Vec<OwnedGift>,
    /// Offset for the next request; absent if there are no more results.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_offset: Option<String>,
}

// Paid media

/// A photo available as paid media.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaidMediaPhoto {
    /// Available sizes of the photo.
    pub photo: Vec<PhotoSize>,
}

/// A preview shown before a user purchases paid media.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaidMediaPreview {
    /// Media width as defined by the sender.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<i64>,
    /// Media height as defined by the sender.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,
    /// Duration of the media in seconds as defined by the sender.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
}

/// A live photo available as paid media.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaidMediaLivePhoto {
    /// The live photo.
    pub live_photo: crate::file::LivePhoto,
}