-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_PersistentMenu.go
130 lines (112 loc) · 3.58 KB
/
request_PersistentMenu.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
package fbmbotapi
//go:generate ffjson $GOFILE
// PersistentMenuMessage is persistent menus message
type PersistentMenuMessage struct {
PersistentMenus []PersistentMenu `json:"persistent_menu"`
}
// PersistentMenu is mersistent menu
type PersistentMenu struct {
Locale string `json:"locale"`
ComposerInputDisabled bool `json:"composer_input_disabled"`
CallToActions []MenuItem `json:"call_to_actions,omitempty"`
}
// NewPersistentMenu creates new persistent menu
func NewPersistentMenu(locale string, composerInputDisabled bool, callToActions ...MenuItem) PersistentMenu {
menu := PersistentMenu{
Locale: locale,
ComposerInputDisabled: composerInputDisabled,
CallToActions: callToActions,
}
return menu
}
// MenuItemType is type of persistent menu item
type MenuItemType string
const (
// MenuItemTypeWebURL is for URL menu items
MenuItemTypeWebURL MenuItemType = "web_url"
// MenuItemTypePostback is for postback menu items
MenuItemTypePostback MenuItemType = "postback"
// MenuItemTypeNested is for nested menu items
MenuItemTypeNested MenuItemType = "nested"
)
// WebviewHeightRatio defines height ratio
type WebviewHeightRatio string
const (
// WebviewHeightRatioCompact is compact height ratio
WebviewHeightRatioCompact WebviewHeightRatio = "compact"
// WebviewHeightRatioTall is tall height ratio
WebviewHeightRatioTall WebviewHeightRatio = "tall"
// WebviewHeightRatioFull is full height ratio
WebviewHeightRatioFull WebviewHeightRatio = "full"
)
// WebviewShareButtonHide to hide button
const WebviewShareButtonHide = "hide"
// MenuItem is menu item
type MenuItem interface {
MenuItemType() MenuItemType
}
// MenuItemBase holds menu item base properties
type MenuItemBase struct {
Type MenuItemType `json:"type"`
Title string `json:"title"`
}
// MenuItemType returns type of menu item
func (mi MenuItemBase) MenuItemType() MenuItemType {
return mi.Type
}
// MenuItemWebURL is URL menu item
type MenuItemWebURL struct {
MenuItemBase
URL string `json:"url"`
WebviewHeightRatio WebviewHeightRatio `json:"webview_height_ratio"`
WebviewShareButton string `json:"webview_share_button,omitempty"`
MessengerExtensions bool `json:"messenger_extensions,omitempty"`
}
// NewMenuItemWebUrl creates new URL menu item
func NewMenuItemWebUrl(title, url string, webviewHeightRatio WebviewHeightRatio, shareButton, messengerExtensions bool) MenuItemWebURL {
menuItem := MenuItemWebURL{
MenuItemBase: MenuItemBase{
Type: MenuItemTypeWebURL,
Title: title,
},
URL: url,
WebviewHeightRatio: webviewHeightRatio,
MessengerExtensions: messengerExtensions,
}
if !shareButton {
menuItem.WebviewShareButton = WebviewShareButtonHide
}
return menuItem
}
// MenuItemPostback is postback menu item
type MenuItemPostback struct {
MenuItemBase
Payload string `json:"payload"`
}
// MenuItemPostback is nested menu item
type MenuItemNested struct {
MenuItemBase
CallToActions []MenuItem `json:"call_to_actions"`
}
// NewMenuItemNested creates nested menu item
func NewMenuItemNested(title string, callToActions ...MenuItem) MenuItemNested {
menuItem := MenuItemNested{
MenuItemBase: MenuItemBase{
Type: MenuItemTypeNested,
Title: title,
},
CallToActions: callToActions,
}
return menuItem
}
// NewMenuItemPostback creates postback menu item
func NewMenuItemPostback(title, payload string) MenuItemPostback {
menuItem := MenuItemPostback{
MenuItemBase: MenuItemBase{
Type: MenuItemTypePostback,
Title: title,
},
Payload: payload,
}
return menuItem
}