Downloads and prints the received passport data.
(update: Update, context: ContextTypes.DEFAULT_TYPE)
| 34 | |
| 35 | |
| 36 | async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
| 37 | """Downloads and prints the received passport data.""" |
| 38 | # Retrieve passport data |
| 39 | passport_data = update.message.passport_data |
| 40 | # If our nonce doesn't match what we think, this Update did not originate from us |
| 41 | # Ideally you would randomize the nonce on the server |
| 42 | if passport_data.decrypted_credentials.nonce != "thisisatest": |
| 43 | return |
| 44 | |
| 45 | # Print the decrypted credential data |
| 46 | # For all elements |
| 47 | # Print their decrypted data |
| 48 | # Files will be downloaded to current directory |
| 49 | for data in passport_data.decrypted_data: # This is where the data gets decrypted |
| 50 | if data.type == "phone_number": |
| 51 | logger.info("Phone: %s", data.phone_number) |
| 52 | elif data.type == "email": |
| 53 | logger.info("Email: %s", data.email) |
| 54 | if data.type in ( |
| 55 | "personal_details", |
| 56 | "passport", |
| 57 | "driver_license", |
| 58 | "identity_card", |
| 59 | "internal_passport", |
| 60 | "address", |
| 61 | ): |
| 62 | logger.info(data.type, data.data) |
| 63 | if data.type in ( |
| 64 | "utility_bill", |
| 65 | "bank_statement", |
| 66 | "rental_agreement", |
| 67 | "passport_registration", |
| 68 | "temporary_registration", |
| 69 | ): |
| 70 | logger.info(data.type, len(data.files), "files") |
| 71 | for file in data.files: |
| 72 | actual_file = await file.get_file() |
| 73 | logger.info(actual_file) |
| 74 | await actual_file.download_to_drive() |
| 75 | if ( |
| 76 | data.type in ("passport", "driver_license", "identity_card", "internal_passport") |
| 77 | and data.front_side |
| 78 | ): |
| 79 | front_file = await data.front_side.get_file() |
| 80 | logger.info(data.type, front_file) |
| 81 | await front_file.download_to_drive() |
| 82 | if data.type in ("driver_license" and "identity_card") and data.reverse_side: |
| 83 | reverse_file = await data.reverse_side.get_file() |
| 84 | logger.info(data.type, reverse_file) |
| 85 | await reverse_file.download_to_drive() |
| 86 | if ( |
| 87 | data.type in ("passport", "driver_license", "identity_card", "internal_passport") |
| 88 | and data.selfie |
| 89 | ): |
| 90 | selfie_file = await data.selfie.get_file() |
| 91 | logger.info(data.type, selfie_file) |
| 92 | await selfie_file.download_to_drive() |
| 93 | if data.translation and data.type in ( |
nothing calls this directly
no test coverage detected