commit 86072a3279397fc7d5ca174064d66a82b794f1e8 Author: GotPPay Date: Tue Nov 28 14:36:59 2017 +0100 test #1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/express.js b/express.js new file mode 100644 index 0000000..a09be00 --- /dev/null +++ b/express.js @@ -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"); diff --git a/lambda.js b/lambda.js new file mode 100644 index 0000000..35bd0c5 --- /dev/null +++ b/lambda.js @@ -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(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..de51119 --- /dev/null +++ b/package.json @@ -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 (http://mattkruse.com/)", + "license": "MIT" +} diff --git a/template.js b/template.js new file mode 100644 index 0000000..66f536a --- /dev/null +++ b/template.js @@ -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; diff --git a/test.js b/test.js new file mode 100644 index 0000000..ef4e7c5 --- /dev/null +++ b/test.js @@ -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)); + }); diff --git a/views/test.ejs b/views/test.ejs new file mode 100644 index 0000000..a84c9fe --- /dev/null +++ b/views/test.ejs @@ -0,0 +1,10 @@ +
+Schema: + +<%=schema%> + +Utterances: + +<%=utterances%> + +
\ No newline at end of file