/
models.go
142 lines (116 loc) · 3.53 KB
/
models.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
package whatsapp
import (
"time"
)
type PreparedOTPTemplate struct {
TemplateName string
TemplateType string
Language string
Components []TemplateComponent
Namespace string
}
type SendTemplateOptions struct {
TemplateName string
To string
TemplateType string
Language string
Components []TemplateComponent
Namespace string
}
type SendTemplateRequest struct {
RecipientType string `json:"recipient_type"`
To string `json:"to"`
Type string `json:"type"`
Template *Template `json:"template"`
}
type Template struct {
Name string `json:"name"`
Language *TemplateLanguage `json:"language"`
Components []TemplateComponent `json:"components"`
Namespace *string `json:"namespace,omitempty"`
}
type TemplateLanguage struct {
Policy string `json:"policy"`
Code string `json:"code"`
}
type TemplateComponentType string
const (
TemplateComponentTypeHeader TemplateComponentType = "header"
TemplateComponentTypeBody TemplateComponentType = "body"
TemplateComponentTypeButton TemplateComponentType = "button"
)
type TemplateComponentSubType string
const (
TemplateComponentSubTypeURL TemplateComponentSubType = "url"
)
type TemplateComponent struct {
Type TemplateComponentType `json:"type"`
SubType *TemplateComponentSubType `json:"sub_type,omitempty"`
Index *int `json:"index,omitempty"`
Parameters []TemplateComponentParameter `json:"parameters"`
}
func NewTemplateComponent(typ TemplateComponentType) *TemplateComponent {
return &TemplateComponent{
Type: typ,
Parameters: []TemplateComponentParameter{},
}
}
func NewTemplateButtonComponent(subtyp TemplateComponentSubType, index int) *TemplateComponent {
return &TemplateComponent{
Type: TemplateComponentTypeButton,
SubType: &subtyp,
Index: &index,
Parameters: []TemplateComponentParameter{},
}
}
type TemplateComponentParameterType string
const (
TemplateComponentParameterTypeText TemplateComponentParameterType = "text"
)
type TemplateComponentParameter struct {
Type TemplateComponentParameterType `json:"type"`
Text string `json:"text"`
}
func NewTemplateComponentTextParameter(text string) *TemplateComponentParameter {
return &TemplateComponentParameter{
Type: TemplateComponentParameterTypeText,
Text: text,
}
}
type LoginResponse struct {
Users []LoginResponseUser `json:"users"`
}
type LoginResponseUser struct {
Token string `json:"token"`
ExpiresAfter LoginResponseUserExpiresTime `json:"expires_after"`
}
type UserToken struct {
Endpoint string `json:"endpoint"`
Username string `json:"username"`
Token string `json:"token"`
ExpireAt time.Time `json:"expire_at"`
}
type LoginResponseUserExpiresTime time.Time
const (
LoginResponseUserExpiresTimeLayout = "2006-01-02 15:04:05-07:00"
)
// Implement Marshaler and Unmarshaler interface
func (j *LoginResponseUserExpiresTime) UnmarshalText(textb []byte) error {
t, err := time.Parse(LoginResponseUserExpiresTimeLayout, string(textb))
if err != nil {
return err
}
*j = LoginResponseUserExpiresTime(t)
return nil
}
func (j LoginResponseUserExpiresTime) MarshalText() ([]byte, error) {
return []byte(time.Time(j).Format(LoginResponseUserExpiresTimeLayout)), nil
}
type SendTemplateErrorResponse struct {
Errors *[]SendTemplateError `json:"errors,omitempty"`
}
type SendTemplateError struct {
Code int `json:"code"`
Title string `json:"title"`
Details string `json:"details"`
}