Merge pull request #13 from GotPPay/implement-built-in-intents
Implement built in intents
This commit is contained in:
@@ -28,7 +28,8 @@ constants.SKILL_ID_LENGTH = 24;
|
|||||||
|
|
||||||
constants.voiceResponseStrings = {
|
constants.voiceResponseStrings = {
|
||||||
QUESTION_NOT_FOUND : 'Sorry, I didnt understand',
|
QUESTION_NOT_FOUND : 'Sorry, I didnt understand',
|
||||||
GENERIC_CONTINUE : 'Would you like to continue'
|
GENERIC_CONTINUE : 'Say something to continue',
|
||||||
|
DIDNT_ASK_ANYTHING : 'There was no question to answer to',
|
||||||
}
|
}
|
||||||
|
|
||||||
//Timing is given in [ms]
|
//Timing is given in [ms]
|
||||||
|
|||||||
@@ -68,6 +68,34 @@ var generateInteractionModel = function (skill) {
|
|||||||
allIntents.push ({name: intent.intentName, samples: intent.questions});
|
allIntents.push ({name: intent.intentName, samples: intent.questions});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Built-In like intents (Amazon built-in don't work, probably something related to existance of dialog intent
|
||||||
|
|
||||||
|
allIntents.push ({
|
||||||
|
name: 'HelpIntent',
|
||||||
|
samples: ['Help', 'Can you help me', 'I need help'],
|
||||||
|
slots: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'CancelIntent',
|
||||||
|
samples: ['Cancel', 'Stop', 'Please stop'],
|
||||||
|
slots: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'YesIntent',
|
||||||
|
samples: [
|
||||||
|
'Yes',
|
||||||
|
'Yes please',
|
||||||
|
'I would like that',
|
||||||
|
'Yes I would like that',
|
||||||
|
],
|
||||||
|
slots: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'NoIntent',
|
||||||
|
samples: ['No', 'No thank you'],
|
||||||
|
slots: [],
|
||||||
|
});
|
||||||
|
|
||||||
//Special intent for sending message (Dialog)
|
//Special intent for sending message (Dialog)
|
||||||
|
|
||||||
allIntents.push ({
|
allIntents.push ({
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ module.exports = {
|
|||||||
destinationEmail = activeSkill.contactEmail;
|
destinationEmail = activeSkill.contactEmail;
|
||||||
|
|
||||||
let listOfPossibleQuestions = '';
|
let listOfPossibleQuestions = '';
|
||||||
activeSkill.intents.forEach(intent => {
|
activeSkill.intents.forEach (intent => {
|
||||||
if (intent.questions.length > 0 && intent.intentExplanation) {
|
if (intent.questions.length > 0 && intent.intentExplanation) {
|
||||||
listOfPossibleQuestions +=
|
listOfPossibleQuestions +=
|
||||||
intent.intentExplanation +
|
intent.intentExplanation +
|
||||||
@@ -44,8 +44,7 @@ module.exports = {
|
|||||||
'ms"/>';
|
'ms"/>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
listOfPossibleQuestions += 'If you dont know what to do, just say help or stop';
|
||||||
console.log(listOfPossibleQuestions);
|
|
||||||
|
|
||||||
//Handler for launch requestconsole.log()
|
//Handler for launch requestconsole.log()
|
||||||
handlers = {
|
handlers = {
|
||||||
@@ -56,9 +55,10 @@ module.exports = {
|
|||||||
'<break time="' +
|
'<break time="' +
|
||||||
constants.voiceResponseTimings.PAUSE_AFTER_WELCOME_MESSAGE +
|
constants.voiceResponseTimings.PAUSE_AFTER_WELCOME_MESSAGE +
|
||||||
'ms"/>' +
|
'ms"/>' +
|
||||||
listOfPossibleQuestions
|
'Would you like to hear list of questions that you can ask me'
|
||||||
)
|
)
|
||||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||||
|
this.attributes['LaunchRequestYesNo'] = true;
|
||||||
this.emit (':responseReady');
|
this.emit (':responseReady');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -66,6 +66,9 @@ module.exports = {
|
|||||||
//Handlers for user defined questions
|
//Handlers for user defined questions
|
||||||
activeSkill.intents.map (intent => {
|
activeSkill.intents.map (intent => {
|
||||||
handlers[intent.intentName] = function () {
|
handlers[intent.intentName] = function () {
|
||||||
|
if (this.attributes['LaunchRequestYesNo']){
|
||||||
|
this.attributes['LaunchRequestYesNo'] = false;
|
||||||
|
}
|
||||||
this.response
|
this.response
|
||||||
.speak (intent.answer)
|
.speak (intent.answer)
|
||||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||||
@@ -75,6 +78,10 @@ module.exports = {
|
|||||||
|
|
||||||
//Handler for sending message
|
//Handler for sending message
|
||||||
handlers.SendMessageIntent = function () {
|
handlers.SendMessageIntent = function () {
|
||||||
|
if (this.attributes['LaunchRequestYesNo']){
|
||||||
|
this.attributes['LaunchRequestYesNo'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
let intent = this.event.request.intent;
|
let intent = this.event.request.intent;
|
||||||
|
|
||||||
console.log ('Dialog state : ' + this.event.request.dialogState);
|
console.log ('Dialog state : ' + this.event.request.dialogState);
|
||||||
@@ -161,7 +168,48 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Default handlers for unknown questions and session close
|
//Built-In intents
|
||||||
|
|
||||||
|
handlers.CancelIntent = function () {
|
||||||
|
if (this.attributes['LaunchRequestYesNo']){
|
||||||
|
this.attributes['LaunchRequestYesNo'] = false;
|
||||||
|
}
|
||||||
|
this.response.speak ('Thank you for using Saburly');
|
||||||
|
this.emit (':responseReady');
|
||||||
|
};
|
||||||
|
|
||||||
|
handlers.HelpIntent = function () {
|
||||||
|
if (this.attributes['LaunchRequestYesNo']){
|
||||||
|
this.attributes['LaunchRequestYesNo'] = false;
|
||||||
|
}
|
||||||
|
this.response
|
||||||
|
.speak (listOfPossibleQuestions)
|
||||||
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||||
|
this.emit (':responseReady');
|
||||||
|
};
|
||||||
|
|
||||||
|
handlers.YesIntent = function(){
|
||||||
|
if (this.attributes['LaunchRequestYesNo']){
|
||||||
|
this.attributes['LaunchRequestYesNo'] = false;
|
||||||
|
this.emit('HelpIntent');
|
||||||
|
}else{
|
||||||
|
this.response.speak(constants.voiceResponseStrings.DIDNT_ASK_ANYTHING).listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||||
|
this.emit(':responseReady');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handlers.NoIntent = function (){
|
||||||
|
if (this.attributes['LaunchRequestYesNo']){
|
||||||
|
this.attributes['LaunchRequestYesNo'] = false;
|
||||||
|
this.response.speak('').listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||||
|
this.emit(':responseReady');
|
||||||
|
}else{
|
||||||
|
this.response.speak(constants.voiceResponseStrings.DIDNT_ASK_ANYTHING).listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||||
|
this.emit(':responseReady');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Default handler for unknown question
|
||||||
|
|
||||||
handlers.Unhandled = function () {
|
handlers.Unhandled = function () {
|
||||||
this.response
|
this.response
|
||||||
@@ -169,6 +217,8 @@ module.exports = {
|
|||||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Session handlers
|
||||||
|
|
||||||
handlers.SessionEndedRequest = function () {
|
handlers.SessionEndedRequest = function () {
|
||||||
//We don't care for now
|
//We don't care for now
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user