-
Notifications
You must be signed in to change notification settings - Fork 26
/
passport.go
228 lines (197 loc) · 11.7 KB
/
passport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package echotron
import (
"encoding/json"
"net/url"
)
// PassportData contains information about Telegram Passport data shared with the bot by the user.
type PassportData struct {
Credentials EncryptedCredentials `json:"encrypted_credentials"`
Data []EncryptedPassportElement `json:"encrypted_passport_element"`
}
// PassportFile represents a file uploaded to Telegram Passport.
// Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.
type PassportFile struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
FileSize int64 `json:"file_size"`
FileDate int64 `json:"file_date"`
}
// EncryptedPassportElementType is a custom type for the various possible options used as Type in EncryptedPassportElement.
type EncryptedPassportElementType string
// These are all the possible options that can be used as Type in EncryptedPassportElement.
const (
TypePersonalDetails EncryptedPassportElementType = "personal_details"
TypePassport = "passport"
TypeDriverLicense = "driver_license"
TypeIdentityCard = "identity_card"
TypeInternalPassport = "internal_passport"
TypeAddress = "address"
TypeUtilityBill = "utility_bill"
TypeBankStatement = "bank_statement"
TypeRentalAgreement = "rental_agreement"
TypePassportRegistration = "passport_registration"
TypeTemporaryRegistration = "temporary_registration"
TypePhoneNumber = "phone_number"
TypeEmail = "email"
)
// EncryptedPassportElement contains information about documents or other Telegram Passport elements shared with the bot by the user.
type EncryptedPassportElement struct {
Type EncryptedPassportElementType `json:"type"`
Data string `json:"data,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
Email string `json:"email,omitempty"`
Files *[]PassportFile `json:"files,omitempty"`
FrontSide *PassportFile `json:"front_side,omitempty"`
ReverseSide *PassportFile `json:"reverse_side,omitempty"`
Selfie *PassportFile `json:"selfie,omitempty"`
Translation *[]PassportFile `json:"translation,omitempty"`
Hash string `json:"hash"`
}
// EncryptedCredentials contains data required for decrypting and authenticating EncryptedPassportElement.
// See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes.
// https://core.telegram.org/passport#receiving-information
type EncryptedCredentials struct {
Data string `json:"data"`
Hash string `json:"hash"`
Secret string `json:"secret"`
}
// PassportElementErrorSource is a custom type for the various possible options used as Source in PassportElementSource.
type PassportElementErrorSource string
// These are all the possible options that can be used as Source in PassportElementSource.
const (
SourceData PassportElementErrorSource = "data"
SourceFrontSide = "front_side"
SourceReverseSide = "reverse_side"
SourceSelfie = "selfie"
SourceFile = "file"
SourceFiles = "files"
SourceTranslationFile = "translation_file"
SourceTranslationFiles = "translation_files"
SourceUnspecified = "unspecified"
)
// PassportElementError is an interface for the various PassportElementError types.
type PassportElementError interface {
ImplementsPassportElementError()
}
// PassportElementErrorDataField represents an issue in one of the data fields that was provided by the user.
// The error is considered resolved when the field's value changes.
// Source MUST BE SourceData.
// Type MUST BE one of TypePersonalDetails, TypePassport, TypeDriverLicense, TypeIdentityCard, TypeInternalPassport and TypeAddress.
type PassportElementErrorDataField struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
FieldName string `json:"field_name"`
DataHash string `json:"data_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorDataField) ImplementsPassportElementError() {}
// PassportElementErrorFrontSide represents an issue with the front side of a document.
// The error is considered resolved when the file with the front side of the document changes.
// Source MUST BE SourceFrontSide.
// Type MUST BE one of TypeDriverLicense and TypeIdentityCard.
type PassportElementErrorFrontSide struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
FileHash string `json:"file_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorFrontSide) ImplementsPassportElementError() {}
// PassportElementErrorReverseSide represents an issue with the reverse side of a document.
// The error is considered resolved when the file with the reverse side of the document changes.
// Source MUST BE SourceReverseSide.
// Type MUST BE one of TypeDriverLicense and TypeIdentityCard.
type PassportElementErrorReverseSide struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
FileHash string `json:"file_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorReverseSide) ImplementsPassportElementError() {}
// PassportElementErrorSelfie represents an issue with the selfie with a document.
// The error is considered resolved when the file with the selfie changes.
// Source MUST BE SourceSelfie.
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard and TypeIdentityPassport.
type PassportElementErrorSelfie struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
FileHash string `json:"file_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorSelfie) ImplementsPassportElementError() {}
// PassportElementErrorFile represents an issue with the document scan.
// The error is considered resolved when the file with the document scan changes.
// Source MUST BE SourceFile.
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard and TypeIdentityPassport.
type PassportElementErrorFile struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
FileHash string `json:"file_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorFile) ImplementsPassportElementError() {}
// PassportElementErrorFiles represents an issue with a list of scans.
// The error is considered resolved when the list of files containing the scans changes.
// Source MUST BE SourceFiles.
// Type MUST BE one of TypeUtilityBill, TypeBankStatement, TypeRentalAgreement, TypePassportRegistration and TypeTemporaryRegistration.
type PassportElementErrorFiles struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
Message string `json:"message"`
FileHashes []string `json:"file_hashes"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorFiles) ImplementsPassportElementError() {}
// PassportElementErrorTranslationFile represents an issue with one of the files that constitute the translation of the document.
// The error is considered resolved when the file changes.
// Source MUST BE SourceTranslationFile.
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard, TypeInternalPassport, TypeUtilityBill, TypeBankStatement,
// TypeRentalAgreement, TypePassportRegistration and TypeTemporaryRegistration.
type PassportElementErrorTranslationFile struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
FileHash string `json:"file_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorTranslationFile) ImplementsPassportElementError() {}
// PassportElementErrorTranslationFiles represents an issue with the translated version of a document.
// The error is considered resolved when a file with the document translation changes.
// Source MUST BE SourceTranslationFiles.
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard, TypeInternalPassport, TypeUtilityBill, TypeBankStatement,
// TypeRentalAgreement, TypePassportRegistration and TypeTemporaryRegistration.
type PassportElementErrorTranslationFiles struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
Message string `json:"message"`
FileHashes []string `json:"file_hashes"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorTranslationFiles) ImplementsPassportElementError() {}
// PassportElementErrorUnspecified represents an issue in an unspecified place.
// The error is considered resolved when new data is added.
type PassportElementErrorUnspecified struct {
Source PassportElementErrorSource `json:"source"`
Type EncryptedPassportElementType `json:"type"`
ElementHash string `json:"element_hash"`
Message string `json:"message"`
}
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
func (p PassportElementErrorUnspecified) ImplementsPassportElementError() {}
// SetPassportDataErrors Informs a user that some of the Telegram Passport elements they provided contains errors.
// The user will not be able to re-submit their Passport to you until the errors are fixed.
// The contents of the field for which you returned the error must change.
func (a API) SetPassportDataErrors(userID int64, errors []PassportElementError) (res APIResponseBool, err error) {
var vals = make(url.Values)
errorsArr, err := json.Marshal(errors)
if err != nil {
return res, err
}
vals.Set("user_id", itoa(userID))
vals.Set("errors", string(errorsArr))
return res, client.get(a.base, "setPassportDataErrors", vals, &res)
}