generate interaction model
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { sendUpdateToAmazon } from './helpers/amazon';
|
var amazonHelper = require('./helpers/amazon');
|
||||||
|
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var alexa = require('alexa-app');
|
var alexa = require('alexa-app');
|
||||||
@@ -60,6 +60,7 @@ router.post ('/updateSkill/:id', async (req, res, next) => {
|
|||||||
if (id !== '-1'){
|
if (id !== '-1'){
|
||||||
let result = db.collection('skill_list').update({_id: ObjectID(id)}, skill,{upsert:true}, (err, result)=>{
|
let result = db.collection('skill_list').update({_id: ObjectID(id)}, skill,{upsert:true}, (err, result)=>{
|
||||||
if (err) throw(err);
|
if (err) throw(err);
|
||||||
|
amazonHelper.sendUpdateToAmazon(id, db);
|
||||||
res.json(result);
|
res.json(result);
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -1,7 +1,52 @@
|
|||||||
|
var ObjectID = require ('mongodb').ObjectID;
|
||||||
|
|
||||||
|
var generateInteractionModel = function (skill) {
|
||||||
|
try{
|
||||||
|
let result = {};
|
||||||
|
let allIntents = [];
|
||||||
|
let defaultIntents = [{
|
||||||
|
name: "AMAZON.CancelIntent",
|
||||||
|
samples: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "AMAZON.HelpIntent",
|
||||||
|
samples: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "AMAZON.StopIntent",
|
||||||
|
samples: []
|
||||||
|
}];
|
||||||
|
|
||||||
|
defaultIntents.map(intent=>{
|
||||||
|
allIntents.push(intent);
|
||||||
|
});
|
||||||
|
|
||||||
export const sendUpdateToAmazon = (id)=>{
|
skill.intents.map(intent=>{
|
||||||
//id - skill ID in database
|
allIntents.push({name: intent.intentName, samples: intent.questions, slots: []});
|
||||||
|
});
|
||||||
|
|
||||||
|
result.languageModel = {
|
||||||
|
invocationName: skill.invocationName,
|
||||||
|
intents: allIntents
|
||||||
|
};
|
||||||
|
|
||||||
|
return JSON.stringify(result);
|
||||||
|
}catch(e){
|
||||||
|
console.log("error generate : " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
sendUpdateToAmazon: function (id, db){
|
||||||
|
db.collection ('skill_list').find({_id: ObjectID(id)}).toArray((err,result)=>{
|
||||||
|
if (err){
|
||||||
|
console.log("Error finding skill");
|
||||||
|
}else{
|
||||||
|
//generateInteractionModel
|
||||||
|
//POST to amazon
|
||||||
|
let generatedInteractionModel = generateInteractionModel(result[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -11,8 +11,9 @@ class App extends Component {
|
|||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state={_id:'5a22ffd36ce046c749739453',
|
this.state={_id:'5a232fb86ce046c749739455',
|
||||||
skillID:'',
|
skillID:'',
|
||||||
|
skillName:'',
|
||||||
invocationName:'Saburly',
|
invocationName:'Saburly',
|
||||||
invocationAnswer:'We are saburly',
|
invocationAnswer:'We are saburly',
|
||||||
allIntents:[],
|
allIntents:[],
|
||||||
@@ -23,7 +24,7 @@ class App extends Component {
|
|||||||
getSkill(this.state._id).then(l=> l.text()).then(result=>{
|
getSkill(this.state._id).then(l=> l.text()).then(result=>{
|
||||||
let jResult = JSON.parse(result)[0];
|
let jResult = JSON.parse(result)[0];
|
||||||
if (jResult===undefined) return;
|
if (jResult===undefined) return;
|
||||||
this.setState({ skillID:jResult.skillID, invocationName: jResult.invocationName,
|
this.setState({ skillID:jResult.skillID,skillName:jResult.skillName, invocationName: jResult.invocationName,
|
||||||
invocationAnswer: jResult.invocationAnswer,
|
invocationAnswer: jResult.invocationAnswer,
|
||||||
allIntents: jResult.intents})
|
allIntents: jResult.intents})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user