from server ; intents working - launch request not working

This commit is contained in:
Bilal
2018-01-08 12:06:25 +00:00
parent 8a59d452f5
commit 51ff7f255c

View File

@@ -62,10 +62,10 @@ alexaApp.express({
app.set("view engine", "ejs"); app.set("view engine", "ejs");
/*
alexaApp.launch(function(request, response) { alexaApp.launch(function(request, response) {
console.log("Alexa launch"); console.log("Alexa launch");
console.log(request); console.log(request);
/*
const skill = db.collection('skill_list').findOne({_id: ObjectID(skillDbID)}, (err,result)=>{ const skill = db.collection('skill_list').findOne({_id: ObjectID(skillDbID)}, (err,result)=>{
if (err){ if (err){
return response.say("I could not find desired skill") return response.say("I could not find desired skill")
@@ -73,8 +73,9 @@ alexaApp.launch(function(request, response) {
return response.say(skill.invocationAnswer); return response.say(skill.invocationAnswer);
} }
}); });
*/
return response.say('Welcome to Saburly');
}); });
*/
var findElementByAttr = function (data, attr, val){ var findElementByAttr = function (data, attr, val){
for(var i = 0; i < data.length; i ++) { for(var i = 0; i < data.length; i ++) {
@@ -105,6 +106,18 @@ alexaApp.request = (jsonRequest) => {
}; };
*/ */
var updateIntentsJSON = function(){
db.collection('skill_list').findOne({_id: ObjectID(skillDbID)}, (err, skill)=>{
if (skill){
skill.intents.map(intent => {
alexaApp.intent(intent.intentName,{'slots':[], 'utterances':intent.questions}, function(request,response){ response.say(intent.answer);});
});
}
});
}
/*
alexaApp.intent("SimpleIntent", { alexaApp.intent("SimpleIntent", {
"slots": [], "slots": [],
"utterances": ["Tell me somethin"] "utterances": ["Tell me somethin"]
@@ -113,6 +126,7 @@ alexaApp.intent("SimpleIntent", {
response.say("This is sample"); response.say("This is sample");
} }
); );
*/
/* /*
alexaApp.error = function(exception, request, response){ alexaApp.error = function(exception, request, response){
@@ -170,6 +184,7 @@ router.post ('/updateSkill/:id', async (req, res, next) => {
if (JSON.parse(result).nModified===1){ if (JSON.parse(result).nModified===1){
//database update ok //database update ok
res.json({result:0, message:'ok'}); res.json({result:0, message:'ok'});
updateIntentsJSON();
}else{ }else{
res.json({result:-1, message:'ok'}); res.json({result:-1, message:'ok'});
} }
@@ -211,6 +226,7 @@ MongoClient.connect (config.dbURL).then (database => {
app.listen (config.PORT, () =>{ app.listen (config.PORT, () =>{
console.log ('Express server running on port ' + config.PORT); console.log ('Express server running on port ' + config.PORT);
updateIntentsJSON();
databaseHelper.loadTokens(); databaseHelper.loadTokens();
}); });
}).catch(e=>{ }).catch(e=>{