-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponse.go
189 lines (170 loc) · 4.46 KB
/
response.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package alexa
type Response struct {
Version string `json:"version"`
SessionAttributes map[string]interface{} `json:"sessionAttributes,omitempty"`
ResponseBody responseBody `json:"response"`
}
type responseBody struct {
OutputSpeech outputSpeech `json:"outputSpeech,omitempty"`
Card card `json:"card,omitempty"`
Reprompt outputSpeech `json:"reprompt,omitempty"`
ShouldEndSession bool `json:"shouldEndSession,omitempty"`
Directives []Directive `json:"directives,omitempty"`
}
type outputSpeech struct {
Type string `json:"type"`
Text string `json:"text"`
SSML string `json:"ssml"`
}
type card struct {
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Content string `json:"content,omitempty"`
Text string `json:"text,omitempty"`
Image cardImage `json:"image,omitempty"`
}
type cardImage struct {
SmallImageUrl string `json:"smallImageUrl,omitempty"`
LargeImageUrl string `json:"largeImageUrl,omitempty"`
}
type Directive struct {
Type string `json:"type,omitempty"`
Template Template `json:"template,omitempty"`
}
type Template struct {
Type string `json:"type,omitempty"`
Token string `json:"token,omitempty"`
BackButton string `json:"backButton,omitempty"`
BackgroundImage string `json:"backgroundImage,omitempty"`
Title string `json:"title,omitempty"`
TextContent TextContent `json:"textContent,omitempty"`
}
type TextContent struct {
PrimaryText PrimaryText `json:"primaryText,omitempty"`
SecondaryText SecondaryText `json:"secondaryText,omitempty"`
TertiaryText TertiaryText `json:"tertiaryText,omitempty"`
}
type PrimaryText struct {
Text string `json:"text,omitempty"`
Type string `json:"type,omitempty"`
}
type SecondaryText struct {
Text string `json:"text,omitempty"`
Type string `json:"type,omitempty"`
}
type TertiaryText struct {
Text string `json:"text,omitempty"`
Type string `json:"type,omitempty"`
}
type responder interface {
newResponse() *Response
}
type SimpleResponse struct {
OutputSpeechText string
CardTitle string
CardContent string
}
type StandardResponse struct {
OutputSpeechText string
CardTitle string
CardText string
CardImage struct {
SmallImageUrl string
LargeImageUrl string
}
}
type DisplayResponse struct {
OutputSpeechText string
CardTitle string
CardContent string
Directives []Directive
}
type LinkAccountResponse struct {
OutputSpeechText string
}
func (res *SimpleResponse) newResponse() *Response {
return &Response{
Version: "1.0",
ResponseBody: responseBody{
OutputSpeech: outputSpeech{
Type: "PlainText",
Text: res.OutputSpeechText,
},
Card: card{
Type: "Simple",
Title: res.CardTitle,
Content: res.CardContent,
},
ShouldEndSession: true,
},
}
}
func (res *StandardResponse) newResponse() *Response {
return &Response{
Version: "1.0",
ResponseBody: responseBody{
OutputSpeech: outputSpeech{
Type: "PlainText",
Text: res.OutputSpeechText,
},
Card: card{
Type: "Standard",
Title: res.CardTitle,
Text: res.CardText,
Image: cardImage{
SmallImageUrl: res.CardImage.SmallImageUrl,
LargeImageUrl: res.CardImage.LargeImageUrl,
},
},
ShouldEndSession: true,
},
}
}
func (res *DisplayResponse) newResponse() *Response {
resp := &Response{
Version: "1.0",
ResponseBody: responseBody{
OutputSpeech: outputSpeech{
Type: "PlainText",
Text: res.OutputSpeechText,
},
Card: card{
Type: "Simple",
Title: res.CardTitle,
Content: res.CardContent,
},
Directives: []Directive{
Directive{
Type: "Display.RenderTemplate",
Template: Template{
Type: "BodyTemplate1",
Token: res.Directives[0].Template.Token,
BackButton: res.Directives[0].Template.BackButton,
Title: res.Directives[0].Template.Title,
TextContent: res.Directives[0].Template.TextContent,
},
},
},
ShouldEndSession: true,
},
}
return resp
}
func (res *LinkAccountResponse) newResponse() *Response {
return &Response{
Version: "1.0",
ResponseBody: responseBody{
OutputSpeech: outputSpeech{
Type: "PlainText",
Text: res.OutputSpeechText,
},
Card: card{
Type: "LinkAccount",
},
ShouldEndSession: true,
},
}
}
func NewResponse(r responder) *Response {
return r.newResponse()
}