-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrequest.go
132 lines (111 loc) · 3.26 KB
/
request.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
package alexa
// constants
// built in intents
const (
//HelpIntent is the Alexa built-in Help Intent
HelpIntent = "AMAZON.HelpIntent"
//CancelIntent is the Alexa built-in Cancel Intent
CancelIntent = "AMAZON.CancelIntent"
//StopIntent is the Alexa built-in Stop Intent
StopIntent = "AMAZON.StopIntent"
)
// locales
const (
// LocaleItalian is the locale for Italian
LocaleItalian = "it-IT"
// LocaleGerman is the locale for standard dialect German
LocaleGerman = "de-DE"
// LocaleAustralianEnglish is the locale for Australian English
LocaleAustralianEnglish = "en-AU"
//LocaleCanadianEnglish is the locale for Canadian English
LocaleCanadianEnglish = "en-CA"
//LocaleBritishEnglish is the locale for UK English
LocaleBritishEnglish = "en-GB"
//LocaleIndianEnglish is the locale for Indian English
LocaleIndianEnglish = "en-IN"
//LocaleAmericanEnglish is the locale for American English
LocaleAmericanEnglish = "en-US"
// LocaleJapanese is the locale for Japanese
LocaleJapanese = "ja-JP"
)
func IsEnglish(locale string) bool {
switch locale {
case LocaleAmericanEnglish:
return true
case LocaleIndianEnglish:
return true
case LocaleBritishEnglish:
return true
case LocaleCanadianEnglish:
return true
case LocaleAustralianEnglish:
return true
default:
return false
}
}
// request
// Request is an Alexa skill request
// see https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#request-format
type Request struct {
Version string `json:"version"`
Session Session `json:"session"`
Body ReqBody `json:"request"`
Context Context `json:"context"`
}
// Session represents the Alexa skill session
type Session struct {
New bool `json:"new"`
SessionID string `json:"sessionId"`
Application struct {
ApplicationID string `json:"applicationId"`
} `json:"application"`
Attributes map[string]interface{} `json:"attributes"`
User struct {
UserID string `json:"userId"`
AccessToken string `json:"accessToken,omitempty"`
} `json:"user"`
}
// Context represents the Alexa skill request context
type Context struct {
System struct {
APIAccessToken string `json:"apiAccessToken"`
Device struct {
DeviceID string `json:"deviceId,omitempty"`
} `json:"device,omitempty"`
Application struct {
ApplicationID string `json:"applicationId,omitempty"`
} `json:"application,omitempty"`
} `json:"System,omitempty"`
}
// ReqBody is the actual request information
type ReqBody struct {
Type string `json:"type"`
RequestID string `json:"requestId"`
Timestamp string `json:"timestamp"`
Locale string `json:"locale"`
Intent Intent `json:"intent,omitempty"`
Reason string `json:"reason,omitempty"`
DialogState string `json:"dialogState,omitempty"`
}
// Intent is the Alexa skill intent
type Intent struct {
Name string `json:"name"`
Slots map[string]Slot `json:"slots"`
}
// Slot is an Alexa skill slot
type Slot struct {
Name string `json:"name"`
Value string `json:"value"`
Resolutions Resolutions `json:"resolutions"`
}
type Resolutions struct {
ResolutionPerAuthority []struct{
Values []struct{
Value struct{
Name string `json:"name"`
Id string `json:"id"`
} `json:"value"`
} `json:"values"`
} `json:"resolutionsPerAuthority"`
}