-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonSkill.go
144 lines (117 loc) · 3.64 KB
/
commonSkill.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package skillgo
// ThumbnailType is Thumbnail template which located in CarouselHeaderType
type ThumbnailType struct {
ImageURL string `json:"imageUrl"`
Link LinkType `json:"link,omitempty"`
FixedRatio bool `json:"fixedRatio,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
}
// Thumbnail creates Thumbnail SkillResponse
func Thumbnail(imageURL string, link LinkType, fixedRatio bool, width int, height int) ThumbnailType {
response := ThumbnailType{}
response.ImageURL = imageURL
response.Link = link
response.FixedRatio = fixedRatio
if fixedRatio {
response.Width = width
response.Height = height
}
return response
}
// LinkType is Link template
type LinkType struct {
PC string `json:"pc,omitempty"`
Mobile string `json:"mobile,omitempty"`
Web string `json:"web,omitempty"`
}
// Link creates Link SkillResponse
func Link(pc string, mobile string, web string) LinkType {
response := LinkType{}
if pc != "" {
response.PC = pc
}
if mobile != "" {
response.Mobile = mobile
}
if web != "" {
response.Web = web
}
return response
}
// ActionConfig represents actions
type ActionConfig struct {
WebLinkURL string `json:"webLinkUrl,omitempty"`
MessageText string `json:"messageText,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
BlockID map[string]interface{} `json:"blockId,omitempty"`
}
// ButtonType is Button Template
type ButtonType struct {
Label string `json:"label"`
Action string `json:"action"`
ActionConfig
}
// Button creates Button SkillResponse
func Button(label string, action string, config ActionConfig) ButtonType {
response := ButtonType{}
response.Label = label
response.Action = action
if action == "webLink" {
response.WebLinkURL = config.WebLinkURL
} else if action == "message" || action == "block" {
response.MessageText = config.MessageText
}
if action == "phone" {
response.PhoneNumber = config.PhoneNumber
} else if action == "block" {
response.BlockID = config.BlockID
}
return response
}
// ProfileType is Profile template
type ProfileType struct {
Nickname string `json:"nickname"`
ImageURL string `json:"imageUrl"`
}
// Profile creates Profile SkillResponse
func Profile(nickname string, imageURL string) ProfileType {
response := ProfileType{}
response.Nickname = nickname
if imageURL != "" {
response.ImageURL = imageURL
}
return response
}
// CarouselHeaderType is CarouselHeader Template which located in Carousel
type CarouselHeaderType struct {
Title string `json:"title"`
Description string `json:"description"`
Thumbnail ThumbnailType `json:"thumbnail"`
}
// CarouselHeader creates CarouselHeader SkillResponse
func CarouselHeader(title string, description string, thumbnail ThumbnailType) CarouselHeaderType {
response := CarouselHeaderType{}
response.Title = title
response.Description = description
response.Thumbnail = thumbnail
return response
}
// QuickRepliesType is QucikReplies Template
type QuickRepliesType struct {
Label string `json:"label"`
Action string `json:"action"`
MessageText string `json:"messageText,omitempty"`
BlockID string `json:"blockId,omitempty"`
Extra interface{} `json:"extra,omitempty"`
}
// QuickReplies creates QuickReplies SkillResponse
func QuickReplies(label string, action string, messageText string, blockID string, extra interface{}) QuickRepliesType {
response := QuickRepliesType{}
response.Label = label
response.Action = action
response.MessageText = messageText
response.BlockID = blockID
response.Extra = extra
return response
}