forked from crisp-dev/messenger-platform-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.go
63 lines (55 loc) · 1.84 KB
/
buttons.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
package template
// ButtonType defines the behavior of the button in the ButtonTemplate
type ButtonType string
const (
ButtonTypeWebURL ButtonType = "web_url"
ButtonTypePostback ButtonType = "postback"
ButtonTypePhoneNumber ButtonType = "phone_number"
ButtonTypeAccountLink ButtonType = "account_link"
ButtonTypeAccountUnlink ButtonType = "account_unlink"
)
type Button struct {
Type ButtonType `json:"type"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
Payload string `json:"payload,omitempty"`
}
// NewWebURLButton creates a button used in ButtonTemplate that redirects user to external address upon clicking the URL
func NewWebURLButton(title string, url string) Button {
return Button{
Type: ButtonTypeWebURL,
Title: title,
URL: url,
}
}
// NewPostbackButton creates a button used in ButtonTemplate that upon clicking sends a payload request to the server
func NewPostbackButton(title string, payload string) Button {
return Button{
Type: ButtonTypePostback,
Title: title,
Payload: payload,
}
}
// NewPhoneNumberButton creates a button used in ButtonTemplate that upon clicking opens a native dialer
func NewPhoneNumberButton(title string, phone string) Button {
return Button{
Type: ButtonTypePhoneNumber,
Title: title,
Payload: phone,
}
}
// NewAccountLinkButton creates a button used for account linking
// https://developers.facebook.com/docs/messenger-platform/account-linking/authentication
func NewAccountLinkButton(url string) Button {
return Button{
Type: ButtonTypeAccountLink,
URL: url,
}
}
// NewAccountUnlinkButton creates a button used for account unlinking
// https://developers.facebook.com/docs/messenger-platform/account-linking/authentication
func NewAccountUnlinkButton() Button {
return Button{
Type: ButtonTypeAccountUnlink,
}
}