Testing dialog handler
This commit is contained in:
@@ -37,15 +37,22 @@ var refreshTokens = function () {
|
|||||||
request (options, function (error, response, body) {
|
request (options, function (error, response, body) {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject (error);
|
reject (error);
|
||||||
}else{
|
} else {
|
||||||
parsedResponse = JSON.parse (body);
|
parsedResponse = JSON.parse (body);
|
||||||
if (parsedResponse.refresh_token){
|
if (parsedResponse.refresh_token) {
|
||||||
databaseHelper.updateTokens(parsedResponse.refresh_token, parsedResponse.access_token, parsedResponse.expires_in).then(()=>{
|
databaseHelper
|
||||||
resolve();
|
.updateTokens (
|
||||||
}).catch(e=>{
|
parsedResponse.refresh_token,
|
||||||
reject(e);
|
parsedResponse.access_token,
|
||||||
});
|
parsedResponse.expires_in
|
||||||
}else{
|
)
|
||||||
|
.then (() => {
|
||||||
|
resolve ();
|
||||||
|
})
|
||||||
|
.catch (e => {
|
||||||
|
reject (e);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
reject (body);
|
reject (body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,81 +63,181 @@ var refreshTokens = function () {
|
|||||||
var generateInteractionModel = function (skill) {
|
var generateInteractionModel = function (skill) {
|
||||||
let result = {};
|
let result = {};
|
||||||
let allIntents = [];
|
let allIntents = [];
|
||||||
let defaultIntents = [
|
|
||||||
{
|
|
||||||
name: 'AMAZON.CancelIntent',
|
|
||||||
samples: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AMAZON.HelpIntent',
|
|
||||||
samples: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AMAZON.StopIntent',
|
|
||||||
samples: [],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
/*
|
|
||||||
defaultIntents.map(intent=>{
|
|
||||||
allIntents.push(intent);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
skill.intents.map (intent => {
|
skill.intents.map (intent => {
|
||||||
allIntents.push ({name: intent.intentName, samples: intent.questions});
|
allIntents.push ({name: intent.intentName, samples: intent.questions});
|
||||||
});
|
});
|
||||||
|
|
||||||
//Special Email Intents :
|
//Special intent for sending message (Dialog)
|
||||||
/*
|
|
||||||
allIntents.push ({
|
|
||||||
name: 'EmailIntentLaunch',
|
|
||||||
slots: [],
|
|
||||||
samples: [
|
|
||||||
'I want to send a message',
|
|
||||||
'I would like to send a message',
|
|
||||||
'I would like to leave a message',
|
|
||||||
'Leave a message',
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
allIntents.push ({
|
allIntents.push ({
|
||||||
name: 'EmailIntent',
|
name: 'SendMessageIntent',
|
||||||
|
samples: [
|
||||||
|
'I would like to send a message',
|
||||||
|
'I want to send a message',
|
||||||
|
'Send message',
|
||||||
|
],
|
||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
type: 'AMAZON.US_FIRST_NAME',
|
type: 'AMAZON.US_FIRST_NAME',
|
||||||
|
samples: ['My name is {Name}', 'I am {Name}', '{Name}'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Email',
|
name: 'Email',
|
||||||
type: 'AMAZON.LITERAL',
|
type: 'EmailSlot',
|
||||||
|
samples: ['My email is {Email}', '{Email}'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Message',
|
name: 'Message',
|
||||||
type: 'AMAZON.LITERAL',
|
type: 'MessageSlot',
|
||||||
|
samples: ['{Message}'],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Data',
|
|
||||||
type: 'AMAZON.LITERAL',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
samples: [
|
|
||||||
'My name is {Name}',
|
|
||||||
'I am {Name}',
|
|
||||||
'{exampleww at wwdwdw|Data}',
|
|
||||||
'My email is {example at efefegedd|Email}',
|
|
||||||
'Send replay to {example at abcdefg|Email}',
|
|
||||||
'My message is {The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.|Message}',
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
let customSlotTypes = [
|
||||||
|
{
|
||||||
|
name: 'EmailSlot',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
id: null,
|
||||||
|
name: {
|
||||||
|
value: 'bla@bla.bla',
|
||||||
|
synonyms: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: null,
|
||||||
|
name: {
|
||||||
|
value: 'bla.bla@bla.bla.bla',
|
||||||
|
synonyms: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: null,
|
||||||
|
name: {
|
||||||
|
value: 'bla_bla@bla.bla',
|
||||||
|
synonyms: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'MessageSlot',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
id: null,
|
||||||
|
name: {
|
||||||
|
value: 'Quick brown fox jumps over lazy dog',
|
||||||
|
synonyms: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: null,
|
||||||
|
name: {
|
||||||
|
value: 'Quick brown fox jumps over lazy dog. Quick brown fox jumps over lazy dog.',
|
||||||
|
synonyms: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: null,
|
||||||
|
name: {
|
||||||
|
value: 'Quick brown fox jumps over lazy dog. Quick brown fox jumps over lazy dog. Quick brown fox jumps over lazy dog.',
|
||||||
|
synonyms: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let dialogPrompts = [
|
||||||
|
{
|
||||||
|
id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Name',
|
||||||
|
variations: [
|
||||||
|
{
|
||||||
|
type: 'PlainText',
|
||||||
|
value: 'What is your name ?',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'PlainText',
|
||||||
|
value: 'Tell me your name',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Email',
|
||||||
|
variations: [
|
||||||
|
{
|
||||||
|
type: 'PlainText',
|
||||||
|
value: 'What is your email ?',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'PlainText',
|
||||||
|
value: 'Tell me your email',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Message',
|
||||||
|
variations: [
|
||||||
|
{
|
||||||
|
type: 'PlainText',
|
||||||
|
value: 'What is your message',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let dialogIntents = [
|
||||||
|
{
|
||||||
|
name: 'SendMessageIntent',
|
||||||
|
confirmationRequired: false,
|
||||||
|
prompts: {},
|
||||||
|
slots: [
|
||||||
|
{
|
||||||
|
name: 'Name',
|
||||||
|
type: 'AMAZON.US_FIRST_NAME',
|
||||||
|
elicitationRequired: true,
|
||||||
|
confirmationRequired: false,
|
||||||
|
prompts: {
|
||||||
|
elicitation: 'Elicit.Intent-SendMessageIntent.IntentSlot-Name',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Email',
|
||||||
|
type: 'EmailSlot',
|
||||||
|
elicitationRequired: true,
|
||||||
|
confirmationRequired: false,
|
||||||
|
prompts: {
|
||||||
|
elicitation: 'Elicit.Intent-SendMessageIntent.IntentSlot-Email',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Message',
|
||||||
|
type: 'MessageSlot',
|
||||||
|
elicitationRequired: true,
|
||||||
|
confirmationRequired: false,
|
||||||
|
prompts: {
|
||||||
|
elicitation: 'Elicit.Intent-SendMessageIntent.IntentSlot-Message',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let dialog = {
|
||||||
|
intents: dialogIntents,
|
||||||
|
};
|
||||||
|
|
||||||
result.interactionModel = {};
|
result.interactionModel = {};
|
||||||
|
|
||||||
result.interactionModel.languageModel = {
|
result.interactionModel.languageModel = {
|
||||||
invocationName: skill.invocationName,
|
invocationName: skill.invocationName,
|
||||||
|
types: customSlotTypes,
|
||||||
intents: allIntents,
|
intents: allIntents,
|
||||||
|
prompts: dialogPrompts,
|
||||||
|
dialog: dialog,
|
||||||
};
|
};
|
||||||
|
|
||||||
return JSON.stringify (result);
|
return JSON.stringify (result);
|
||||||
|
|||||||
@@ -53,19 +53,24 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Handler for sending message
|
||||||
|
handlers.SendMessageIntent = function () {
|
||||||
|
console.log("Dialog state : " + this.event.request.dialogState);
|
||||||
|
console.log("Intent object :");
|
||||||
|
console.log(this.event.request.intent);
|
||||||
|
};
|
||||||
|
|
||||||
//Default handlers for unknown questions and session close
|
//Default handlers for unknown questions and session close
|
||||||
|
|
||||||
handlers.Unhandled = function () {
|
handlers.Unhandled = function () {
|
||||||
this.response
|
this.response
|
||||||
.speak (constants.voiceResponseStrings.QUESTION_NOT_FOUND)
|
.speak (constants.voiceResponseStrings.QUESTION_NOT_FOUND)
|
||||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||||
}
|
};
|
||||||
|
|
||||||
handlers.SessionEndedRequest = function(){
|
handlers.SessionEndedRequest = function () {
|
||||||
//We don't care for now
|
//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