Merge pull request #14 from GotPPay/handle-user-input
Handle user input
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
To obtain client ID and secret :
|
||||
https://developer.amazon.com/lwa/sp/overview.html
|
||||
Click create new security profile, and add whitelist redirect uri : https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO
|
||||
|
||||
|
||||
To obtain new Auth Code :
|
||||
|
||||
https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7&scope=alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test&response_type=code&redirect_uri=https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO
|
||||
https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.8c183daec15c488c9126b62bda9f7832&scope=alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test&response_type=code&redirect_uri=https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO
|
||||
|
||||
Response URL (Decoded) :
|
||||
|
||||
|
||||
@@ -3,15 +3,28 @@ var config = {};
|
||||
config.DB_URL = 'mongodb://localhost:27017/tellall';
|
||||
config.PORT = 5000;
|
||||
|
||||
config.TOKEN = 'Atza|IwEBIBe6gDqrrowEEav6N-_6s4NztYeP3oG8PGWmu8ZiZw6lbOh3wNla3TK6pY-VEpT1d8an-dVf_n3kXJzVFsNo_4xBfZyFHGoCTDTFjs3yBRul4PVdBOhwwiH3-sgRLcUofZbe2oE06GmTcbfYtaStfXpQI5dfpldfnsJg_CvhSA6AHb_snJT3F6lyXzbV076d_3cYUMJxFldJGnYcviNHHxjjmuQTD06hhGzCbAxxe9eBmkuopRsNfyedLT2UlKP_ublah9CUGA3AdIX_3Iuke82jMwGnNl9gv7pbaDNEjAbj7IQSl3B08uuREtJq-oTBOjALNXRvFxTJmQjZwXNf9eHC7fSHJDdEPdZQU0AcffRQObAyAkUuL6Jv39OHzhb3Q64-zzoyODqnJyLP5SQZ2JVF53Kc_cTBqjIc9pXljqe7yEVk6JD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gxfWj2H0hwLy0oZ7_qykS7wUHMGjRO5yScuBWFIr0RFFu00GS7zrKjkhFc_E4ZBBKskn0gywS-5pogo0U1rQtLg8lQJsVbxXQwtq2TxkGFMBiVxtQcXtHM1qbCVXpZQbk7ezxvasj4yAIsF4H7KBiZSGmWHkk4yADykWJSntTjFcM2wG0wSiEYoYzJQ';
|
||||
config.TOKEN_EXPIRES_IN = 1515100500;
|
||||
|
||||
config.SKILL_ID = 'amzn1.ask.skill.efbf0564-a732-4ba9-958f-57939138adae';
|
||||
|
||||
|
||||
//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.CLIENT_ID = 'amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7';
|
||||
config.CLIENT_SECRET = '6dea8125cecd049d3c4cff7bb5bdfd3ff17bc6fed246c4c8f6b519d9ed08d0b3';
|
||||
//Bilal
|
||||
//config.CLIENT_ID = 'amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7';
|
||||
//config.CLIENT_SECRET = '6dea8125cecd049d3c4cff7bb5bdfd3ff17bc6fed246c4c8f6b519d9ed08d0b3';
|
||||
|
||||
//Saburly
|
||||
config.CLIENT_ID = 'amzn1.application-oa2-client.8c183daec15c488c9126b62bda9f7832';
|
||||
config.CLIENT_SECRET = '3acaa0755291132ee11e1cceaa100feef96a0244662df712a52189199cc655de';
|
||||
|
||||
module.exports = config;
|
||||
|
||||
@@ -1,43 +1,61 @@
|
||||
const constants = {};
|
||||
|
||||
constants.amazonResultCodes = {
|
||||
OK:200,
|
||||
ACCEPTED:202,
|
||||
BAD_REQUEST:400,
|
||||
UNAUTHORIZED:401,
|
||||
NOT_FOUND:404,
|
||||
CONFLICT:409,
|
||||
PAYLOAD_TOO_LARGE:413
|
||||
}
|
||||
OK: 200,
|
||||
ACCEPTED: 202,
|
||||
BAD_REQUEST: 400,
|
||||
UNAUTHORIZED: 401,
|
||||
NOT_FOUND: 404,
|
||||
CONFLICT: 409,
|
||||
PAYLOAD_TOO_LARGE: 413,
|
||||
};
|
||||
|
||||
constants.apiResultCodes = {
|
||||
GENERIC_ERROR : -1,
|
||||
OK:0,
|
||||
AMAZON_ERROR:1, //amazon api works, but error is some of the amazonResultCodes
|
||||
AMAZON_FAIL:2, //amazon api doesn't work
|
||||
DATABASE_ERROR:3,
|
||||
NO_SKILL:4,
|
||||
INCONSISTENT_STATE:5,
|
||||
}
|
||||
GENERIC_ERROR: -1,
|
||||
OK: 0,
|
||||
AMAZON_ERROR: 1, //amazon api works, but error is some of the amazonResultCodes
|
||||
AMAZON_FAIL: 2, //amazon api doesn't work
|
||||
DATABASE_ERROR: 3,
|
||||
NO_SKILL: 4,
|
||||
INCONSISTENT_STATE: 5,
|
||||
INVALID_SKILL: 6,
|
||||
};
|
||||
|
||||
constants.HTTPResultCodes = {
|
||||
INTERNAL_SERVER_ERROR : 500,
|
||||
}
|
||||
INTERNAL_SERVER_ERROR: 500,
|
||||
};
|
||||
|
||||
constants.SKILL_ID_LENGTH = 24;
|
||||
|
||||
constants.voiceResponseStrings = {
|
||||
QUESTION_NOT_FOUND : 'Sorry, I didnt understand',
|
||||
GENERIC_CONTINUE : 'Say something to continue',
|
||||
DIDNT_ASK_ANYTHING : 'There was no question to answer to',
|
||||
}
|
||||
QUESTION_NOT_FOUND: 'Sorry, I didnt understand',
|
||||
GENERIC_CONTINUE: 'Say something to continue',
|
||||
DIDNT_ASK_ANYTHING: 'There was no question to answer to',
|
||||
};
|
||||
|
||||
//Timing is given in [ms]
|
||||
constants.voiceResponseTimings = {
|
||||
PAUSE_BETWEEN_QUESTIONS : 650,
|
||||
PAUSE_AFTER_WELCOME_MESSAGE : 650,
|
||||
}
|
||||
PAUSE_BETWEEN_QUESTIONS: 650,
|
||||
PAUSE_AFTER_WELCOME_MESSAGE: 650,
|
||||
};
|
||||
|
||||
constants.stringConstraints = {
|
||||
INTENT_EXPLANATION_MAX_LENGTH: 70,
|
||||
|
||||
INTENT_NAME_MAX_LENGTH: 30,
|
||||
INTENT_NAME_MIN_LENGTH: 2,
|
||||
|
||||
QUESTION_MAX_LENGTH: 150,
|
||||
QUESTION_MIN_LENGTH: 2,
|
||||
|
||||
ANSWER_MAX_LENGTH: 150,
|
||||
ANSWER_MIN_LENGTH: 2,
|
||||
|
||||
INVOCATION_NAME_MAX_LENGTH: 50,
|
||||
INVOCATION_NAME_MIN_LENGTH: 2,
|
||||
INVOCATION_ANSWER_MAX_LENGTH: 100,
|
||||
|
||||
EMAIL_MAX_LENGTH: 100,
|
||||
};
|
||||
|
||||
module.exports = constants;
|
||||
@@ -2,6 +2,7 @@ var 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');
|
||||
|
||||
@@ -31,6 +32,20 @@ router.put ('/:id', bodyParser.json (), async (req, res, next) => {
|
||||
delete skill.updateOnAmazon;
|
||||
delete skill._id;
|
||||
|
||||
//Validate skill
|
||||
if (!skillValidator.validateSkill(skill)){
|
||||
//skill not valid
|
||||
res
|
||||
.status (
|
||||
constants.HTTPResultCodes.INTERNAL_SERVER_ERROR
|
||||
)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.INVALID_SKILL,
|
||||
message: '',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//First get current skill from DB
|
||||
databaseHelper
|
||||
.getSkill (id)
|
||||
|
||||
100
backend/helpers/skillValidator.js
Normal file
100
backend/helpers/skillValidator.js
Normal file
@@ -0,0 +1,100 @@
|
||||
const constants = require ('../config/constants');
|
||||
|
||||
validateEmail = function (email) {
|
||||
if (email.length > constants.stringConstraints.EMAIL_MAX_LENGTH) return false;
|
||||
let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return validEmailRegex.test (email);
|
||||
};
|
||||
|
||||
validateIntentName = function (intentName) {
|
||||
if (
|
||||
intentName.length < constants.stringConstraints.INTENT_NAME_MIN_LENGTH ||
|
||||
intentName.length > constants.stringConstraints.INTENT_NAME_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validIntentNameRegex = /^[a-z]*$/i;
|
||||
return validIntentNameRegex.test (intentName);
|
||||
};
|
||||
|
||||
validateQuestion = function (question) {
|
||||
if (
|
||||
question.length < constants.stringConstraints.QUESTION_MIN_LENGTH ||
|
||||
question.length > constants.stringConstraints.QUESTION_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validQuestionNameRegex = /^[a-z,.' ]*$/i;
|
||||
return validQuestionNameRegex.test (question);
|
||||
};
|
||||
|
||||
validateAnswer = function (answer) {
|
||||
if (
|
||||
answer.length < constants.stringConstraints.ANSWER_MIN_LENGTH ||
|
||||
answer.length > constants.stringConstraints.ANSWER_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validAnswerRegex = /^[a-z,.' ]*$/i;
|
||||
return validAnswerRegex.test (answer);
|
||||
};
|
||||
|
||||
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;
|
||||
return validInvocationNameRegex.test (invocationName);
|
||||
};
|
||||
|
||||
validateInvocationAnswer = function (invocationAnswer) {
|
||||
if (invocationAnswer.length > constants.stringConstraints.INVOCATION_ANSWER_MAX_LENGTH)
|
||||
return false;
|
||||
let validInvocationAnswerRegex = /^[a-z,.' ]*$/i;
|
||||
return validInvocationAnswerRegex.test (invocationAnswer);
|
||||
};
|
||||
|
||||
validateIntentExplanation = function (explanation) {
|
||||
if (explanation.length > constants.stringConstraints.INTENT_EXPLANATION_MAX_LENGTH)
|
||||
return false;
|
||||
let validExplanationRegex = /^[a-z,.' ]*$/i;
|
||||
return validExplanationRegex.test (explanation);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateSkill: function (skill) {
|
||||
try {
|
||||
if (
|
||||
!validateEmail (skill.contactEmail) ||
|
||||
!validateInvocationName (skill.invocationName) ||
|
||||
!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;
|
||||
|
||||
for (let j = 0; j < skill.intents.length; j++) {
|
||||
if (i === j) continue;
|
||||
if (skill.intents[i].intentName === skill.intents[j].intentName)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let j = 0; j < skill.intents[i].questions.length; j++) {
|
||||
if (!validateQuestion (skill.intents[i].questions[j])) return false;
|
||||
|
||||
for (let k = 0; k < skill.intents[i].questions.length; k++) {
|
||||
if (j === k) continue;
|
||||
if (skill.intents[i].questions[j] === skill.intents[i].questions[k])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log ('Error : ' + e);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -7,11 +7,16 @@ import LaunchRequest from './components/LaunchRequest';
|
||||
import Contact from './components/Contact';
|
||||
import Popup from 'react-popup';
|
||||
import {getSkill, updateSkill} from './lib/api';
|
||||
import {isEmailValid} from './lib/helpers';
|
||||
import {
|
||||
NEW_INTENT_SELECTED_INDEX,
|
||||
LAUNCH_REQUEST_SELECTED_INDEX,
|
||||
CONTACT_SELECTED_INDEX,
|
||||
RESULT_CODES,
|
||||
INVOCATION_NAME_MIN_LENGTH,
|
||||
INTENT_NAME_MIN_LENGTH,
|
||||
QUESTION_MIN_LENGTH,
|
||||
ANSWER_MIN_LENGTH,
|
||||
} from './config/constants';
|
||||
|
||||
class App extends Component {
|
||||
@@ -132,7 +137,6 @@ class App extends Component {
|
||||
this.setState ({
|
||||
selectedIntent: selectedIntent,
|
||||
selectedIndex: index,
|
||||
launchRequest: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,6 +149,12 @@ class App extends Component {
|
||||
}
|
||||
|
||||
handleSaveLaunchRequestClick (name, answer) {
|
||||
|
||||
if (name.length < INVOCATION_NAME_MIN_LENGTH){
|
||||
Popup.alert ('Invocation name should be at least 2 characters long');
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState ({
|
||||
waiting: true,
|
||||
invocationName: name,
|
||||
@@ -163,6 +173,7 @@ class App extends Component {
|
||||
}
|
||||
|
||||
handleSaveEmailClick (email) {
|
||||
if (isEmailValid(email)){
|
||||
this.setState ({waiting: true});
|
||||
this.sendSkill (
|
||||
this.state.allIntents,
|
||||
@@ -174,6 +185,9 @@ class App extends Component {
|
||||
email,
|
||||
false
|
||||
);
|
||||
}else{
|
||||
Popup.alert ('Please enter valid email');
|
||||
}
|
||||
}
|
||||
|
||||
handleDeleteIntentClick (selectedIntent) {
|
||||
@@ -216,14 +230,56 @@ class App extends Component {
|
||||
}
|
||||
|
||||
handleSaveIntentClick (selectedIntent) {
|
||||
|
||||
if (selectedIntent.intentName.length < INTENT_NAME_MIN_LENGTH){
|
||||
Popup.alert ('Question name should have at least 2 characters');
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedIntent.answer.length < ANSWER_MIN_LENGTH){
|
||||
Popup.alert('Answer should have at least 2 characters');
|
||||
return;
|
||||
}
|
||||
|
||||
for(let i=0;i<selectedIntent.questions.length;i++){
|
||||
if (selectedIntent.questions[i].length < QUESTION_MIN_LENGTH){
|
||||
Popup.alert('Question variant should have at least 2 characters');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Check for same question variants and same question name in other intents
|
||||
|
||||
for (let i=0;i<this.state.allIntents.length;i++){
|
||||
if (i!==this.state.selectedIndex){
|
||||
if (selectedIntent.intentName === this.state.allIntents[i].intentName){
|
||||
Popup.alert('Question name already exists');
|
||||
return;
|
||||
}
|
||||
|
||||
for(let j=0;j<selectedIntent.questions.length;j++){
|
||||
for (let k=0;k<this.state.allIntents[i].questions.length;k++){
|
||||
if (selectedIntent.questions[j] === this.state.allIntents[i].questions[k]){
|
||||
Popup.alert('Question variant already exists (in question :' + this.state.allIntents[i].intentName + ')');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let newAllIntentsJSON = JSON.stringify (this.state.allIntents);
|
||||
let newAllIntents = JSON.parse (newAllIntentsJSON);
|
||||
|
||||
let newState = null;
|
||||
let resolveState = null;
|
||||
let rejectState = {waiting:false}
|
||||
|
||||
if (this.state.selectedIndex === NEW_INTENT_SELECTED_INDEX) {
|
||||
//new intent
|
||||
newAllIntents.push (selectedIntent);
|
||||
newState = {
|
||||
resolveState = {
|
||||
allIntents: newAllIntents,
|
||||
selectedIntent: selectedIntent,
|
||||
selectedIndex: newAllIntents.length - 1,
|
||||
@@ -231,18 +287,18 @@ class App extends Component {
|
||||
};
|
||||
} else {
|
||||
newAllIntents[this.state.selectedIndex] = selectedIntent;
|
||||
newState = {
|
||||
resolveState = {
|
||||
allIntents: newAllIntents,
|
||||
selectedIntent: selectedIntent,
|
||||
waiting: false,
|
||||
waiting:false,
|
||||
};
|
||||
}
|
||||
this.setState ({waiting: true});
|
||||
this.sendSkill (
|
||||
newAllIntents,
|
||||
true,
|
||||
newState,
|
||||
{waiting: false},
|
||||
resolveState,
|
||||
rejectState,
|
||||
this.state.invocationName,
|
||||
this.state.invocationAnswer,
|
||||
this.state.contactEmail,
|
||||
|
||||
@@ -103,28 +103,28 @@ class IntentDetails extends Component {
|
||||
}
|
||||
|
||||
handleQuestionEdit(e,index){
|
||||
if (e.length === QUESTION_MAX_LENGTH) return;
|
||||
if (e.length === QUESTION_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.questions[index] = e;
|
||||
this.setState({intent: newIntent});
|
||||
}
|
||||
|
||||
handleIntentExplanationEdit(e,index){
|
||||
if (e.length === INTENT_EXPLANATION_MAX_LENGTH) return;
|
||||
if (e.length === INTENT_EXPLANATION_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.intentExplanation = e;
|
||||
this.setState({intent: newIntent});
|
||||
}
|
||||
|
||||
handleAnswerEdit(e){
|
||||
if (e.length === ANSWER_MAX_LENGTH) return;
|
||||
if (e.length === ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.answer = e;
|
||||
this.setState({intent: newIntent});
|
||||
}
|
||||
|
||||
handleIntentNameEdit(e){
|
||||
if (e.length === INTENT_NAME_MAX_LENGTH) return;
|
||||
if (e.length === INTENT_NAME_MAX_LENGTH || !(/^[a-z]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.intentName = e;
|
||||
this.setState({intent: newIntent});
|
||||
|
||||
@@ -52,12 +52,12 @@ class LaunchRequest extends Component {
|
||||
}
|
||||
|
||||
handleNameEdit(e){
|
||||
if (e.length === INVOCATION_NAME_MAX_LENGTH) return;
|
||||
if (e.length === INVOCATION_NAME_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
this.setState({invocationName: e});
|
||||
}
|
||||
|
||||
handleAnswerEdit(e){
|
||||
if (e.length === INVOCATION_ANSWER_MAX_LENGTH) return;
|
||||
if (e.length === INVOCATION_ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
this.setState({invocationAnswer: e});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
export const INTENT_NAME_MAX_LENGTH = 30;
|
||||
export const INTENT_EXPLANATION_MAX_LENGTH = 70;
|
||||
|
||||
export const INTENT_NAME_MAX_LENGTH = 30;
|
||||
export const INTENT_NAME_MIN_LENGTH = 2;
|
||||
|
||||
export const QUESTION_MAX_LENGTH = 150;
|
||||
export const QUESTION_MIN_LENGTH = 2;
|
||||
|
||||
export const ANSWER_MAX_LENGTH = 150;
|
||||
export const ANSWER_MIN_LENGTH = 2;
|
||||
|
||||
export const INTENT_TITLE_MAX_LENGTH = 20;
|
||||
export const INTENT_TITLE_TOOLTIP_DELAY = 700;
|
||||
|
||||
export const INVOCATION_NAME_MAX_LENGTH = 15;
|
||||
export const INVOCATION_NAME_MAX_LENGTH = 50;
|
||||
export const INVOCATION_NAME_MIN_LENGTH = 2;
|
||||
export const INVOCATION_ANSWER_MAX_LENGTH = 100;
|
||||
|
||||
export const EMAIL_MAX_LENGTH = 100;
|
||||
|
||||
5
web/src/lib/helpers.js
Normal file
5
web/src/lib/helpers.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export const isEmailValid = email => {
|
||||
let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
|
||||
return validEmailRegex.test (email);
|
||||
};
|
||||
Reference in New Issue
Block a user