From a00859c5944127e932add03841c818c03b2b0535 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 22 Jan 2018 22:34:13 +0100 Subject: [PATCH] fix InteractionModel generator --- backend/controllers/skill.js | 1 + backend/helpers/amazon.js | 43 ++++++++++++++---------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/backend/controllers/skill.js b/backend/controllers/skill.js index a0c2f5f..921e45b 100644 --- a/backend/controllers/skill.js +++ b/backend/controllers/skill.js @@ -79,6 +79,7 @@ router.put ('/:id', bodyParser.json (), async (req, res, next) => { } }) .catch (e => { + console.log(e); //Update on amazon failed, revert changes in database and send error to user databaseHelper .updateSkill (id, currentSkillState) diff --git a/backend/helpers/amazon.js b/backend/helpers/amazon.js index fa414ac..486f1ab 100644 --- a/backend/helpers/amazon.js +++ b/backend/helpers/amazon.js @@ -64,25 +64,12 @@ var generateInteractionModel = function (skill) { let result = {}; let allIntents = []; - allIntents.push({ - "name": "AMAZON.CancelIntent", - "samples": [] - }, - { - "name": "AMAZON.HelpIntent", - "samples": [] - }, - { - "name": "AMAZON.StopIntent", - "samples": [] - },); - skill.intents.map (intent => { - allIntents.push ({name: intent.intentName, samples: intent.questions, slots:[]}); + allIntents.push ({name: intent.intentName, samples: intent.questions}); }); //Special intent for sending message (Dialog) -/* + allIntents.push ({ name: 'SendMessageIntent', samples: [ @@ -108,7 +95,9 @@ var generateInteractionModel = function (skill) { }, ], }); -*/ + + + let customSlotTypes = [ { name: 'EmailSlot', @@ -163,7 +152,7 @@ var generateInteractionModel = function (skill) { ], }, ]; - + let dialogPrompts = [ { id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Name', @@ -201,7 +190,7 @@ var generateInteractionModel = function (skill) { ], }, ]; - + let dialogIntents = [ { name: 'SendMessageIntent', @@ -239,24 +228,24 @@ var generateInteractionModel = function (skill) { }, ]; - let dialog = { - intents: dialogIntents, - }; + result.interactionModel = {}; - result.languageModel = { + result.interactionModel.languageModel = { invocationName: skill.invocationName, - //types: customSlotTypes, + types: customSlotTypes, intents: allIntents, }; - //result.prompts = dialogPrompts; - //result.dialog = dialog; + result.interactionModel.prompts = dialogPrompts; + result.interactionModel.dialog = {}; + result.interactionModel.dialog.intents = dialogIntents; - console.log(JSON.stringify(result)); return JSON.stringify (result); }; var uploadSkill = function (skill) { + let generatedInteractionModel = generateInteractionModel(skill); + console.log(generatedInteractionModel); return fetch ( `https://api.amazonalexa.com/v0/skills/${skill.skillID}/interactionModel/locales/en-US`, { @@ -264,7 +253,7 @@ var uploadSkill = function (skill) { headers: { Authorization: config.TOKEN, }, - body: generateInteractionModel (skill), + body: generatedInteractionModel, } ); };