diff --git a/backend/helpers/amazon.js b/backend/helpers/amazon.js index d6c554b..6d1b553 100644 --- a/backend/helpers/amazon.js +++ b/backend/helpers/amazon.js @@ -37,15 +37,22 @@ var refreshTokens = function () { request (options, function (error, response, body) { if (error) { reject (error); - }else{ + } else { parsedResponse = JSON.parse (body); - if (parsedResponse.refresh_token){ - databaseHelper.updateTokens(parsedResponse.refresh_token, parsedResponse.access_token, parsedResponse.expires_in).then(()=>{ - resolve(); - }).catch(e=>{ - reject(e); - }); - }else{ + if (parsedResponse.refresh_token) { + databaseHelper + .updateTokens ( + parsedResponse.refresh_token, + parsedResponse.access_token, + parsedResponse.expires_in + ) + .then (() => { + resolve (); + }) + .catch (e => { + reject (e); + }); + } else { reject (body); } } @@ -56,81 +63,181 @@ var refreshTokens = function () { var generateInteractionModel = function (skill) { let result = {}; 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 => { allIntents.push ({name: intent.intentName, samples: intent.questions}); }); - //Special Email Intents : - /* - 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', - ], - }); + //Special intent for sending message (Dialog) allIntents.push ({ - name: 'EmailIntent', + name: 'SendMessageIntent', + samples: [ + 'I would like to send a message', + 'I want to send a message', + 'Send message', + ], slots: [ { name: 'Name', type: 'AMAZON.US_FIRST_NAME', + samples: ['My name is {Name}', 'I am {Name}', '{Name}'], }, { name: 'Email', - type: 'AMAZON.LITERAL', + type: 'EmailSlot', + samples: ['My email is {Email}', '{Email}'], }, { 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.languageModel = { invocationName: skill.invocationName, + types: customSlotTypes, intents: allIntents, + prompts: dialogPrompts, + dialog: dialog, }; return JSON.stringify (result); diff --git a/backend/models/alexa.js b/backend/models/alexa.js index d95c855..ff303e6 100644 --- a/backend/models/alexa.js +++ b/backend/models/alexa.js @@ -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 handlers.Unhandled = function () { this.response .speak (constants.voiceResponseStrings.QUESTION_NOT_FOUND) .listen (constants.voiceResponseStrings.GENERIC_CONTINUE); - } + }; - handlers.SessionEndedRequest = function(){ + handlers.SessionEndedRequest = function () { //We don't care for now - } - - + }; }) .catch (e => { //Something is wrong, skill is not ready, use catch-all intent to inform user