send update to amazon
This commit is contained in:
@@ -1,52 +1,62 @@
|
||||
require('isomorphic-fetch');
|
||||
|
||||
var ObjectID = require ('mongodb').ObjectID;
|
||||
|
||||
var generateInteractionModel = function (skill) {
|
||||
|
||||
var getBuildStatus = function(skillID){
|
||||
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);
|
||||
fetch(`https://api.amazonalexa.com/v0/skills/${skillID}/interactionModel/locales/en-US/status`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: TOKEN
|
||||
},
|
||||
}).then(l=>l.text()).then(result=>{
|
||||
return result;
|
||||
});
|
||||
|
||||
skill.intents.map(intent=>{
|
||||
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);
|
||||
console.log("err : " + 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]);
|
||||
|
||||
}
|
||||
});
|
||||
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);
|
||||
});
|
||||
*/
|
||||
|
||||
skill.intents.map(intent=>{
|
||||
allIntents.push({name: intent.intentName, samples: intent.questions});
|
||||
});
|
||||
|
||||
result.interactionModel = {};
|
||||
|
||||
result.interactionModel.languageModel = {
|
||||
invocationName: skill.invocationName,
|
||||
intents: allIntents
|
||||
};
|
||||
|
||||
return JSON.stringify(result);
|
||||
}catch(e){
|
||||
console.log("error generate : " + e);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user