-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmenu.go
57 lines (49 loc) · 1.33 KB
/
menu.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
package fbbot
type Menu struct {
Locale string `json:"locale"`
ComposerInputDisabled bool `json:"composer_input_disabled"`
CallToActions []*MenuItem `json:"call_to_actions"`
}
func NewMenu() *Menu {
return &Menu{
Locale: "default",
}
}
func (m *Menu) AddMenuItems(items ...*MenuItem) {
m.CallToActions = append(m.CallToActions, items...)
}
type MenuItem struct {
Title string `json:"title"`
Type string `json:"type"`
URL string `json:"url,omitempty"`
WebviewHeightRatio string `json:"webview_height_ratio,omitempty"`
Payload string `json:"payload,omitempty"`
CallToActions []*MenuItem `json:"call_to_actions,omitempty"`
}
func NewWebURLMenuItem(title, url string) *MenuItem {
return &MenuItem{
Title: title,
Type: "web_url",
URL: url,
WebviewHeightRatio: "full",
}
}
func NewPostbackMenuItem(title, payload string) *MenuItem {
return &MenuItem{
Title: title,
Type: "postback",
Payload: payload,
}
}
func NewNestedMenuItem(title string) *MenuItem {
return &MenuItem{
Title: title,
Type: "nested",
}
}
// AddMenuItems only used for nested menu item
func (mi *MenuItem) AddMenuItems(items ...*MenuItem) {
if mi.Type == "nested" {
mi.CallToActions = append(mi.CallToActions, items...)
}
}