From 9652645339b561c64147984c238a90b4b04bbc5d Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 4 Dec 2017 12:18:05 +0100 Subject: [PATCH] fix --- backend/SaburlySkillInteractionModel.json | 60 +++++++++++++++++++++++ backend/express.js | 46 ++++++++++++++--- 2 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 backend/SaburlySkillInteractionModel.json diff --git a/backend/SaburlySkillInteractionModel.json b/backend/SaburlySkillInteractionModel.json new file mode 100644 index 0000000..ff9fdd7 --- /dev/null +++ b/backend/SaburlySkillInteractionModel.json @@ -0,0 +1,60 @@ +{ + "languageModel": { + "intents": [ + { + "name": "AMAZON.CancelIntent", + "samples": [] + }, + { + "name": "AMAZON.HelpIntent", + "samples": [] + }, + { + "name": "AMAZON.StopIntent", + "samples": [] + }, + { + "name": "GetProcessIntent", + "samples": [ + "tell me your process", + "what is your process", + "how do you work", + "about your proces" + ], + "slots": [] + }, + { + "name": "GetProjectsIntent", + "samples": [ + "list me your projects", + "show me what you have done", + "what did you do so far", + "what are your projects", + "your project" + ], + "slots": [] + }, + { + "name": "GetServicesIntent", + "samples": [ + "what are your services", + "what services do you ofer", + "what you do", + "your service", + "tell me service" + ], + "slots": [] + }, + { + "name": "GetTechnologiesIntent", + "samples": [ + "list me your technologies", + "give me your technologies", + "what you know" + ], + "slots": [] + } + ], + "invocationName": "saburly" + } +} \ No newline at end of file diff --git a/backend/express.js b/backend/express.js index 6e2bc7e..29e89b2 100644 --- a/backend/express.js +++ b/backend/express.js @@ -12,8 +12,6 @@ const PORT = 5000; const TOKEN = 'Atza|IwEBIMv0spn-eZhjP8-R2Jjkb4VUi-EY4V3MX-wlJyr2P6YBUmIChl7VKgRberEdQ-Wolp53SqfwHbxlSo4-rdUgFYFAxImB622boeqUBBCtwybP0OTBJBT1CVm_FBr48Li5LkwR9DxPciCnc052ddohpjGuGZxsCqIJo2c-7LPEhH0Lx63VOFgfPIfBsrVqjDbPNrr5ApPUijKYZWurktb6ytTks8eFUSTyv3FDbE5HEng0qpE4mgSjdgBkEc8BgUfpm2QGvctINH9SioUJOJonxgTPYhbD4BEd-jdQHsltKFzkb3-Rm3lFhEu3_CQFxCeQ6yGe1the_qID3vnPfpSY6hyblgF5L_5d7bE7BWg8fm6rSwXv67L2sMwBOji6cuR0wVVvXfYxmgGIMGkVQrq-SPSdtCpx2BvBz2SqqN6a_98svP8ukvhwc_oJsN6VwEmTDFgutNf-XuGkuVii-k9-DncwuwD00LvJG1FhBvbvSyuv-a3LAJSqTmroemTDG0xzLn7ULFY5p-93sM0_ZNGFeW-lL_r1ldqM_5lFRKDta1Tkg7lT9-rHftgnpGs4zv7vGLIPzHpNiXjsKyCk-wMQrihhWlR15kiz7oKDeTf6wCIETg'; const USER_ID = 'amzn1.ask.account.AGE34MG3VIQ75D4Q5CXFK25GUOXHZ2MIVSII3QUCOT3CP44IPE25PLD3DWW7HLWO2KVC7PC7VUXSZZEFPVHJ6PTDYVYYESJE35CE6VEXCE3BI3AK24TGO4CJXFF3SZ7IA4QVJRZC6EN4MUF2WUP4IB4CGDLRZZMYQENOFNBYWFXZHMZ5PA6S6ERK7NGEPUSDHXWKH26UGMIATMI'; - - var MongoClient = require ('mongodb').MongoClient; var ObjectID = require ('mongodb').ObjectID; @@ -43,7 +41,6 @@ router.get ('/getSkill/:id', async (req, res, next) => { } }); - router.get ('/deleteSkill/:skillID', async (req, res, next) => { try { let id = req.params.id; @@ -94,13 +91,13 @@ router.post ('/updateSkill/:id', async (req, res, next) => { } }); - - +var skillID = 'amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3'; +var skillDbID = '5a232fb86ce046c749739455'; //_id in database var app = express(); // ALWAYS setup the alexa app and attach it to express before anything else. -var alexaApp = new alexa.app('step3'); +var alexaApp = new alexa.app('step3'); // this means we still work with one skill alexaApp.express({ expressApp: app, @@ -119,6 +116,43 @@ alexaApp.express({ // from here on you can setup any other express routes or middlewares as normal +alexaApp.launch(function(request, response) { + const skill = db.collection('skill_list').findOne({_id: ObjectID(skillDbID)}, (err,result)=>{ + if (err){ + response.say("I could not find desired skill") + }else{ + response.say(skill.invocationAnswer); + } + }); +}); + +var findElementByAttr = function (data, attr, val){ + for(var i = 0; i < data.length; i ++) { + if(data[i][attr] === val) { + return i; + } + } + return -1; +} + +alexaApp.request = (jsonRequest) => { + const alexaRequest = new alexa.request(jsonRequest); + if (alexaRequest.type() === "IntentRequest") { + const skill = db.collection('skill_list').findOne({ + _id: skillDbID + }); + if (skill) { + let intentId = findElementByAttr(skill.intents, 'intentName', alexaRequest.data.request.intent.name); + const response = new alexa.response(alexaRequest.getSession()); + if (intentId !== -1){ + return response.say(skill.intents[intentId].answer); + }else{ + return response.say('Sorry, I could not find desired intent'); + } + } + } +}; + app.use (function (req, res, next) { res.header ('Access-Control-Allow-Origin', '*'); res.header (