4a. import content from WP ; change design to reflect 4a
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
constants = require('./constants')
|
||||
var config = {};
|
||||
|
||||
config.SKILL_STAGE = constants.skillStage.IN_DEVELOPMENT;
|
||||
|
||||
config.DB_URL = 'mongodb://localhost:27017/tellall';
|
||||
config.PORT = 5000;
|
||||
|
||||
@@ -17,7 +20,7 @@ config.TOKEN_EXPIRES_IN = 1515100500;
|
||||
//config.SKILL_ID = 'amzn1.ask.skill.efbf0564-a732-4ba9-958f-57939138adae'; //bilal
|
||||
config.SKILL_ID = 'amzn1.ask.skill.2445552d-954d-4cd6-b77f-295368e02842'; //saburly
|
||||
//config.SKILL_DB_ID = '5a5016e775becaef2015da10'; //for server
|
||||
config.SKILL_DB_ID = '5a232fb86ce046c749739455'; //for local
|
||||
config.SKILL_DB_ID = '5abd461329f85e4ec728d945'; //for local
|
||||
|
||||
//Bilal
|
||||
//config.CLIENT_ID = 'amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7';
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
const constants = {};
|
||||
|
||||
constants.skillStage = {
|
||||
IN_DEVELOPMENT : 'development',
|
||||
LIVE : 'live'
|
||||
}
|
||||
|
||||
constants.amazonResultCodes = {
|
||||
OK: 200,
|
||||
ACCEPTED: 202,
|
||||
@@ -58,4 +63,10 @@ constants.stringConstraints = {
|
||||
EMAIL_MAX_LENGTH: 100,
|
||||
};
|
||||
|
||||
constants.answerType = {
|
||||
PREDEFINED: 0,
|
||||
EXTERNAL_SOURCE_WP_JSON : 1,
|
||||
EXTERNAL_SOURCE_RSS : 2
|
||||
}
|
||||
|
||||
module.exports = constants;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var express = require ('express'), router = express.Router ();
|
||||
let express = require ('express'), router = express.Router ();
|
||||
const constants = require ('../config/constants');
|
||||
var databaseHelper = require ('../helpers/database');
|
||||
var amazonHelper = require ('../helpers/amazon');
|
||||
var skillValidator = require('../helpers/skillValidator');
|
||||
var bodyParser = require ('body-parser');
|
||||
var alexa = require ('../models/alexa');
|
||||
let databaseHelper = require ('../helpers/database');
|
||||
let amazonHelper = require ('../helpers/amazon');
|
||||
let skillValidator = require('../helpers/skillValidator');
|
||||
let bodyParser = require ('body-parser');
|
||||
let alexa = require ('../models/alexa');
|
||||
|
||||
router.get ('/:id', async (req, res, next) => {
|
||||
const id = req.params.id;
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
52
backend/helpers/externalSource.js
Normal file
52
backend/helpers/externalSource.js
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,9 +3,8 @@ const config = require ('../config/config');
|
||||
var databaseHelper = require ('../helpers/database');
|
||||
var emailHelper = require ('../helpers/email');
|
||||
const constants = require ('../config/constants');
|
||||
let Parser = require('rss-parser');
|
||||
let predefinedSourceHelper = require ('../helpers/externalSource');
|
||||
|
||||
let parser = new Parser();
|
||||
var handlers = {};
|
||||
var destinationEmail;
|
||||
|
||||
@@ -46,7 +45,8 @@ module.exports = {
|
||||
'ms"/>';
|
||||
}
|
||||
});
|
||||
listOfPossibleQuestions += 'If you dont know what to do, just say help or stop';
|
||||
listOfPossibleQuestions +=
|
||||
'If you dont know what to do, just say help or stop';
|
||||
|
||||
//Handler for launch requestconsole.log()
|
||||
handlers = {
|
||||
@@ -60,7 +60,7 @@ module.exports = {
|
||||
'Would you like to hear list of questions that you can ask me'
|
||||
)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||
this.attributes['LaunchRequestYesNo'] = true;
|
||||
this.attributes['LaunchRequestYesNo'] = true;
|
||||
this.emit (':responseReady');
|
||||
},
|
||||
};
|
||||
@@ -68,20 +68,23 @@ module.exports = {
|
||||
//Handlers for user defined questions
|
||||
activeSkill.intents.map (intent => {
|
||||
handlers[intent.intentName] = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
if (this.attributes['LaunchRequestYesNo']) {
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
if (intent.predefinedAnswer) {
|
||||
const url = 'https://www.klix.ba/rss/naslovnica';
|
||||
let feed = await parser.parseURL(url);
|
||||
console.log(feed.title);
|
||||
|
||||
feed.items.forEach(item => {
|
||||
console.log(item.title + ':' + item.link)
|
||||
});
|
||||
let answer = '';
|
||||
switch (intent.answerType){
|
||||
case constants.answerType.PREDEFINED:
|
||||
answer = intent.answer;
|
||||
break;
|
||||
case constants.answerType.EXTERNAL_SOURCE_WP_JSON:
|
||||
answer = predefinedSourceHelper.getAnswerFromWP(intent.externalAnswerSource);
|
||||
break;
|
||||
case constants.answerType.EXTERNAL_SOURCE_RSS:
|
||||
answer = 'Not implemented yet'
|
||||
break;
|
||||
}
|
||||
this.response
|
||||
.speak (intent.answer)
|
||||
.speak (answer)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||
this.emit (':responseReady');
|
||||
};
|
||||
@@ -89,7 +92,7 @@ module.exports = {
|
||||
|
||||
//Handler for sending message
|
||||
handlers.SendMessageIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
if (this.attributes['LaunchRequestYesNo']) {
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
|
||||
@@ -182,7 +185,7 @@ module.exports = {
|
||||
//Built-In intents
|
||||
|
||||
handlers.CancelIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
if (this.attributes['LaunchRequestYesNo']) {
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
this.response.speak ('Thank you for using Saburly');
|
||||
@@ -190,7 +193,7 @@ module.exports = {
|
||||
};
|
||||
|
||||
handlers.HelpIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
if (this.attributes['LaunchRequestYesNo']) {
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
this.response
|
||||
@@ -199,26 +202,32 @@ module.exports = {
|
||||
this.emit (':responseReady');
|
||||
};
|
||||
|
||||
handlers.YesIntent = function(){
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
handlers.YesIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']) {
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
this.emit('HelpIntent');
|
||||
}else{
|
||||
this.response.speak(constants.voiceResponseStrings.DIDNT_ASK_ANYTHING).listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit(':responseReady');
|
||||
this.emit ('HelpIntent');
|
||||
} else {
|
||||
this.response
|
||||
.speak (constants.voiceResponseStrings.DIDNT_ASK_ANYTHING)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit (':responseReady');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
handlers.NoIntent = function (){
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
handlers.NoIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']) {
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
this.response.speak('').listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit(':responseReady');
|
||||
}else{
|
||||
this.response.speak(constants.voiceResponseStrings.DIDNT_ASK_ANYTHING).listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit(':responseReady');
|
||||
this.response
|
||||
.speak ('')
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit (':responseReady');
|
||||
} else {
|
||||
this.response
|
||||
.speak (constants.voiceResponseStrings.DIDNT_ASK_ANYTHING)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit (':responseReady');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Default handler for unknown question
|
||||
|
||||
|
||||
1717
backend/package-lock.json
generated
1717
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,6 @@
|
||||
"nodejs-text-summarizer": "^2.0.3",
|
||||
"nodemailer": "^4.4.1",
|
||||
"request": "^2.83.0",
|
||||
"rss-parser": "^3.1.1",
|
||||
"rss-parser": "^3.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user