test #1
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
node_modules
|
||||||
43
express.js
Normal file
43
express.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
var express = require("express");
|
||||||
|
var alexa = require("alexa-app");
|
||||||
|
|
||||||
|
var PORT = process.env.port || 5000;
|
||||||
|
var app = express();
|
||||||
|
|
||||||
|
// ALWAYS setup the alexa app and attach it to express before anything else.
|
||||||
|
var alexaApp = new alexa.app("step1");
|
||||||
|
|
||||||
|
alexaApp.express({
|
||||||
|
expressApp: app,
|
||||||
|
|
||||||
|
// verifies requests come from amazon alexa. Must be enabled for production.
|
||||||
|
// You can disable this if you're running a dev environment and want to POST
|
||||||
|
// things to test behavior. enabled by default.
|
||||||
|
checkCert: false,
|
||||||
|
|
||||||
|
// sets up a GET route when set to true. This is handy for testing in
|
||||||
|
// development, but not recommended for production. disabled by default
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// now POST calls to /test in express will be handled by the app.request() function
|
||||||
|
|
||||||
|
// from here on you can setup any other express routes or middlewares as normal
|
||||||
|
app.set("view engine", "ejs");
|
||||||
|
|
||||||
|
alexaApp.launch(function(request, response) {
|
||||||
|
response.say("You launched Saburly app!");
|
||||||
|
});
|
||||||
|
|
||||||
|
alexaApp.intent("GetProcessIntent", {
|
||||||
|
"utterances": [
|
||||||
|
"tell me about projects", "say something about your project", "what are your projects"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
function(request, response) {
|
||||||
|
response.say("We collaborate closely with our clients at each step of the developmentprocess. From designing the UX to developing the front-end andarchitecting the back-end.");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
app.listen(PORT);
|
||||||
|
console.log("Listening on port " + PORT + ", try http://localhost:" + PORT + "/test");
|
||||||
14
lambda.js
Normal file
14
lambda.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
var alexa = require("alexa-app");
|
||||||
|
var find = require("find-my-iphone");
|
||||||
|
|
||||||
|
var app = new alexa.app();
|
||||||
|
app.launch(function(request, response) {
|
||||||
|
find("me@icloud.com", "mypassword", "iPhone", function() {
|
||||||
|
response.say("OK").send();
|
||||||
|
});
|
||||||
|
// because this is an async handler
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// connect to lambda
|
||||||
|
exports.handler = app.lambda();
|
||||||
14
package.json
Normal file
14
package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "example",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "test.js",
|
||||||
|
"dependencies": {
|
||||||
|
"body-parser": "^1.13.1",
|
||||||
|
"ejs": "^2.3.1",
|
||||||
|
"express": "^4.13.0",
|
||||||
|
"alexa-app": "4.2.0"
|
||||||
|
},
|
||||||
|
"author": "Matt Kruse <github@mattkruse.com> (http://mattkruse.com/)",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
116
template.js
Normal file
116
template.js
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
var template = {};
|
||||||
|
// LaunchRequest template
|
||||||
|
template.launch = {
|
||||||
|
"version": "1.0",
|
||||||
|
"session": {
|
||||||
|
"new": true,
|
||||||
|
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
|
||||||
|
"attributes": {},
|
||||||
|
"application": {
|
||||||
|
"applicationId": "amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3"
|
||||||
|
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"type": "LaunchRequest",
|
||||||
|
"requestId": "amzn1.echo-api.request.9cdaa4db-f20e-4c58-8d01-c75322d6c423"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// IntentRequest template
|
||||||
|
template.intent = {
|
||||||
|
"version": "1.0",
|
||||||
|
"session": {
|
||||||
|
"new": false,
|
||||||
|
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
|
||||||
|
"attributes": {},
|
||||||
|
"application": {
|
||||||
|
"applicationId": "amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"type": "IntentRequest",
|
||||||
|
"requestId": "amzn1.echo-api.request.6919844a-733e-4e89-893a-fdcb77e2ef0d",
|
||||||
|
"intent": {
|
||||||
|
"name": "sampleIntent",
|
||||||
|
"slots": {
|
||||||
|
"NAME": {
|
||||||
|
"name": "NAME",
|
||||||
|
"value": "Matt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// errorIntent template
|
||||||
|
template.errorIntent = {
|
||||||
|
"version": "1.0",
|
||||||
|
"session": {
|
||||||
|
"new": false,
|
||||||
|
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
|
||||||
|
"attributes": {},
|
||||||
|
"application": {
|
||||||
|
"applicationId": "amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"type": "IntentRequest",
|
||||||
|
"requestId": "amzn1.echo-api.request.6919844a-733e-4e89-893a-fdcb77e2ef0d",
|
||||||
|
"intent": {
|
||||||
|
"name": "errorIntent",
|
||||||
|
"slots": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// missingIntent template
|
||||||
|
template.missingIntent = {
|
||||||
|
"version": "1.0",
|
||||||
|
"session": {
|
||||||
|
"new": false,
|
||||||
|
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
|
||||||
|
"attributes": {},
|
||||||
|
"application": {
|
||||||
|
"applicationId": "amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"type": "IntentRequest",
|
||||||
|
"requestId": "amzn1.echo-api.request.6919844a-733e-4e89-893a-fdcb77e2ef0d",
|
||||||
|
"intent": {
|
||||||
|
"name": "missingIntent",
|
||||||
|
"slots": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// SessionEndedRequest template
|
||||||
|
template.session_end = {
|
||||||
|
"version": "1.0",
|
||||||
|
"session": {
|
||||||
|
"new": false,
|
||||||
|
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
|
||||||
|
"attributes": {},
|
||||||
|
"application": {
|
||||||
|
"applicationId": "amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"type": "SessionEndedRequest",
|
||||||
|
"requestId": "amzn1.echo-api.request.d8c37cd6-0e1c-458e-8877-5bb4160bf1e1",
|
||||||
|
"reason": "USER_INITIATED"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = template;
|
||||||
79
test.js
Normal file
79
test.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
var alexa = require("alexa-app");
|
||||||
|
var template = require("./template.js");
|
||||||
|
|
||||||
|
var app = new alexa.app("test");
|
||||||
|
|
||||||
|
app.dictionary = {
|
||||||
|
"names": ["Bob", "Jack", "Matt", "Mary", "Jane", "Bill"]
|
||||||
|
};
|
||||||
|
|
||||||
|
app.launch(function(request, response) {
|
||||||
|
response.say("App launched!");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.intent("sampleIntent", {
|
||||||
|
"slots": { "NAME": "LITERAL", "AGE": "NUMBER" },
|
||||||
|
"utterances": ["my {name is|name's} {names|NAME} and {I am|I'm} {1-100|AGE}{ years old|}"]
|
||||||
|
},
|
||||||
|
function(request, response) {
|
||||||
|
setTimeout(function() {
|
||||||
|
response.say("After timeout!").say(" test ").reprompt("Reprompt");
|
||||||
|
response.send();
|
||||||
|
}, 1000);
|
||||||
|
// We are async!
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
app.intent("errorIntent", function(request, response) {
|
||||||
|
response.say(someVariableThatDoesntExist);
|
||||||
|
});
|
||||||
|
|
||||||
|
// output the schema
|
||||||
|
console.log("\n\nSCHEMA:\n\n" + app.schema() + "\n\n");
|
||||||
|
// output sample utterances
|
||||||
|
console.log("\n\nUTTERANCES:\n\n" + app.utterances() + "\n\n");
|
||||||
|
|
||||||
|
// test pre() and post() functions
|
||||||
|
app.pre = function(request, response, type) {
|
||||||
|
response.say("This part of the output is from pre(). ");
|
||||||
|
};
|
||||||
|
app.post = function(request, response, type, exception) {
|
||||||
|
if (exception) {
|
||||||
|
response.clear().say("An error occured: " + exception).send();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// error example
|
||||||
|
app.request(template.errorIntent)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(JSON.stringify(response, null, 3));
|
||||||
|
});
|
||||||
|
|
||||||
|
// async example
|
||||||
|
app.request(template.intent)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(JSON.stringify(response, null, 3));
|
||||||
|
});
|
||||||
|
|
||||||
|
// synchronous example
|
||||||
|
app.request(template.launch)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(JSON.stringify(response, null, 3));
|
||||||
|
});
|
||||||
|
|
||||||
|
// error example
|
||||||
|
app.messages.NO_INTENT_FOUND = "Why you called dat intent? I don't know bout dat";
|
||||||
|
app.request(template.missingIntent)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(JSON.stringify(response, null, 3));
|
||||||
|
});
|
||||||
|
|
||||||
|
// error handler example
|
||||||
|
app.error = function(e, request, response) {
|
||||||
|
response.say("I captured the exception! It was: " + e.message);
|
||||||
|
};
|
||||||
|
app.request(template.errorIntent)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log(JSON.stringify(response, null, 3));
|
||||||
|
});
|
||||||
10
views/test.ejs
Normal file
10
views/test.ejs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<div style="white-space:pre;border:1px solid black;margin:5px;padding:5px;font-family:monospace;">
|
||||||
|
Schema:
|
||||||
|
|
||||||
|
<%=schema%>
|
||||||
|
|
||||||
|
Utterances:
|
||||||
|
|
||||||
|
<%=utterances%>
|
||||||
|
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user