tele 0.1.23

Ergonomic Telegram Bot API SDK for Rust, built on reqx
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
482
483
484
485
486
487
488
489
490
491
492
493
// Auto-generated by crates/tele-codegen. Do not edit manually.
use serde::Serialize;

use crate::{Error, Result};

use crate::types::validation::{
    control_free_string as validate_control_free_string, i64_range as validate_i64_range,
    non_negative_i64 as validate_non_negative_i64,
    optional_rich_text_formatting as validate_optional_rich_text_formatting,
    positive_i64 as validate_positive_i64, string_id as validate_string_id,
    text_length_range as validate_text_length_range,
};

use super::AdvancedRequest;

/// Auto-generated request for `getAvailableGifts`.
#[derive(Clone, Debug, Default, Serialize)]
pub struct AdvancedGetAvailableGiftsRequest {}

impl AdvancedGetAvailableGiftsRequest {
    pub fn new() -> Self {
        Self {}
    }
}

impl AdvancedRequest for AdvancedGetAvailableGiftsRequest {
    type Response = crate::types::gift::Gifts;
    const METHOD: &'static str = "getAvailableGifts";
}

/// Auto-generated request for `sendGift`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedSendGiftRequest {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub user_id: Option<crate::types::common::UserId>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub chat_id: Option<crate::types::common::ChatId>,
    pub gift_id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pay_for_upgrade: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text_parse_mode: Option<crate::types::common::ParseMode>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text_entities: Option<Vec<crate::types::message::MessageEntity>>,
}

impl AdvancedSendGiftRequest {
    pub fn new(gift_id: impl Into<String>) -> Self {
        Self {
            user_id: None,
            chat_id: None,
            gift_id: gift_id.into(),
            pay_for_upgrade: None,
            text: None,
            text_parse_mode: None,
            text_entities: None,
        }
    }
}

impl AdvancedRequest for AdvancedSendGiftRequest {
    type Response = bool;
    const METHOD: &'static str = "sendGift";

    fn validate(&self) -> Result<()> {
        if let Some(value) = self.user_id.as_ref() {
            value.validate()?;
        }
        if let Some(value) = self.chat_id.as_ref() {
            value.validate()?;
        }
        validate_string_id("gift_id", &self.gift_id)?;
        if let Some(value) = self.text.as_deref() {
            validate_text_length_range("text", value, 0, 128)?;
        }
        validate_optional_rich_text_formatting(
            "text",
            self.text.as_deref(),
            self.text_parse_mode,
            self.text_entities.as_deref(),
        )?;
        match (self.user_id.is_some(), self.chat_id.is_some()) {
            (true, false) | (false, true) => {}
            (false, false) => {
                return Err(Error::InvalidRequest {
                    reason: "sendGift requires either `user_id` or `chat_id`".to_owned(),
                });
            }
            (true, true) => {
                return Err(Error::InvalidRequest {
                    reason: "sendGift accepts either `user_id` or `chat_id`, not both".to_owned(),
                });
            }
        }
        Ok(())
    }
}

/// Auto-generated request for `giftPremiumSubscription`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedGiftPremiumSubscriptionRequest {
    pub user_id: crate::types::common::UserId,
    pub month_count: i64,
    pub star_count: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text_parse_mode: Option<crate::types::common::ParseMode>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text_entities: Option<Vec<crate::types::message::MessageEntity>>,
}

impl AdvancedGiftPremiumSubscriptionRequest {
    pub fn new(user_id: crate::types::common::UserId, month_count: i64, star_count: i64) -> Self {
        Self {
            user_id,
            month_count,
            star_count,
            text: None,
            text_parse_mode: None,
            text_entities: None,
        }
    }
}

impl AdvancedRequest for AdvancedGiftPremiumSubscriptionRequest {
    type Response = bool;
    const METHOD: &'static str = "giftPremiumSubscription";

    fn validate(&self) -> Result<()> {
        self.user_id.validate()?;
        validate_positive_i64("month_count", self.month_count)?;
        validate_positive_i64("star_count", self.star_count)?;
        if let Some(value) = self.text.as_deref() {
            validate_text_length_range("text", value, 0, 128)?;
        }
        validate_optional_rich_text_formatting(
            "text",
            self.text.as_deref(),
            self.text_parse_mode,
            self.text_entities.as_deref(),
        )?;
        match (self.month_count, self.star_count) {
            (3, 1000) | (6, 1500) | (12, 2500) => {}
            _ => {
                return Err(Error::InvalidRequest {
                    reason: "giftPremiumSubscription requires 1000 stars for 3 months, 1500 for 6 months, or 2500 for 12 months"
                        .to_owned(),
                });
            }
        }
        Ok(())
    }
}

/// Auto-generated request for `getUserGifts`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedGetUserGiftsRequest {
    pub user_id: crate::types::common::UserId,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_unlimited: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_limited_upgradable: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_limited_non_upgradable: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_from_blockchain: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_unique: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sort_by_price: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub offset: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

impl AdvancedGetUserGiftsRequest {
    pub fn new(user_id: crate::types::common::UserId) -> Self {
        Self {
            user_id,
            exclude_unlimited: None,
            exclude_limited_upgradable: None,
            exclude_limited_non_upgradable: None,
            exclude_from_blockchain: None,
            exclude_unique: None,
            sort_by_price: None,
            offset: None,
            limit: None,
        }
    }
}

impl AdvancedRequest for AdvancedGetUserGiftsRequest {
    type Response = crate::types::gift::OwnedGifts;
    const METHOD: &'static str = "getUserGifts";

    fn validate(&self) -> Result<()> {
        self.user_id.validate()?;
        if let Some(value) = self.offset.as_deref() {
            validate_control_free_string("offset", value)?;
        }
        if let Some(value) = self.limit {
            validate_i64_range("limit", value, 1, 100)?;
        }
        Ok(())
    }
}

/// Auto-generated request for `getChatGifts`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedGetChatGiftsRequest {
    pub chat_id: crate::types::common::ChatId,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_unsaved: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_saved: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_unlimited: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_limited_upgradable: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_limited_non_upgradable: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_from_blockchain: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_unique: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sort_by_price: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub offset: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

impl AdvancedGetChatGiftsRequest {
    pub fn new(chat_id: impl Into<crate::types::common::ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
            exclude_unsaved: None,
            exclude_saved: None,
            exclude_unlimited: None,
            exclude_limited_upgradable: None,
            exclude_limited_non_upgradable: None,
            exclude_from_blockchain: None,
            exclude_unique: None,
            sort_by_price: None,
            offset: None,
            limit: None,
        }
    }
}

impl AdvancedRequest for AdvancedGetChatGiftsRequest {
    type Response = crate::types::gift::OwnedGifts;
    const METHOD: &'static str = "getChatGifts";

    fn validate(&self) -> Result<()> {
        self.chat_id.validate()?;
        if let Some(value) = self.offset.as_deref() {
            validate_control_free_string("offset", value)?;
        }
        if let Some(value) = self.limit {
            validate_i64_range("limit", value, 1, 100)?;
        }
        Ok(())
    }
}

/// Auto-generated request for `convertGiftToStars`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedConvertGiftToStarsRequest {
    pub business_connection_id: String,
    pub owned_gift_id: String,
}

impl AdvancedConvertGiftToStarsRequest {
    pub fn new(
        business_connection_id: impl Into<String>,
        owned_gift_id: impl Into<String>,
    ) -> Self {
        Self {
            business_connection_id: business_connection_id.into(),
            owned_gift_id: owned_gift_id.into(),
        }
    }
}

impl AdvancedRequest for AdvancedConvertGiftToStarsRequest {
    type Response = bool;
    const METHOD: &'static str = "convertGiftToStars";

    fn validate(&self) -> Result<()> {
        validate_string_id("business_connection_id", &self.business_connection_id)?;
        validate_string_id("owned_gift_id", &self.owned_gift_id)?;
        Ok(())
    }
}

/// Auto-generated request for `upgradeGift`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedUpgradeGiftRequest {
    pub business_connection_id: String,
    pub owned_gift_id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub keep_original_details: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub star_count: Option<i64>,
}

impl AdvancedUpgradeGiftRequest {
    pub fn new(
        business_connection_id: impl Into<String>,
        owned_gift_id: impl Into<String>,
    ) -> Self {
        Self {
            business_connection_id: business_connection_id.into(),
            owned_gift_id: owned_gift_id.into(),
            keep_original_details: None,
            star_count: None,
        }
    }
}

impl AdvancedRequest for AdvancedUpgradeGiftRequest {
    type Response = bool;
    const METHOD: &'static str = "upgradeGift";

    fn validate(&self) -> Result<()> {
        validate_string_id("business_connection_id", &self.business_connection_id)?;
        validate_string_id("owned_gift_id", &self.owned_gift_id)?;
        if let Some(value) = self.star_count {
            validate_positive_i64("star_count", value)?;
        }
        Ok(())
    }
}

/// Auto-generated request for `transferGift`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedTransferGiftRequest {
    pub business_connection_id: String,
    pub owned_gift_id: String,
    pub new_owner_chat_id: crate::types::common::NumericChatId,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub star_count: Option<i64>,
}

impl AdvancedTransferGiftRequest {
    pub fn new(
        business_connection_id: impl Into<String>,
        owned_gift_id: impl Into<String>,
        new_owner_chat_id: impl Into<crate::types::common::NumericChatId>,
    ) -> Self {
        Self {
            business_connection_id: business_connection_id.into(),
            owned_gift_id: owned_gift_id.into(),
            new_owner_chat_id: new_owner_chat_id.into(),
            star_count: None,
        }
    }
}

impl AdvancedRequest for AdvancedTransferGiftRequest {
    type Response = bool;
    const METHOD: &'static str = "transferGift";

    fn validate(&self) -> Result<()> {
        validate_string_id("business_connection_id", &self.business_connection_id)?;
        validate_string_id("owned_gift_id", &self.owned_gift_id)?;
        self.new_owner_chat_id.validate()?;
        if let Some(value) = self.star_count {
            validate_positive_i64("star_count", value)?;
        }
        Ok(())
    }
}

/// Auto-generated request for `getMyStarBalance`.
#[derive(Clone, Debug, Default, Serialize)]
pub struct AdvancedGetMyStarBalanceRequest {}

impl AdvancedGetMyStarBalanceRequest {
    pub fn new() -> Self {
        Self {}
    }
}

impl AdvancedRequest for AdvancedGetMyStarBalanceRequest {
    type Response = crate::types::message::StarAmount;
    const METHOD: &'static str = "getMyStarBalance";
}

/// Auto-generated request for `getStarTransactions`.
#[derive(Clone, Debug, Default, Serialize)]
pub struct AdvancedGetStarTransactionsRequest {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub offset: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

impl AdvancedGetStarTransactionsRequest {
    pub fn new() -> Self {
        Self::default()
    }
}

impl AdvancedRequest for AdvancedGetStarTransactionsRequest {
    type Response = crate::types::gift::StarTransactions;
    const METHOD: &'static str = "getStarTransactions";

    fn validate(&self) -> Result<()> {
        if let Some(value) = self.offset {
            validate_non_negative_i64("offset", value)?;
        }
        if let Some(value) = self.limit {
            validate_i64_range("limit", value, 1, 100)?;
        }
        Ok(())
    }
}

/// Auto-generated request for `refundStarPayment`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedRefundStarPaymentRequest {
    pub user_id: crate::types::common::UserId,
    pub telegram_payment_charge_id: String,
}

impl AdvancedRefundStarPaymentRequest {
    pub fn new(
        user_id: crate::types::common::UserId,
        telegram_payment_charge_id: impl Into<String>,
    ) -> Self {
        Self {
            user_id,
            telegram_payment_charge_id: telegram_payment_charge_id.into(),
        }
    }
}

impl AdvancedRequest for AdvancedRefundStarPaymentRequest {
    type Response = bool;
    const METHOD: &'static str = "refundStarPayment";

    fn validate(&self) -> Result<()> {
        self.user_id.validate()?;
        validate_string_id(
            "telegram_payment_charge_id",
            &self.telegram_payment_charge_id,
        )?;
        Ok(())
    }
}

/// Auto-generated request for `editUserStarSubscription`.
#[derive(Clone, Debug, Serialize)]
pub struct AdvancedEditUserStarSubscriptionRequest {
    pub user_id: crate::types::common::UserId,
    pub telegram_payment_charge_id: String,
    pub is_canceled: bool,
}

impl AdvancedEditUserStarSubscriptionRequest {
    pub fn new(
        user_id: crate::types::common::UserId,
        telegram_payment_charge_id: impl Into<String>,
        is_canceled: bool,
    ) -> Self {
        Self {
            user_id,
            telegram_payment_charge_id: telegram_payment_charge_id.into(),
            is_canceled,
        }
    }
}

impl AdvancedRequest for AdvancedEditUserStarSubscriptionRequest {
    type Response = bool;
    const METHOD: &'static str = "editUserStarSubscription";

    fn validate(&self) -> Result<()> {
        self.user_id.validate()?;
        validate_string_id(
            "telegram_payment_charge_id",
            &self.telegram_payment_charge_id,
        )?;
        Ok(())
    }
}