4a. import content from WP ; change design to reflect 4a

This commit is contained in:
GotPPay
2018-03-30 10:54:15 +02:00
parent 5484a9a461
commit 443dc53dbd
17 changed files with 3581 additions and 875 deletions

View File

@@ -271,10 +271,11 @@ var generateInteractionModel = function (skill) {
var uploadSkill = function (skill) {
let generatedInteractionModel = generateInteractionModel (skill);
console.log(skill.skillID);
return fetch (
`https://api.amazonalexa.com/v0/skills/${skill.skillID}/interactionModel/locales/en-US`,
`https://api.amazonalexa.com/v1/skills/${skill.skillID}/stages/development/interactionModel/locales/en-US`,
{
method: 'POST',
method: 'PUT',
headers: {
Authorization: config.TOKEN,
},

View File

@@ -0,0 +1,52 @@
let request = require ('request');
let Parser = require ('rss-parser');
let parser = new Parser ();
getDataFromRSSFeed = function (url) {
//let feed = await parser.parseURL(url);
//console.log(feed.title);
//feed.items.forEach(item => {
// console.log(item.title + ':' + item.link)
//});
}
getDataFromWPJSON = function (sourceUrl, page = 1, maxPosts = 10) {
return new Promise ((resolve, reject) => {
var options = {
method: 'GET',
url: `${sourceUrl}/wp-json/wp/v2/posts`,
qs:{
page:page,
per_page:maxPosts
}
};
request (options, (error, response, body)=> {
if (error) {
reject (error);
} else {
resolve(JSON.parse (body));
}
});
});
}
module.exports = {
getAnswerFromWP : function (sourceUrl){
//This function will extract needed data from JSON, which we got from getDataFromWPJSON
//At the moment, it's taking titles and creates answer
return new Promise((resolve,reject)=>{
getDataFromWPJSON(sourceUrl).then(rawData=>{
let result='';
rawData.forEach(post=>{
result += post.title.rendered + '<break time="300ms"/> '
});
resolve(result);
}).catch(err=>{
reject(err);
});
});
}
}

View File

@@ -26,7 +26,9 @@ validateQuestion = function (question) {
return validQuestionNameRegex.test (question);
};
validateAnswer = function (answer) {
validateAnswer = function (answer, answerType) {
if (answerType !== constants.answerType.PREDEFINED) return true;
if (
answer.length < constants.stringConstraints.ANSWER_MIN_LENGTH ||
answer.length > constants.stringConstraints.ANSWER_MAX_LENGTH
@@ -36,13 +38,18 @@ validateAnswer = function (answer) {
return validAnswerRegex.test (answer);
};
validateExternalAnswerSource = function (externalAnswerSource, answerType){
// TODO: implement validation logic
return true;
}
validateInvocationName = function (invocationName) {
if (
invocationName.length < constants.stringConstraints.INVOCATION_NAME_MIN_LENGTH ||
invocationName.length > constants.stringConstraints.INVOCATION_NAME_MAX_LENGTH
)
return false;
let validInvocationNameRegex = /^[a-z,.' ]*$/i;
let validInvocationNameRegex = /^[a-z,.' ]*$/;
return validInvocationNameRegex.test (invocationName);
};
@@ -69,10 +76,10 @@ module.exports = {
!validateInvocationAnswer (skill.invocationAnswer)
)
return false;
for (let i = 0; i < skill.intents.length; i++) {
if (!validateIntentName (skill.intents[i].intentName)) return false;
if (!validateAnswer (skill.intents[i].answer)) return false;
if (!validateAnswer (skill.intents[i].answer, skill.intents[i].answerType)) return false;
if (!validateExternalAnswerSource(skill.intents[i].externalAnswerSource, skill.intents[i].answerType)) return false;
for (let j = 0; j < skill.intents.length; j++) {
if (i === j) continue;