1 module telega.telegram.passport; 2 3 import std.typecons; 4 import telega.botapi; 5 import telega.serialization; 6 7 version (unittest) 8 { 9 import telega.test : assertEquals; 10 } 11 12 /******************************************************************/ 13 /* Types */ 14 /******************************************************************/ 15 16 struct PassportData 17 { 18 EncryptedPassportElement[] data; 19 EncryptedCredentials credentials; 20 } 21 22 struct PassportFile 23 { 24 string file_id; 25 string file_unique_id; 26 uint file_size; 27 uint file_date; 28 } 29 30 struct EncryptedPassportElement 31 { 32 enum Type 33 { 34 PersonalDetails = "personal_details", 35 Passport = "passport", 36 DriverLicence = "driver_license", 37 IdentityCard = "identity_card", 38 InternalPassport = "internal_passport", 39 Address = "address", 40 UtilityBill = "utility_bill", 41 BankStatement = "bank_statement", 42 RentalAgreement = "rental_agreement", 43 PassportRegistration = "passport_registration", 44 TemporaryRegistration = "temporary_registration", 45 PhoneNumber = "phone_number", 46 Email = "email" 47 } 48 49 string type; 50 Nullable!string data; 51 Nullable!string phone_number; 52 Nullable!string email; 53 Nullable!(PassportFile[]) files; 54 Nullable!PassportFile front_side; 55 Nullable!PassportFile reverse_side; 56 Nullable!PassportFile selfie; 57 Nullable!(PassportFile[]) translation; 58 string hash; 59 } 60 61 struct EncryptedCredentials 62 { 63 string data; 64 string hash; 65 string secret; 66 } 67 68 import std.meta : AliasSeq; 69 70 alias PassportElementErrorStructs = AliasSeq!( 71 PassportElementErrorDataField, 72 PassportElementErrorFrontSide, 73 PassportElementErrorReverseSide, 74 PassportElementErrorSelfie, 75 PassportElementErrorFile, 76 PassportElementErrorFiles, 77 PassportElementErrorTranslationFile, 78 PassportElementErrorTranslationFiles, 79 PassportElementErrorUnspecified, 80 ); 81 82 alias PassportElementError = JsonableAlgebraicProxy!PassportElementErrorStructs; 83 84 85 struct PassportElementErrorDataField 86 { 87 string source; 88 string type; 89 string field_name; 90 string data_hash; 91 string message; 92 } 93 94 struct PassportElementErrorFrontSide 95 { 96 string source = "front_side"; 97 string type; 98 string file_hash; 99 string message; 100 } 101 102 struct PassportElementErrorReverseSide 103 { 104 string source = "reverse_side"; 105 string type; 106 string file_hash; 107 string message; 108 } 109 110 struct PassportElementErrorSelfie 111 { 112 string source = "selfie"; 113 string type; 114 string file_hash; 115 string message; 116 } 117 118 struct PassportElementErrorFile 119 { 120 string source = "file"; 121 string type; 122 string file_hash; 123 string message; 124 } 125 126 struct PassportElementErrorFiles 127 { 128 string source = "files"; 129 string type; 130 string[] file_hashes; 131 string message; 132 } 133 134 struct PassportElementErrorTranslationFile 135 { 136 string source = "translation_file"; 137 string type; 138 string file_hash; 139 string message; 140 } 141 142 struct PassportElementErrorTranslationFiles 143 { 144 string source = "translation_files"; 145 string type; 146 string[] file_hashes; 147 string message; 148 } 149 150 struct PassportElementErrorUnspecified 151 { 152 string source = "unspecified"; 153 string type; 154 string element_hash; 155 string message; 156 } 157 158 /******************************************************************/ 159 /* Methods */ 160 /******************************************************************/ 161 162 struct SetPassportDataErrorsMethod 163 { 164 mixin TelegramMethod!"/setPassportDataErrors"; 165 166 uint user_id; 167 PassportElementError[] errors; 168 } 169 170 unittest 171 { 172 SetPassportDataErrorsMethod m = { 173 user_id: 42, 174 errors: [ 175 PassportElementErrorUnspecified( 176 "unspecified", 177 EncryptedPassportElement.Type.Email, 178 "#123", 179 "Error Message" 180 ) 181 ] 182 }; 183 184 m.serializeToJsonString() 185 .assertEquals( 186 `{"user_id":42,"errors":[{"source":"unspecified","type":"email","element_hash":"#123",` ~ 187 `"message":"Error Message"}]}` 188 ); 189 } 190 191 bool setPassportDataErrors(BotApi api, uint userId, PassportElementError[] errors) 192 { 193 SetPassportDataErrorsMethod m = { 194 user_id : userId, 195 errors : errors 196 }; 197 198 return api.setPassportDataErrors(m); 199 } 200 201 bool setPassportDataErrors(BotApi api, ref SetPassportDataErrorsMethod m) 202 { 203 return api.callMethod!(bool, SetPassportDataErrorsMethod)(m); 204 }