-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub_component_button.go
69 lines (59 loc) · 1.98 KB
/
sub_component_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
package got
import "github.com/ramin0/messenger"
const (
// SubComponentButtonTypeWebURL const
SubComponentButtonTypeWebURL = "web_url"
// SubComponentButtonTypePostback const
SubComponentButtonTypePostback = "postback"
// SubComponentButtonWebviewHeightRatioCompact const
SubComponentButtonWebviewHeightRatioCompact = "compact"
// SubComponentButtonWebviewHeightRatioTall const
SubComponentButtonWebviewHeightRatioTall = "tall"
// SubComponentButtonWebviewHeightRatioFull const
SubComponentButtonWebviewHeightRatioFull = "full"
// SubComponentButtonWebviewShareButtonHide const
SubComponentButtonWebviewShareButtonHide = "hide"
// SubComponentButtonMessengerExtensionsTrue const
SubComponentButtonMessengerExtensionsTrue = "true"
)
// SubComponentButton type
type SubComponentButton struct {
Title string
Type string
Payload *BotPayload
URL string
WebviewHeightRatio string
WebviewShareButton string
MessengerExtensions string
}
// Execute func
func (c *SubComponentButton) Execute(ctx *BotContext) *messenger.ElmButton {
switch c.Type {
case SubComponentButtonTypePostback:
return c.executePostback(ctx)
case SubComponentButtonTypeWebURL:
return c.executeWebURL(ctx)
}
return nil
}
func (c *SubComponentButton) executePostback(ctx *BotContext) *messenger.ElmButton {
payload := BotPayload{
BlockID: c.Payload.BlockID,
Content: ctx.InterpolateMap(c.Payload.Content),
}
return &messenger.ElmButton{
Type: c.Type,
Title: ctx.Interpolate(c.Title),
Payload: payload.Marshal(),
}
}
func (c *SubComponentButton) executeWebURL(ctx *BotContext) *messenger.ElmButton {
return &messenger.ElmButton{
Type: c.Type,
Title: ctx.Interpolate(c.Title),
URL: ctx.Interpolate(c.URL),
WebviewHeightRatio: ctx.Interpolate(c.WebviewHeightRatio),
WebviewShareButton: ctx.Interpolate(c.WebviewShareButton),
MessengerExtensions: ctx.Interpolate(c.MessengerExtensions),
}
}