almost there

This commit is contained in:
Bilal
2018-01-07 16:39:21 +00:00
parent 9ba9209aa3
commit 675861d2cd

View File

@@ -16,7 +16,7 @@ var ObjectID = require ('mongodb').ObjectID;
const router = express.Router ();
var skillID = 'amzn1.ask.skill.7115bfc9-313e-4728-830b-ebd19ce96cb3';
var skillDbID = '5a232fb86ce046c749739455'; //_id in database
var skillDbID = '5a5016e775becaef2015da10'; //_id in database
var app = express();
@@ -66,18 +66,19 @@ var findElementByAttr = function (data, attr, val){
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');
db.collection('skill_list').findOne({_id: ObjectID(skillDbID)}, (err,skill)=>{
if (skill) {
let intentId = findElementByAttr(skill.intents, 'intentName', alexaRequest.data.request.intent.name);
console.log(alexaRequest.data.request.intent.name);
console.log(intentId);
const response = new alexa.response(alexaRequest.getSession());
if (intentId !== -1){
response.say(skill.intents[intentId].answer);
}else{
response.say('Sorry, I could not find desired intent');
}
}
}
});
}
};