-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
89 lines (70 loc) · 2.46 KB
/
app.js
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
const SKILL_ID = 'amzn1.ask.skill.3f8e5be1-7582-44bc-868d-ffc2130ede79';
const WELCOME_MSG = ''.concat(
'Welcome to Universal Containers. ',
'Please ask me about the status of your package and include your order id. ',
'For example, Ask Universal Containers about order 12345?'
);
const REPROMPT_TEXT = 'Ask me where your package is by saying Where is order 12345?';
var mysalesforce = require('./mysalesforce');
/**
* Load express/alexa framework
*/
var express = require('express');
var alexa = require('alexa-app');
var PORT = process.env.PORT || 3000;
var app = express();
var alexaApp = new alexa.app("universalcontainers");
alexaApp.express({
expressApp: app,
checkCert: false,
debug: true
})
app.set("view engine", "jade");
/**
* pre Handler
* Executed before any event handlers. This is useful to setup new sessions, validate the applicationId, or do any other kind of validations.
*/
alexaApp.pre = function(request, response, type) {
if (request.applicationId != SKILL_ID) {
console.log('request.applicationId is: ' + request.applicationId);
console.log('SKILL_ID is: ' + SKILL_ID);
// fail ungracefully
response.fail("Invalid applicationId");
}
};
/**
* Launch Handler
*/
alexaApp.launch(function(request, response) {
response.say(WELCOME_MSG);
response.card("Universal Containers", WELCOME_MSG);
});
/**
* Order Tracking Intent
*/
alexaApp.intent("OrderTrackingIntent", {
"slots": {
"OrderId": "AMAZON.NUMBER"
},
"utterances": [
"for status on order number {OrderId}",
"about {OrderId}"
]
},
function(request, response) {
response.reprompt("I didn't hear a valid order number. Please ask something like 'What is the status of order number 100?'");
return mysalesforce.getOrderStatus(request.slot('OrderId')).then(function(output) {
response.say(output.say);
response.card(output.card);
});
});
alexaApp.intent("AMAZON.HelpIntent", {}, function(request, response) {
response.say("Here's some help. Try saying 'Ask Universal Containers for status on order 100'");
response.card({
type: "Simple",
title: "Universal Containers",
content: "Valid syntax:\nAsk Universal Containers about 100\nAsk Universal Containers for status on order 100"
});
});
app.listen(PORT);
console.log("Listening on port " + PORT + ", try http://localhost:" + PORT + "/universalcontainers");