-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
84 lines (70 loc) · 2.58 KB
/
handlers.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
package alexa
import (
"fmt"
"encoding/json"
"github.com/webability-go/alexa/locale"
"github.com/webability-go/alexa/request"
"github.com/webability-go/alexa/response"
)
func DefaultHandler(req request.AlexaRequest) (*response.AlexaResponse, error) {
if DEVEL {
d, _ := json.Marshal(req)
fmt.Println("HANDLER: ", string(d))
}
loc := req.GetLocale()
messages := locale.Get(loc)
requesttype := req.GetRequestType()
fct, ok := HandlerTypeMap[requesttype]
if !ok {
fct, ok = HandlerTypeMap[Fallback]
if !ok {
errormessage := messages.Get("RequestTypeNotFound") + requesttype
if DEVEL {
fmt.Println(errormessage)
}
return response.NewSimpleResponse(messages.Get("ERROR"), errormessage, true), nil
}
}
data, err := fct(req)
if err != nil && ERRORCAPTURE {
return response.NewSimpleResponse(messages.Get("ERROR"), fmt.Sprint(err), true), nil
}
return data, err
}
func DefaultFallbackHandler(req request.AlexaRequest) (*response.AlexaResponse, error) {
loc := req.GetLocale()
messages := locale.Get(loc)
return response.NewSimpleResponse(messages.Get("Fallback.Title"), messages.Get("Fallback.Message"), false), nil
}
func DefaultLaunchHandler(req request.AlexaRequest) (*response.AlexaResponse, error) {
// simulate an error
return nil, fmt.Errorf("Esto es un error simulado de alexa")
loc := req.GetLocale()
messages := locale.Get(loc)
return response.NewSimpleResponse(messages.Get("Launch.Title"), messages.Get("Launch.Message"), false), nil
}
func DefaultSessionEndedHandler(req request.AlexaRequest) (*response.AlexaResponse, error) {
loc := req.GetLocale()
messages := locale.Get(loc)
return response.NewSimpleResponse(messages.Get("SessionEnded.Title"), messages.Get("SessionEnded.Message"), true), nil
}
func DefaultIntentTypeHandler(req request.AlexaRequest) (*response.AlexaResponse, error) {
loc := req.GetLocale()
messages := locale.Get(loc)
var intentname = req.GetRequestIntentName()
fct, ok := HandlerIntentMap[intentname]
if !ok {
fct, ok = HandlerIntentMap[Fallback]
if !ok {
errormessage := messages.Get("IntentNameNotFound") + intentname
fmt.Println(errormessage)
return response.NewSimpleResponse(messages.Get("ERROR"), errormessage, true), nil
}
}
return fct(req)
}
func DefaultIntentHandler(req request.AlexaRequest) (*response.AlexaResponse, error) {
loc := req.GetLocale()
messages := locale.Get(loc)
return response.NewSimpleResponse(messages.Get("Handler.Title"), messages.Get("Handler.Message") + req.GetRequestIntentName(), false), nil
}