forked from mileusna/viber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.go
203 lines (176 loc) · 4.82 KB
/
button.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
package viber
// Button for carousel and keyboards
type Button struct {
Columns int `json:"Columns"`
Rows int `json:"Rows"`
ActionType ActionType `json:"ActionType"`
ActionBody string `json:"ActionBody"`
Image string `json:"Image,omitempty"`
Text string `json:"Text,omitempty"`
TextSize TextSize `json:"TextSize,omitempty"`
TextVAlign TextVAlign `json:"TextVAlign,omitempty"`
TextHAlign TextHAlign `json:"TextHAlign,omitempty"`
TextOpacity int8 `json:"TextOpacity,omitempty"`
TextBgGradientColor string `json:"TextBgGradientColor,omitempty"`
BgColor string `json:"BgColor,omitempty"`
BgMediaType string `json:"BgMediaType,omitempty"`
BgMedia string `json:"BgMedia,omitempty"`
BgLoop bool `json:"BgLoop,omitempty"`
Silent bool `json:"Silent,omitempty"`
}
// NewButton helper function for creating button with text and image
func (v *Viber) NewButton(cols, rows int, typ ActionType, actionBody string, text, image string) *Button {
return &Button{
Columns: cols,
Rows: rows,
ActionType: typ,
ActionBody: actionBody,
Text: text,
Image: image,
}
}
// NewImageButton helper function for creating image button struct with common params
func (v *Viber) NewImageButton(cols, rows int, typ ActionType, actionBody string, image string) *Button {
return &Button{
Columns: cols,
Rows: rows,
ActionType: typ,
ActionBody: actionBody,
Image: image,
}
}
// NewTextButton helper function for creating image button struct with common params
func (v *Viber) NewTextButton(cols, rows int, t ActionType, actionBody, text string) *Button {
return &Button{
Columns: cols,
Rows: rows,
ActionType: t,
ActionBody: actionBody,
Text: text,
}
}
// TextSize for carousel buttons
// viber.Small
// viber.Medium (synonym to regular)
// viber.Large
// viber.Regular (default)
type TextSize string
// TextSize values
const (
Small = TextSize("small")
Medium = TextSize("medium")
Large = TextSize("large")
Regular = TextSize("regular")
)
// TextSizeSmall for button text
func (b *Button) TextSizeSmall() *Button {
b.TextSize = Small
return b
}
// TextSizeMedium for button text, synonym to Regular
func (b *Button) TextSizeMedium() *Button {
b.TextSize = Medium
return b
}
// TextSizeRegular for button text, synonym to Medium
func (b *Button) TextSizeRegular() *Button {
b.TextSize = Regular
return b
}
// TextSizeLarge for button text
func (b *Button) TextSizeLarge() *Button {
b.TextSize = Large
return b
}
// ActionType for carousel buttons
// viber.Reply
// viber.OpenURL
type ActionType string
// ActionType values
const (
Reply = ActionType("reply")
OpenURL = ActionType("open-url")
None = ActionType("none")
)
// TextVAlign for carousel buttons
// viber.Top
// viber.Middle (default)
// viber.Bottom
type TextVAlign string
// TextVAlign values
const (
Top = TextVAlign("top")
Middle = TextVAlign("middle")
Bottom = TextVAlign("bottom")
)
// TextVAlignTop vertically align text to the top
func (b *Button) TextVAlignTop() *Button {
b.TextVAlign = Top
return b
}
// TextVAlignMiddle vertically align text to the middle
func (b *Button) TextVAlignMiddle() *Button {
b.TextVAlign = Middle
return b
}
// TextVAlignBottom vertically align text to the bottom
func (b *Button) TextVAlignBottom() *Button {
b.TextVAlign = Bottom
return b
}
// TextHAlign for carousel buttons
// viber.Left
// viber.Center (default)
// viber.Middle
type TextHAlign string
// TextHAlign values
const (
Left = TextHAlign("left")
Center = TextHAlign("center")
Right = TextHAlign("right")
)
// TextHAlignLeft horizontaly center text left
func (b *Button) TextHAlignLeft() *Button {
b.TextHAlign = Left
return b
}
// TextHAlignCenter horizontaly center text
func (b *Button) TextHAlignCenter() *Button {
b.TextHAlign = Center
return b
}
// TextHAlignRight horizontaly align text right
func (b *Button) TextHAlignRight() *Button {
b.TextHAlign = Right
return b
}
// SetSilent response from button
func (b *Button) SetSilent() *Button {
b.Silent = true
return b
}
// SetBgColor for button
func (b *Button) SetBgColor(hex string) *Button {
b.BgColor = hex
return b
}
// SetTextOpacity 0-100
func (b *Button) SetTextOpacity(o int8) *Button {
if o >= 0 && o <= 100 {
b.TextOpacity = o
}
return b
}
// BgMediaGIF set BgMedia to GIF with loop param
func (b *Button) BgMediaGIF(gifURL string, loop bool) *Button {
b.BgMediaType = "gif"
b.BgMedia = gifURL
b.BgLoop = loop
return b
}
// BgMediaPicture to set background to PNG or JPG. Use BgMediaGIF for GIF background
func (b *Button) BgMediaPicture(picURL string) *Button {
b.BgMediaType = "picture"
b.BgMedia = picURL
return b
}