-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbutton.go
More file actions
189 lines (164 loc) · 4.39 KB
/
button.go
File metadata and controls
189 lines (164 loc) · 4.39 KB
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
package instabot
import (
"encoding/json"
)
// Button defines button type.
type Button interface {
Type() ButtonType
}
// ButtonType defines button type.
type ButtonType string
// all button type.
// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons
const (
ButtonTypeURL ButtonType = ButtonType("web_url")
ButtonTypePostBack ButtonType = ButtonType("postback")
ButtonTypeCall ButtonType = ButtonType("phone_number")
ButtonTypeLogin ButtonType = ButtonType("account_link")
ButtonTypeLogOut ButtonType = ButtonType("account_unlink")
ButtonTypeGamePlay ButtonType = ButtonType("game_play")
)
// URLButton defines URL button.
// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#url
type URLButton struct {
buttonType ButtonType
Title string
URL string
}
// NewURLButton returns a new url button.
func NewURLButton(title string, URL string) *URLButton {
return &URLButton{
buttonType: ButtonTypeURL,
Title: title,
URL: URL,
}
}
// Type returns button type.
func (b *URLButton) Type() ButtonType {
return b.buttonType
}
// MarshalJSON returns json of the button.
func (b *URLButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Title string `json:"title"`
URL string `json:"url"`
}{
Type: string(b.buttonType),
Title: b.Title,
URL: b.URL,
})
}
// PostBackButton defines post back button.
// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#postback
type PostBackButton struct {
buttonType ButtonType
Title string
Payload string
}
// NewPostBackButton returns a new post back button.
func NewPostBackButton(title string, payload string) *PostBackButton {
return &PostBackButton{
buttonType: ButtonTypePostBack,
Title: title,
Payload: payload,
}
}
// Type returns button type.
func (b *PostBackButton) Type() ButtonType {
return b.buttonType
}
// MarshalJSON returns json of the button.
func (b *PostBackButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Title string `json:"title"`
Payload string `json:"payload"`
}{
Type: string(b.buttonType),
Title: b.Title,
Payload: b.Payload,
})
}
// CallButton defines call button.
// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#call
type CallButton struct {
buttonType ButtonType
Title string
PhoneNumber string
}
// NewCallButton returns a new call button.
func NewCallButton(title string, PhoneNumber string) *CallButton {
return &CallButton{
buttonType: ButtonTypeCall,
Title: title,
PhoneNumber: PhoneNumber,
}
}
// Type returns button type.
func (b *CallButton) Type() ButtonType {
return b.buttonType
}
// MarshalJSON returns json of the button.
func (b *CallButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Title string `json:"title"`
Payload string `json:"payload"`
}{
Type: string(b.buttonType),
Title: b.Title,
Payload: b.PhoneNumber,
})
}
// LogInButton defines log in button.
// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#login
type LogInButton struct {
buttonType ButtonType
URL string
}
// NewLogInButton returns a new log in button.
func NewLogInButton(URL string) *LogInButton {
return &LogInButton{
buttonType: ButtonTypeLogin,
URL: URL,
}
}
// Type returns button type.
func (b *LogInButton) Type() ButtonType {
return b.buttonType
}
// MarshalJSON returns json of the button.
func (b *LogInButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
URL string `json:"url"`
}{
Type: string(b.buttonType),
URL: b.URL,
})
}
// LogOutButton defines log out button.
// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#logout
type LogOutButton struct {
buttonType ButtonType
}
// NewLogOutButton returns a new log out button.
func NewLogOutButton() *LogOutButton {
return &LogOutButton{
buttonType: ButtonTypeLogOut,
}
}
// Type returns button type.
func (b *LogOutButton) Type() ButtonType {
return b.buttonType
}
// MarshalJSON returns json of the button.
func (b *LogOutButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
}{
Type: string(b.buttonType),
})
}
// TODO:- define GamePlayButton.