passport.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. package tgbotapi
  2. // PassportRequestInfoConfig allows you to request passport info
  3. type PassportRequestInfoConfig struct {
  4. BotID int `json:"bot_id"`
  5. Scope *PassportScope `json:"scope"`
  6. Nonce string `json:"nonce"`
  7. PublicKey string `json:"public_key"`
  8. }
  9. // PassportScopeElement supports using one or one of several elements.
  10. type PassportScopeElement interface {
  11. ScopeType() string
  12. }
  13. // PassportScope is the requested scopes of data.
  14. type PassportScope struct {
  15. V int `json:"v"`
  16. Data []PassportScopeElement `json:"data"`
  17. }
  18. // PassportScopeElementOneOfSeveral allows you to request any one of the
  19. // requested documents.
  20. type PassportScopeElementOneOfSeveral struct {
  21. }
  22. // ScopeType is the scope type.
  23. func (eo *PassportScopeElementOneOfSeveral) ScopeType() string {
  24. return "one_of"
  25. }
  26. // PassportScopeElementOne requires the specified element be provided.
  27. type PassportScopeElementOne struct {
  28. Type string `json:"type"` // One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”
  29. Selfie bool `json:"selfie"`
  30. Translation bool `json:"translation"`
  31. NativeNames bool `json:"native_name"`
  32. }
  33. // ScopeType is the scope type.
  34. func (eo *PassportScopeElementOne) ScopeType() string {
  35. return "one"
  36. }
  37. type (
  38. // PassportData contains information about Telegram Passport data shared with
  39. // the bot by the user.
  40. PassportData struct {
  41. // Array with information about documents and other Telegram Passport
  42. // elements that was shared with the bot
  43. Data []EncryptedPassportElement `json:"data"`
  44. // Encrypted credentials required to decrypt the data
  45. Credentials *EncryptedCredentials `json:"credentials"`
  46. }
  47. // PassportFile represents a file uploaded to Telegram Passport. Currently, all
  48. // Telegram Passport files are in JPEG format when decrypted and don't exceed
  49. // 10MB.
  50. PassportFile struct {
  51. // Unique identifier for this file
  52. FileID string `json:"file_id"`
  53. FileUniqueID string `json:"file_unique_id"`
  54. // File size
  55. FileSize int `json:"file_size"`
  56. // Unix time when the file was uploaded
  57. FileDate int64 `json:"file_date"`
  58. }
  59. // EncryptedPassportElement contains information about documents or other
  60. // Telegram Passport elements shared with the bot by the user.
  61. EncryptedPassportElement struct {
  62. // Element type.
  63. Type string `json:"type"`
  64. // Base64-encoded encrypted Telegram Passport element data provided by
  65. // the user, available for "personal_details", "passport",
  66. // "driver_license", "identity_card", "identity_passport" and "address"
  67. // types. Can be decrypted and verified using the accompanying
  68. // EncryptedCredentials.
  69. Data string `json:"data,omitempty"`
  70. // User's verified phone number, available only for "phone_number" type
  71. PhoneNumber string `json:"phone_number,omitempty"`
  72. // User's verified email address, available only for "email" type
  73. Email string `json:"email,omitempty"`
  74. // Array of encrypted files with documents provided by the user,
  75. // available for "utility_bill", "bank_statement", "rental_agreement",
  76. // "passport_registration" and "temporary_registration" types. Files can
  77. // be decrypted and verified using the accompanying EncryptedCredentials.
  78. Files []PassportFile `json:"files,omitempty"`
  79. // Encrypted file with the front side of the document, provided by the
  80. // user. Available for "passport", "driver_license", "identity_card" and
  81. // "internal_passport". The file can be decrypted and verified using the
  82. // accompanying EncryptedCredentials.
  83. FrontSide *PassportFile `json:"front_side,omitempty"`
  84. // Encrypted file with the reverse side of the document, provided by the
  85. // user. Available for "driver_license" and "identity_card". The file can
  86. // be decrypted and verified using the accompanying EncryptedCredentials.
  87. ReverseSide *PassportFile `json:"reverse_side,omitempty"`
  88. // Encrypted file with the selfie of the user holding a document,
  89. // provided by the user; available for "passport", "driver_license",
  90. // "identity_card" and "internal_passport". The file can be decrypted
  91. // and verified using the accompanying EncryptedCredentials.
  92. Selfie *PassportFile `json:"selfie,omitempty"`
  93. }
  94. // EncryptedCredentials contains data required for decrypting and
  95. // authenticating EncryptedPassportElement. See the Telegram Passport
  96. // Documentation for a complete description of the data decryption and
  97. // authentication processes.
  98. EncryptedCredentials struct {
  99. // Base64-encoded encrypted JSON-serialized data with unique user's
  100. // payload, data hashes and secrets required for EncryptedPassportElement
  101. // decryption and authentication
  102. Data string `json:"data"`
  103. // Base64-encoded data hash for data authentication
  104. Hash string `json:"hash"`
  105. // Base64-encoded secret, encrypted with the bot's public RSA key,
  106. // required for data decryption
  107. Secret string `json:"secret"`
  108. }
  109. // PassportElementError represents an error in the Telegram Passport element
  110. // which was submitted that should be resolved by the user.
  111. PassportElementError interface{}
  112. // PassportElementErrorDataField represents an issue in one of the data
  113. // fields that was provided by the user. The error is considered resolved
  114. // when the field's value changes.
  115. PassportElementErrorDataField struct {
  116. // Error source, must be data
  117. Source string `json:"source"`
  118. // The section of the user's Telegram Passport which has the error, one
  119. // of "personal_details", "passport", "driver_license", "identity_card",
  120. // "internal_passport", "address"
  121. Type string `json:"type"`
  122. // Name of the data field which has the error
  123. FieldName string `json:"field_name"`
  124. // Base64-encoded data hash
  125. DataHash string `json:"data_hash"`
  126. // Error message
  127. Message string `json:"message"`
  128. }
  129. // PassportElementErrorFrontSide represents an issue with the front side of
  130. // a document. The error is considered resolved when the file with the front
  131. // side of the document changes.
  132. PassportElementErrorFrontSide struct {
  133. // Error source, must be front_side
  134. Source string `json:"source"`
  135. // The section of the user's Telegram Passport which has the issue, one
  136. // of "passport", "driver_license", "identity_card", "internal_passport"
  137. Type string `json:"type"`
  138. // Base64-encoded hash of the file with the front side of the document
  139. FileHash string `json:"file_hash"`
  140. // Error message
  141. Message string `json:"message"`
  142. }
  143. // PassportElementErrorReverseSide represents an issue with the reverse side
  144. // of a document. The error is considered resolved when the file with reverse
  145. // side of the document changes.
  146. PassportElementErrorReverseSide struct {
  147. // Error source, must be reverse_side
  148. Source string `json:"source"`
  149. // The section of the user's Telegram Passport which has the issue, one
  150. // of "driver_license", "identity_card"
  151. Type string `json:"type"`
  152. // Base64-encoded hash of the file with the reverse side of the document
  153. FileHash string `json:"file_hash"`
  154. // Error message
  155. Message string `json:"message"`
  156. }
  157. // PassportElementErrorSelfie represents an issue with the selfie with a
  158. // document. The error is considered resolved when the file with the selfie
  159. // changes.
  160. PassportElementErrorSelfie struct {
  161. // Error source, must be selfie
  162. Source string `json:"source"`
  163. // The section of the user's Telegram Passport which has the issue, one
  164. // of "passport", "driver_license", "identity_card", "internal_passport"
  165. Type string `json:"type"`
  166. // Base64-encoded hash of the file with the selfie
  167. FileHash string `json:"file_hash"`
  168. // Error message
  169. Message string `json:"message"`
  170. }
  171. // PassportElementErrorFile represents an issue with a document scan. The
  172. // error is considered resolved when the file with the document scan changes.
  173. PassportElementErrorFile struct {
  174. // Error source, must be a file
  175. Source string `json:"source"`
  176. // The section of the user's Telegram Passport which has the issue, one
  177. // of "utility_bill", "bank_statement", "rental_agreement",
  178. // "passport_registration", "temporary_registration"
  179. Type string `json:"type"`
  180. // Base64-encoded file hash
  181. FileHash string `json:"file_hash"`
  182. // Error message
  183. Message string `json:"message"`
  184. }
  185. // PassportElementErrorFiles represents an issue with a list of scans. The
  186. // error is considered resolved when the list of files containing the scans
  187. // changes.
  188. PassportElementErrorFiles struct {
  189. // Error source, must be files
  190. Source string `json:"source"`
  191. // The section of the user's Telegram Passport which has the issue, one
  192. // of "utility_bill", "bank_statement", "rental_agreement",
  193. // "passport_registration", "temporary_registration"
  194. Type string `json:"type"`
  195. // List of base64-encoded file hashes
  196. FileHashes []string `json:"file_hashes"`
  197. // Error message
  198. Message string `json:"message"`
  199. }
  200. // Credentials contains encrypted data.
  201. Credentials struct {
  202. Data SecureData `json:"secure_data"`
  203. // Nonce the same nonce given in the request
  204. Nonce string `json:"nonce"`
  205. }
  206. // SecureData is a map of the fields and their encrypted values.
  207. SecureData map[string]*SecureValue
  208. // PersonalDetails *SecureValue `json:"personal_details"`
  209. // Passport *SecureValue `json:"passport"`
  210. // InternalPassport *SecureValue `json:"internal_passport"`
  211. // DriverLicense *SecureValue `json:"driver_license"`
  212. // IdentityCard *SecureValue `json:"identity_card"`
  213. // Address *SecureValue `json:"address"`
  214. // UtilityBill *SecureValue `json:"utility_bill"`
  215. // BankStatement *SecureValue `json:"bank_statement"`
  216. // RentalAgreement *SecureValue `json:"rental_agreement"`
  217. // PassportRegistration *SecureValue `json:"passport_registration"`
  218. // TemporaryRegistration *SecureValue `json:"temporary_registration"`
  219. // SecureValue contains encrypted values for a SecureData item.
  220. SecureValue struct {
  221. Data *DataCredentials `json:"data"`
  222. FrontSide *FileCredentials `json:"front_side"`
  223. ReverseSide *FileCredentials `json:"reverse_side"`
  224. Selfie *FileCredentials `json:"selfie"`
  225. Translation []*FileCredentials `json:"translation"`
  226. Files []*FileCredentials `json:"files"`
  227. }
  228. // DataCredentials contains information required to decrypt data.
  229. DataCredentials struct {
  230. // DataHash checksum of encrypted data
  231. DataHash string `json:"data_hash"`
  232. // Secret of encrypted data
  233. Secret string `json:"secret"`
  234. }
  235. // FileCredentials contains information required to decrypt files.
  236. FileCredentials struct {
  237. // FileHash checksum of encrypted data
  238. FileHash string `json:"file_hash"`
  239. // Secret of encrypted data
  240. Secret string `json:"secret"`
  241. }
  242. // PersonalDetails https://core.telegram.org/passport#personaldetails
  243. PersonalDetails struct {
  244. FirstName string `json:"first_name"`
  245. LastName string `json:"last_name"`
  246. MiddleName string `json:"middle_name"`
  247. BirthDate string `json:"birth_date"`
  248. Gender string `json:"gender"`
  249. CountryCode string `json:"country_code"`
  250. ResidenceCountryCode string `json:"residence_country_code"`
  251. FirstNameNative string `json:"first_name_native"`
  252. LastNameNative string `json:"last_name_native"`
  253. MiddleNameNative string `json:"middle_name_native"`
  254. }
  255. // IDDocumentData https://core.telegram.org/passport#iddocumentdata
  256. IDDocumentData struct {
  257. DocumentNumber string `json:"document_no"`
  258. ExpiryDate string `json:"expiry_date"`
  259. }
  260. )