forked from arienmalec/alexa-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectives.go
64 lines (57 loc) · 2 KB
/
directives.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
package alexa
import "strings"
// DirectiveType represents confirmvarious Directive Types
type DirectiveType int
const (
// DirectiveTypeUndefined means incoming value incorrect or not supported
DirectiveTypeUndefined DirectiveType = iota
// DirectiveTypeDialogDelegate is constant `Dialog.Delegate`
DirectiveTypeDialogDelegate
// DirectiveTypeDialogElicitSlot is constant `Dialog.ElicitSlot`
DirectiveTypeDialogElicitSlot
// DirectiveTypeDialogConfirmSlot is constant `Dialog.ConfirmSlot`
DirectiveTypeDialogConfirmSlot
// DirectiveTypeDialogConfirmIntent is constant `Dialog.ConfirmIntent`
DirectiveTypeDialogConfirmIntent
)
// directiveTypeStrings for use outside this module
var directiveTypeStrings = [...]string{
"Undefined", // Placeholder - should never be this
"Dialog.Delegate",
"Dialog.ElicitSlot",
"Dialog.ConfirmSlot",
"Dialog.ConfirmIntent",
}
// Directives is imformation
type Directives struct {
Type DirectiveType `json:"type,omitempty"`
SlotToElicit string `json:"slotToElicit,omitempty"`
UpdatedIntent *UpdatedIntent `json:"UpdatedIntent,omitempty"`
PlayBehavior string `json:"playBehavior,omitempty"`
AudioItem struct {
Stream struct {
Token string `json:"token,omitempty"`
URL string `json:"url,omitempty"`
OffsetInMilliseconds int `json:"offsetInMilliseconds,omitempty"`
} `json:"stream,omitempty"`
} `json:"audioItem,omitempty"`
}
// MarshalJSON Function to handle JSON parsing out
func (d DirectiveType) MarshalJSON() ([]byte, error) {
j := string(`"` + directiveTypeStrings[d] + `"`)
return []byte(j), nil
}
// UnmarshalJSON Function to handle JSON parsing out
func (d *DirectiveType) UnmarshalJSON(data []byte) error {
dt := DirectiveTypeUndefined
// Convert to string whilst removing quotes
x := string(data)[1 : len(data)-1]
// Find the type in the range of values
for i, s := range directiveTypeStrings {
if strings.ToLower(s) == strings.ToLower(x) {
dt = DirectiveType(i)
}
}
*d = dt
return nil
}