-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathresponse.go
140 lines (113 loc) · 2.93 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
package golexa
const (
OUTPUT_SPEECH_TYPE_PLAIN = "PlainText"
OUTPUT_SPEECH_TYPE_SSML = "SSML"
CARD_TYPE_SIMPLE = "Simple"
CARD_TYPE_STANDARD = "Standard"
CARD_TYPE_LINK_ACCOUNT = "LinkAccount"
)
func newEmptyResponse() *Response {
return &Response{
Version: "1.0",
Response: innerResponse{
ShouldEndSession: true,
OutputSpeech: nil,
},
}
}
type Response struct {
Version string `json:"version"`
SessionAttributes SessionAttributes `json:"sessionAttributes,omitempty"`
Response innerResponse `json:"response"`
}
type innerResponse struct {
OutputSpeech *OutputSpeech `json:"outputSpeech,omitempty"`
Card *Card `json:"card,omitempty"`
Reprompt *Reprompt `json:"reprompt,omitempty"`
ShouldEndSession bool `json:"shouldEndSession"`
}
type OutputSpeech struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
SSML string `json:"ssml,omitempty"`
}
type Card struct {
Type string `json:"type"`
Title string `json:"title,omitempty"`
Content string `json:"content,omitempty"`
Text string `json:"text,omitempty"`
ImageUrls *imageUrls `json:"image,omitempty"`
}
type imageUrls struct {
SmallImageUrl string `json:"smallImageUrl"`
LargeImageUrl string `json:"largeImageUrl"`
}
type Reprompt struct {
OutputSpeech OutputSpeech `json:"outputSpeech,omitempty"`
}
func (r *Response) AddPlainTextSpeech(text string) *Response {
r.Response.OutputSpeech = &OutputSpeech{
Type: OUTPUT_SPEECH_TYPE_PLAIN,
Text: text,
}
return r
}
func (r *Response) AddSSMLSpeech(ssml string) *Response {
r.Response.OutputSpeech = &OutputSpeech{
Type: OUTPUT_SPEECH_TYPE_SSML,
SSML: ssml,
}
return r
}
func (r *Response) AddSimpleCard(title, content string) *Response {
r.Response.Card = &Card{
Type: CARD_TYPE_SIMPLE,
Title: title,
Content: content,
}
return r
}
func (r *Response) AddStandardCard(title, text, smallImageUrl, largeImageUrl string) *Response {
r.Response.Card = &Card{
Type: CARD_TYPE_STANDARD,
Title: title,
Text: text,
ImageUrls: &imageUrls{
SmallImageUrl: smallImageUrl,
LargeImageUrl: largeImageUrl,
},
}
return r
}
func (r *Response) AddLinkAccountCard() *Response {
r.Response.Card = &Card{
Type: CARD_TYPE_LINK_ACCOUNT,
}
return r
}
func (r *Response) AddPlainTextReprompt(text string) *Response {
r.Response.Reprompt = &Reprompt{
OutputSpeech: OutputSpeech{
Type: OUTPUT_SPEECH_TYPE_PLAIN,
Text: text,
},
}
return r
}
func (r *Response) AddSSMLReprompt(ssml string) *Response {
r.Response.Reprompt = &Reprompt{
OutputSpeech: OutputSpeech{
Type: OUTPUT_SPEECH_TYPE_SSML,
SSML: ssml,
},
}
return r
}
func (r *Response) AddSessionAttributes(attributes SessionAttributes) *Response {
r.SessionAttributes = attributes
return r
}
func (r *Response) KeepSessionAlive() *Response {
r.Response.ShouldEndSession = false
return r
}