This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from Arman92/go-tdlib
/
inputIDentityDocument.go
78 lines (67 loc) · 3.1 KB
/
inputIDentityDocument.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
package tdlib
import (
"encoding/json"
)
// InputIdentityDocument An identity document to be saved to Telegram Passport
type InputIdentityDocument struct {
tdCommon
Number string `json:"number"` // Document number; 1-24 characters
ExpiryDate *Date `json:"expiry_date"` // Document expiry date; pass null if not applicable
FrontSide InputFile `json:"front_side"` // Front side of the document
ReverseSide InputFile `json:"reverse_side"` // Reverse side of the document; only for driver license and identity card; pass null otherwise
Selfie InputFile `json:"selfie"` // Selfie with the document; pass null if unavailable
Translation []InputFile `json:"translation"` // List of files containing a certified English translation of the document
}
// MessageType return the string telegram-type of InputIdentityDocument
func (inputIdentityDocument *InputIdentityDocument) MessageType() string {
return "inputIdentityDocument"
}
// NewInputIdentityDocument creates a new InputIdentityDocument
//
// @param number Document number; 1-24 characters
// @param expiryDate Document expiry date; pass null if not applicable
// @param frontSide Front side of the document
// @param reverseSide Reverse side of the document; only for driver license and identity card; pass null otherwise
// @param selfie Selfie with the document; pass null if unavailable
// @param translation List of files containing a certified English translation of the document
func NewInputIdentityDocument(number string, expiryDate *Date, frontSide InputFile, reverseSide InputFile, selfie InputFile, translation []InputFile) *InputIdentityDocument {
inputIdentityDocumentTemp := InputIdentityDocument{
tdCommon: tdCommon{Type: "inputIdentityDocument"},
Number: number,
ExpiryDate: expiryDate,
FrontSide: frontSide,
ReverseSide: reverseSide,
Selfie: selfie,
Translation: translation,
}
return &inputIdentityDocumentTemp
}
// UnmarshalJSON unmarshal to json
func (inputIdentityDocument *InputIdentityDocument) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
Number string `json:"number"` // Document number; 1-24 characters
ExpiryDate *Date `json:"expiry_date"` // Document expiry date; pass null if not applicable
Translation []InputFile `json:"translation"` // List of files containing a certified English translation of the document
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
inputIdentityDocument.tdCommon = tempObj.tdCommon
inputIdentityDocument.Number = tempObj.Number
inputIdentityDocument.ExpiryDate = tempObj.ExpiryDate
inputIdentityDocument.Translation = tempObj.Translation
fieldFrontSide, _ := unmarshalInputFile(objMap["front_side"])
inputIdentityDocument.FrontSide = fieldFrontSide
fieldReverseSide, _ := unmarshalInputFile(objMap["reverse_side"])
inputIdentityDocument.ReverseSide = fieldReverseSide
fieldSelfie, _ := unmarshalInputFile(objMap["selfie"])
inputIdentityDocument.Selfie = fieldSelfie
return nil
}