Skip to main content

rustigram_api/methods/
passport.rs

1use crate::client::BotClient;
2use crate::error::Result;
3use serde::Serialize;
4use std::future::{Future, IntoFuture};
5use std::pin::Pin;
6
7// ─── setPassportDataErrors ────────────────────────────────────────────────────
8
9#[derive(Serialize)]
10struct SetPassportDataErrorsParams {
11    user_id: i64,
12    /// Array of `PassportElementError` objects describing the errors.
13    ///
14    /// Uses `serde_json::Value` since `PassportElementError` is a complex enum
15    /// defined in `rustigram_types::passport`. Construct each error using the
16    /// appropriate variant from that module and serialise with `serde_json::to_value`.
17    errors: Vec<serde_json::Value>,
18}
19
20/// Builder for the [`setPassportDataErrors`](https://core.telegram.org/bots/api#setpassportdataerrors) method.
21///
22/// Informs a user that some Telegram Passport elements they provided contain
23/// errors. The user will not be able to re-submit their Passport to the bot
24/// until the errors are fixed — the contents of the affected field must change.
25///
26/// The `errors` parameter accepts `Vec<serde_json::Value>`. Construct each
27/// element from `rustigram_types::passport::PassportElementError` variants
28/// and serialise with `serde_json::to_value(&error)`.
29pub struct SetPassportDataErrors {
30    client: BotClient,
31    params: SetPassportDataErrorsParams,
32}
33
34impl SetPassportDataErrors {
35    pub(crate) fn new(client: BotClient, user_id: i64, errors: Vec<serde_json::Value>) -> Self {
36        Self {
37            client,
38            params: SetPassportDataErrorsParams { user_id, errors },
39        }
40    }
41}
42
43impl IntoFuture for SetPassportDataErrors {
44    type Output = Result<bool>;
45    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
46    fn into_future(self) -> Self::IntoFuture {
47        Box::pin(async move {
48            self.client
49                .post_json("setPassportDataErrors", &self.params)
50                .await
51        })
52    }
53}