hande unknown questions
This commit is contained in:
@@ -26,6 +26,11 @@ constants.HTTPResultCodes = {
|
|||||||
|
|
||||||
constants.SKILL_ID_LENGTH = 24;
|
constants.SKILL_ID_LENGTH = 24;
|
||||||
|
|
||||||
|
constants.voiceResponseStrings = {
|
||||||
|
QUESTION_NOT_FOUND : 'Sorry, I didnt understan',
|
||||||
|
GENERIC_CONTINUE : 'Would you like to continue'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = constants;
|
module.exports = constants;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
var Alexa = require ('alexa-sdk');
|
var Alexa = require ('alexa-sdk');
|
||||||
const config = require ('../config/config');
|
const config = require ('../config/config');
|
||||||
var databaseHelper = require ('../helpers/database');
|
var databaseHelper = require ('../helpers/database');
|
||||||
|
const constants = require ('../config/constants');
|
||||||
|
|
||||||
var handlers = {};
|
var handlers = {};
|
||||||
|
|
||||||
@@ -24,31 +25,47 @@ module.exports = {
|
|||||||
alexa.execute ();
|
alexa.execute ();
|
||||||
},
|
},
|
||||||
updateModel: function () {
|
updateModel: function () {
|
||||||
//TODO : Alexa-sdk has handlers like SessionEndedRequest, Unhandled ,... that can be used
|
|
||||||
|
|
||||||
//Get info from database, and store it for faster response on intent
|
//Get info from database, and store it for faster response on intent
|
||||||
databaseHelper
|
databaseHelper
|
||||||
.getSkill (config.SKILL_DB_ID)
|
.getSkill (config.SKILL_DB_ID)
|
||||||
.then (activeSkill => {
|
.then (activeSkill => {
|
||||||
handlers = {};
|
handlers = {};
|
||||||
|
|
||||||
|
//Handler for launch request
|
||||||
handlers = {
|
handlers = {
|
||||||
LaunchRequest: function () {
|
LaunchRequest: function () {
|
||||||
this.response
|
this.response
|
||||||
.speak (activeSkill.invocationAnswer)
|
.speak (activeSkill.invocationAnswer)
|
||||||
.listen (' Would you like to continue ?');
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||||
//TODO : Maybe to ask user does he want to hear possible intents
|
//TODO : Maybe to ask user does he want to hear possible intents
|
||||||
//For this functionality, we need explanation text for each intent (Question)
|
//For this functionality, we need explanation text for each intent (Question)
|
||||||
this.emit (':responseReady');
|
this.emit (':responseReady');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Handlers for user defined questions
|
||||||
activeSkill.intents.map (intent => {
|
activeSkill.intents.map (intent => {
|
||||||
handlers[intent.intentName] = function () {
|
handlers[intent.intentName] = function () {
|
||||||
this.response
|
this.response
|
||||||
.speak (intent.answer)
|
.speak (intent.answer)
|
||||||
.listen ('Would you like to continue ?');
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||||
this.emit (':responseReady');
|
this.emit (':responseReady');
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Default handlers for unknown questions and session close
|
||||||
|
|
||||||
|
handlers.Unhandled = function () {
|
||||||
|
this.response
|
||||||
|
.speak (constants.voiceResponseStrings.QUESTION_NOT_FOUND)
|
||||||
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
handlers.SessionEndedRequest = function(){
|
||||||
|
//We don't care for now
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch (e => {
|
.catch (e => {
|
||||||
//Something is wrong, skill is not ready, use catch-all intent to inform user
|
//Something is wrong, skill is not ready, use catch-all intent to inform user
|
||||||
|
|||||||
Reference in New Issue
Block a user