rustigram-api 0.10.2

Telegram Bot API method builders and HTTP client 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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
use crate::client::BotClient;
use crate::error::Result;
use reqwest::multipart::{Form, Part};
use rustigram_types::keyboard::MenuButton;
use rustigram_types::user::{
    BotCommand, BotCommandScope, BotDescription, BotName, BotShortDescription,
    ChatAdministratorRights, ChatId,
};
use serde::Serialize;
use std::future::{Future, IntoFuture};
use std::pin::Pin;

// ─── Helper macro ─────────────────────────────────────────────────────────────

/// Generates an `IntoFuture` impl that calls `BotClient::post_json`.
macro_rules! impl_into_future {
    ($builder:ident, $return_ty:ty, $method:literal) => {
        impl IntoFuture for $builder {
            type Output = Result<$return_ty>;
            type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;

            fn into_future(self) -> Self::IntoFuture {
                Box::pin(async move { self.client.post_json($method, &self.params).await })
            }
        }
    };
}

// ─── setMyCommands ────────────────────────────────────────────────────────────

#[derive(Serialize)]
struct SetMyCommandsParams {
    commands: Vec<BotCommand>,
    #[serde(skip_serializing_if = "Option::is_none")]
    scope: Option<BotCommandScope>,
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`setMyCommands`](https://core.telegram.org/bots/api#setmycommands) method.
pub struct SetMyCommands {
    client: BotClient,
    params: SetMyCommandsParams,
}

impl SetMyCommands {
    pub(crate) fn new(client: BotClient, commands: Vec<BotCommand>) -> Self {
        Self {
            client,
            params: SetMyCommandsParams {
                commands,
                scope: None,
                language_code: None,
            },
        }
    }
    /// Restricts these commands to a specific scope (chat type or individual chat).
    pub fn scope(mut self, s: BotCommandScope) -> Self {
        self.params.scope = Some(s);
        self
    }
    /// Sets the language code for localised command lists (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(SetMyCommands, bool, "setMyCommands");

// ─── deleteMyCommands ─────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct DeleteMyCommandsParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    scope: Option<BotCommandScope>,
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`deleteMyCommands`](https://core.telegram.org/bots/api#deletemycommands) method.
///
/// Deletes the bot's command list for the given scope and language.
/// After deletion, higher-level commands will be shown to affected users.
pub struct DeleteMyCommands {
    client: BotClient,
    params: DeleteMyCommandsParams,
}

impl DeleteMyCommands {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Restricts deletion to a specific scope.
    pub fn scope(mut self, s: BotCommandScope) -> Self {
        self.params.scope = Some(s);
        self
    }
    /// Restricts deletion to a specific language code (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(DeleteMyCommands, bool, "deleteMyCommands");

// ─── getMyCommands ────────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct GetMyCommandsParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    scope: Option<BotCommandScope>,
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`getMyCommands`](https://core.telegram.org/bots/api#getmycommands) method.
pub struct GetMyCommands {
    client: BotClient,
    params: GetMyCommandsParams,
}

impl GetMyCommands {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Restricts the list of retrieved commands to a specific scope (chat type or individual chat).
    pub fn scope(mut self, s: BotCommandScope) -> Self {
        self.params.scope = Some(s);
        self
    }
    /// The language code for localised command lists (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(GetMyCommands, Vec<BotCommand>, "getMyCommands");

// ─── setMyName ────────────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct SetMyNameParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`setMyName`](https://core.telegram.org/bots/api#setmyname) method.
pub struct SetMyName {
    client: BotClient,
    params: SetMyNameParams,
}

impl SetMyName {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Sets the new bot name (up to 64 characters).
    pub fn name(mut self, n: impl Into<String>) -> Self {
        self.params.name = Some(n.into());
        self
    }
    /// Sets the language code for localised bot names (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(SetMyName, bool, "setMyName");

// ─── getMyName ────────────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct GetMyNameParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`getMyName`](https://core.telegram.org/bots/api#getmyname) method.
pub struct GetMyName {
    client: BotClient,
    params: GetMyNameParams,
}

impl GetMyName {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// The language code for the localised bot name to retrieve (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(GetMyName, BotName, "getMyName");

// ─── setMyDescription ─────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct SetMyDescriptionParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`setMyDescription`](https://core.telegram.org/bots/api#setmydescription) method.
pub struct SetMyDescription {
    client: BotClient,
    params: SetMyDescriptionParams,
}

impl SetMyDescription {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Sets the new bot description shown on the profile page (up to 512 characters).
    pub fn description(mut self, d: impl Into<String>) -> Self {
        self.params.description = Some(d.into());
        self
    }
    /// Sets the language code for localised bot descriptions (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(SetMyDescription, bool, "setMyDescription");

// ─── getMyDescription ─────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct GetMyDescriptionParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`getMyDescription`](https://core.telegram.org/bots/api#getmydescription) method.
pub struct GetMyDescription {
    client: BotClient,
    params: GetMyDescriptionParams,
}

impl GetMyDescription {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// The language code for the localised bot description to retrieve (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(GetMyDescription, BotDescription, "getMyDescription");

// ─── setMyShortDescription ────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct SetMyShortDescriptionParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    short_description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`setMyShortDescription`](https://core.telegram.org/bots/api#setmyshortdescription) method.
///
/// The short description is shown on the bot's profile page and sent with
/// sharing links. Up to 120 characters; omit to remove the localised value.
pub struct SetMyShortDescription {
    client: BotClient,
    params: SetMyShortDescriptionParams,
}

impl SetMyShortDescription {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Sets the short description (0–120 characters). Omit to remove the dedicated value.
    pub fn short_description(mut self, d: impl Into<String>) -> Self {
        self.params.short_description = Some(d.into());
        self
    }
    /// Sets the language code for the localised short description (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(SetMyShortDescription, bool, "setMyShortDescription");

// ─── getMyShortDescription ────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct GetMyShortDescriptionParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    language_code: Option<String>,
}

/// Builder for the [`getMyShortDescription`](https://core.telegram.org/bots/api#getmyshortdescription) method.
pub struct GetMyShortDescription {
    client: BotClient,
    params: GetMyShortDescriptionParams,
}

impl GetMyShortDescription {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// The language code for the localised short description to retrieve (IETF tag, e.g. `"en"`).
    pub fn language_code(mut self, lc: impl Into<String>) -> Self {
        self.params.language_code = Some(lc.into());
        self
    }
}

impl_into_future!(
    GetMyShortDescription,
    BotShortDescription,
    "getMyShortDescription"
);

// ─── setMyDefaultAdministratorRights ─────────────────────────────────────────

#[derive(Serialize, Default)]
struct SetMyDefaultAdministratorRightsParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    rights: Option<ChatAdministratorRights>,
    #[serde(skip_serializing_if = "Option::is_none")]
    for_channels: Option<bool>,
}

/// Builder for the [`setMyDefaultAdministratorRights`](https://core.telegram.org/bots/api#setmydefaultadministratorrights) method.
///
/// Sets the default administrator rights suggested to users when the bot is
/// added as an administrator. Pass `None` rights to clear the defaults.
pub struct SetMyDefaultAdministratorRights {
    client: BotClient,
    params: SetMyDefaultAdministratorRightsParams,
}

impl SetMyDefaultAdministratorRights {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Sets the new default administrator rights. Omit to clear the current defaults.
    pub fn rights(mut self, r: ChatAdministratorRights) -> Self {
        self.params.rights = Some(r);
        self
    }
    /// Pass `true` to change defaults for channels; otherwise changes group/supergroup defaults.
    pub fn for_channels(mut self, v: bool) -> Self {
        self.params.for_channels = Some(v);
        self
    }
}

impl_into_future!(
    SetMyDefaultAdministratorRights,
    bool,
    "setMyDefaultAdministratorRights"
);

// ─── getMyDefaultAdministratorRights ─────────────────────────────────────────

#[derive(Serialize, Default)]
struct GetMyDefaultAdministratorRightsParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    for_channels: Option<bool>,
}

/// Builder for the [`getMyDefaultAdministratorRights`](https://core.telegram.org/bots/api#getmydefaultadministratorrights) method.
pub struct GetMyDefaultAdministratorRights {
    client: BotClient,
    params: GetMyDefaultAdministratorRightsParams,
}

impl GetMyDefaultAdministratorRights {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Pass `true` to get default administrator rights for channels;
    /// otherwise returns defaults for groups and supergroups.
    pub fn for_channels(mut self, v: bool) -> Self {
        self.params.for_channels = Some(v);
        self
    }
}

impl_into_future!(
    GetMyDefaultAdministratorRights,
    ChatAdministratorRights,
    "getMyDefaultAdministratorRights"
);

// ─── getChatMenuButton ────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct GetChatMenuButtonParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    chat_id: Option<ChatId>,
}

/// Builder for the [`getChatMenuButton`](https://core.telegram.org/bots/api#getchatmenubutton) method.
pub struct GetChatMenuButton {
    client: BotClient,
    params: GetChatMenuButtonParams,
}

impl GetChatMenuButton {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Restricts the menu button query to a specific private chat.
    pub fn chat_id(mut self, id: impl Into<ChatId>) -> Self {
        self.params.chat_id = Some(id.into());
        self
    }
}

impl_into_future!(GetChatMenuButton, MenuButton, "getChatMenuButton");

// ─── setChatMenuButton ────────────────────────────────────────────────────────

#[derive(Serialize, Default)]
struct SetChatMenuButtonParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    chat_id: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    menu_button: Option<MenuButton>,
}

/// Builder for the [`setChatMenuButton`](https://core.telegram.org/bots/api#setchatmenubutton) method.
///
/// Changes the bot's menu button in a private chat, or the default menu button.
/// Omit `chat_id` to change the default; omit `menu_button` to reset to `MenuButtonDefault`.
pub struct SetChatMenuButton {
    client: BotClient,
    params: SetChatMenuButtonParams,
}

impl SetChatMenuButton {
    pub(crate) fn new(client: BotClient) -> Self {
        Self {
            client,
            params: Default::default(),
        }
    }
    /// Targets a specific private chat. Omit to change the default menu button.
    pub fn chat_id(mut self, id: i64) -> Self {
        self.params.chat_id = Some(id);
        self
    }
    /// Sets the new menu button. Omit to reset to `MenuButtonDefault`.
    pub fn menu_button(mut self, btn: MenuButton) -> Self {
        self.params.menu_button = Some(btn);
        self
    }
}

impl_into_future!(SetChatMenuButton, bool, "setChatMenuButton");

// ─── logOut ───────────────────────────────────────────────────────────────────

/// Builder for the [`logOut`](https://core.telegram.org/bots/api#logout) method.
///
/// Logs out from the cloud Bot API server. Must be called before running the
/// bot locally. After a successful call the bot cannot log back in to the cloud
/// server for 10 minutes.
pub struct LogOut {
    client: BotClient,
}

impl LogOut {
    pub(crate) fn new(client: BotClient) -> Self {
        Self { client }
    }
}

impl IntoFuture for LogOut {
    type Output = Result<bool>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;

    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move {
            self.client
                .post_json("logOut", &serde_json::json!({}))
                .await
        })
    }
}

// ─── close ────────────────────────────────────────────────────────────────────

/// Builder for the [`close`](https://core.telegram.org/bots/api#close) method.
///
/// Closes the bot instance before moving it to another local server. Delete
/// the webhook before calling this to prevent the bot from restarting.
/// Returns error 429 in the first 10 minutes after launch.
pub struct Close {
    client: BotClient,
}

impl Close {
    pub(crate) fn new(client: BotClient) -> Self {
        Self { client }
    }
}

impl IntoFuture for Close {
    type Output = Result<bool>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;

    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move { self.client.post_json("close", &serde_json::json!({})).await })
    }
}

// ─── setMyProfilePhoto ────────────────────────────────────────────────────────

/// Builder for the [`setMyProfilePhoto`](https://core.telegram.org/bots/api#setmyprofilephoto) method (Bot API 9.4).
///
/// Changes the profile photo of the bot. The photo must be uploaded via
/// multipart/form-data as an `InputProfilePhoto`.
pub struct SetMyProfilePhoto {
    client: BotClient,
    /// The serialised `InputProfilePhoto` JSON sent as the `photo` field.
    photo_json: String,
}

impl SetMyProfilePhoto {
    /// Creates a new builder from a pre-serialised `InputProfilePhoto` value.
    ///
    /// Pass the result of `serde_json::to_string(&input_profile_photo)`.
    pub(crate) fn new(client: BotClient, photo_json: String) -> Self {
        Self { client, photo_json }
    }
}

impl IntoFuture for SetMyProfilePhoto {
    type Output = Result<bool>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;

    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move {
            let part = Part::text(self.photo_json)
                .mime_str("application/json")
                .map_err(|e| crate::error::Error::Decode(e.to_string()))?;
            let form = Form::new().part("photo", part);
            self.client.post_multipart("setMyProfilePhoto", form).await
        })
    }
}

// ─── removeMyProfilePhoto ─────────────────────────────────────────────────────

/// Builder for the [`removeMyProfilePhoto`](https://core.telegram.org/bots/api#removemyprofilephoto) method (Bot API 9.4).
///
/// Removes the current profile photo of the bot. Requires no parameters.
pub struct RemoveMyProfilePhoto {
    client: BotClient,
}

impl RemoveMyProfilePhoto {
    pub(crate) fn new(client: BotClient) -> Self {
        Self { client }
    }
}

impl IntoFuture for RemoveMyProfilePhoto {
    type Output = Result<bool>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;

    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move {
            self.client
                .post_json("removeMyProfilePhoto", &serde_json::json!({}))
                .await
        })
    }
}

// ─── replaceManagedBotToken ───────────────────────────────────────────────────

#[derive(Serialize)]
struct ReplaceManagedBotTokenParams {
    user_id: i64,
}

/// Builder for the [`replaceManagedBotToken`](https://core.telegram.org/bots/api#replacemanagedbottoken) method (Bot API 9.6).
///
/// Revokes the current token of a managed bot and generates a new one.
/// Returns the new token as a `String`.
pub struct ReplaceManagedBotToken {
    client: BotClient,
    params: ReplaceManagedBotTokenParams,
}

impl ReplaceManagedBotToken {
    pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
        Self {
            client,
            params: ReplaceManagedBotTokenParams { user_id },
        }
    }
}

impl_into_future!(ReplaceManagedBotToken, String, "replaceManagedBotToken");

// ─── getManagedBotToken ───────────────────────────────────────────────────────

#[derive(Serialize)]
struct GetManagedBotTokenParams {
    user_id: i64,
}

/// Builder for the [`getManagedBotToken`](https://core.telegram.org/bots/api#getmanagedbottoken) method (Bot API 9.6).
pub struct GetManagedBotToken {
    client: BotClient,
    params: GetManagedBotTokenParams,
}

impl GetManagedBotToken {
    pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
        Self {
            client,
            params: GetManagedBotTokenParams { user_id },
        }
    }
}

impl_into_future!(GetManagedBotToken, String, "getManagedBotToken");

// ─── getManagedBotAccessSettings ─────────────────────────────────────────────

#[derive(serde::Serialize)]
struct GetManagedBotAccessSettingsParams {
    user_id: i64,
}

/// Builder for the [`getManagedBotAccessSettings`](https://core.telegram.org/bots/api#getmanagedbotaccesssettings) method (Bot API 9.7).
///
/// Returns the access settings of a managed bot.
pub struct GetManagedBotAccessSettings {
    client: BotClient,
    params: GetManagedBotAccessSettingsParams,
}

impl GetManagedBotAccessSettings {
    pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
        Self {
            client,
            params: GetManagedBotAccessSettingsParams { user_id },
        }
    }
}

impl IntoFuture for GetManagedBotAccessSettings {
    type Output = crate::error::Result<rustigram_types::user::BotAccessSettings>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move {
            self.client
                .post_json("getManagedBotAccessSettings", &self.params)
                .await
        })
    }
}

// ─── setManagedBotAccessSettings ─────────────────────────────────────────────

#[derive(serde::Serialize)]
struct SetManagedBotAccessSettingsParams {
    user_id: i64,
    is_access_restricted: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    added_user_ids: Option<Vec<i64>>,
}

/// Builder for the [`setManagedBotAccessSettings`](https://core.telegram.org/bots/api#setmanagedbotaccesssettings) method (Bot API 9.7).
///
/// Changes the access settings of a managed bot.
pub struct SetManagedBotAccessSettings {
    client: BotClient,
    params: SetManagedBotAccessSettingsParams,
}

impl SetManagedBotAccessSettings {
    pub(crate) fn new(client: BotClient, user_id: i64, is_access_restricted: bool) -> Self {
        Self {
            client,
            params: SetManagedBotAccessSettingsParams {
                user_id,
                is_access_restricted,
                added_user_ids: None,
            },
        }
    }

    /// Up to 10 user IDs who will have access to the bot in addition to its owner.
    /// Ignored if `is_access_restricted` is `false`.
    pub fn added_user_ids(mut self, ids: Vec<i64>) -> Self {
        self.params.added_user_ids = Some(ids);
        self
    }
}

impl IntoFuture for SetManagedBotAccessSettings {
    type Output = crate::error::Result<bool>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move {
            self.client
                .post_json("setManagedBotAccessSettings", &self.params)
                .await
        })
    }
}