Skip to main content

telexide_fork/model/
telegram_passport.rs

1use super::utils::unix_date_formatting;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5/// Contains information about Telegram Passport data shared with the bot by the
6/// user.
7#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
8pub struct PassportData {
9    /// Vec with information about documents and other Telegram Passport
10    /// elements that was shared with the bot
11    pub data: Vec<EncryptedCredentials>,
12    /// Encrypted credentials required to decrypt the data
13    pub credentials: EncryptedCredentials,
14}
15
16/// This object represents a file uploaded to Telegram Passport.
17/// Currently all Telegram Passport files are in JPEG format when decrypted and
18/// don't exceed 10MB.
19#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
20pub struct PassportFile {
21    /// Identifier for this file, which can be used to download or reuse the
22    /// file
23    pub file_id: String,
24    /// Unique identifier for this file, which is supposed to be the same over
25    /// time and for different bots. Can't be used to download or reuse the
26    /// file.
27    pub file_unique_id: String,
28    /// File size
29    pub file_size: i64,
30    /// Unix time when the file was uploaded
31    #[serde(with = "unix_date_formatting")]
32    pub file_date: DateTime<Utc>,
33}
34
35/// Contains information about documents or other Telegram Passport elements
36/// shared with the bot by the user.
37#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
38pub struct EncryptedPassportElement {
39    /// Element type.
40    pub element_type: TelegramPassportElement,
41    /// Base64-encoded encrypted Telegram Passport element data provided by the
42    /// user, available for “personal_details”, “passport”,
43    /// “driver_license”, “identity_card”, “internal_passport” and “address”
44    /// types. Can be decrypted and verified using the accompanying
45    /// [EncryptedCredentials].
46    pub data: Option<String>,
47    /// User's verified phone number, available only for “phone_number” type
48    pub phone_number: Option<String>,
49    /// Array of encrypted files with documents provided by the user, available
50    /// for “utility_bill”, “bank_statement”, “rental_agreement”,
51    /// “passport_registration” and “temporary_registration” types.
52    /// Files can be decrypted and verified using the accompanying
53    /// [EncryptedCredentials].
54    pub files: Vec<PassportFile>,
55    /// Encrypted file with the front side of the document, provided by the
56    /// user. Available for “passport”, “driver_license”, “identity_card”
57    /// and “internal_passport”. The file can be decrypted and verified
58    /// using the accompanying [EncryptedCredentials].
59    pub front_side: PassportFile,
60    /// Encrypted file with the reverse side of the document, provided by the
61    /// user. Available for “driver_license” and “identity_card”.
62    /// The file can be decrypted and verified using the accompanying
63    /// [EncryptedCredentials].
64    pub reverse_side: PassportFile,
65    /// Encrypted file with the selfie of the user holding a document, provided
66    /// by the user; available for “passport”, “driver_license”,
67    /// “identity_card” and “internal_passport”. The file can be decrypted
68    /// and verified using the accompanying [EncryptedCredentials].
69    pub selfie: PassportFile,
70    /// Array of encrypted files with translated versions of documents provided
71    /// by the user. Available if requested for “passport”,
72    /// “driver_license”, “identity_card”, “internal_passport”,
73    /// "utility_bill”, “bank_statement”, “rental_agreement”,
74    /// “passport_registration” and “temporary_registration” types.
75    /// Files can be decrypted and verified using the accompanying
76    /// [EncryptedCredentials].
77    pub translation: Vec<PassportFile>,
78    /// Base64-encoded element hash for using in
79    /// [PassportElementErrorUnspecified]
80    ///
81    /// [PassportElementErrorUnspecified]:
82    /// ../api/types/struct.PassportElementErrorUnspecified.html
83    pub hash: String,
84}
85
86/// Contains data required for decrypting and authenticating
87/// [`EncryptedPassportElement`]. See the [Telegram Passport Documentation](https://core.telegram.org/passport#receiving-information)
88/// for a complete description of the data decryption and authentication
89/// processes.
90#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
91pub struct EncryptedCredentials {
92    /// Base64-encoded encrypted JSON-serialized data with unique user's
93    /// payload, data hashes and secrets required for
94    /// [EncryptedPassportElement] decryption and authentication
95    pub data: String,
96    /// Base64-encoded data hash for data authentication
97    pub hash: String,
98    /// Base64-encoded secret, encrypted with the bot's public RSA key, required
99    /// for data decryption
100    pub secret: String,
101}
102
103/// The type of a telegram passport element
104#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
105pub enum TelegramPassportElement {
106    #[serde(rename = "personal_details")]
107    PersonalDetails,
108    #[serde(rename = "passport")]
109    Passport,
110    #[serde(rename = "driver_license")]
111    DriverLicense,
112    #[serde(rename = "identity_card")]
113    IdentityCard,
114    #[serde(rename = "internal_passport")]
115    InternalPassport,
116    #[serde(rename = "address")]
117    Address,
118    #[serde(rename = "utility_bill")]
119    UtilityBill,
120    #[serde(rename = "bank_statement")]
121    BankStatement,
122    #[serde(rename = "rental_agreement")]
123    RentalAgreement,
124    #[serde(rename = "passport_registration")]
125    PassportRegistration,
126    #[serde(rename = "temporary_registration")]
127    TemporaryRegistration,
128    #[serde(rename = "phone_number")]
129    PhoneNumber,
130    #[serde(rename = "email")]
131    Email,
132}