diff --git a/backend/express.js b/backend/express.js index 252e564..3c2fe22 100644 --- a/backend/express.js +++ b/backend/express.js @@ -79,21 +79,22 @@ alexaApp.express({ // 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."); +alexaApp.request = (jsonRequest) => { + const alexaRequest = new alexa.request(jsonRequest); + if (alexaRequest.type() === "IntentRequest") { + const intent = db.collection('intent_list').findOne({ + name: alexaRequest.data.request.intent.name + }); + if (intent) { + const response = new alexa.response(alexaRequest.getSession()); + return response.say(intent.answer); + } } -); +}; app.use (function (req, res, next) { res.header ('Access-Control-Allow-Origin', '*'); diff --git a/backend/lambda.js b/backend/lambda.js deleted file mode 100644 index 35bd0c5..0000000 --- a/backend/lambda.js +++ /dev/null @@ -1,14 +0,0 @@ -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/backend/template.js b/backend/template.js deleted file mode 100644 index 66f536a..0000000 --- a/backend/template.js +++ /dev/null @@ -1,116 +0,0 @@ -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/backend/test.js b/backend/test.js deleted file mode 100644 index ef4e7c5..0000000 --- a/backend/test.js +++ /dev/null @@ -1,79 +0,0 @@ -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/backend/views/test.ejs b/backend/views/test.ejs deleted file mode 100644 index a84c9fe..0000000 --- a/backend/views/test.ejs +++ /dev/null @@ -1,10 +0,0 @@ -
-Schema: - -<%=schema%> - -Utterances: - -<%=utterances%> - -
\ No newline at end of file diff --git a/web/package.json b/web/package.json index 03a03fe..12756dc 100644 --- a/web/package.json +++ b/web/package.json @@ -13,4 +13,4 @@ "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } -} \ No newline at end of file +}