25 Commits

Author SHA1 Message Date
GotPPay
779e2d61f4 backend user input handling 2018-01-29 23:23:36 +01:00
GotPPay
5e92314938 frontend user input handling 2018-01-29 21:32:24 +01:00
GotPPay
3b5c287ef9 . 2018-01-27 10:53:06 +01:00
GotPPay
7ffbf42da9 update tokens 2018-01-27 03:15:47 +01:00
GotPPay
6b4256b7ab switch to saburly amazon account 2018-01-26 23:21:59 +01:00
GotPPay
e712693dd0 switch to saburly amazon account 2018-01-26 23:21:18 +01:00
GotPPay
220d76c2be test saburly account 2018-01-26 17:46:16 +01:00
GotPPay
2870695b25 Fix regex 2018-01-26 15:35:38 +01:00
GotPPay
bca71604fb Allow only letters for question name 2018-01-25 17:42:17 +01:00
GotPPay
84edb5563f prevent space in question name 2018-01-25 16:09:12 +01:00
GotPPay
9b58f7745b improve code 2018-01-25 15:56:45 +01:00
GotPPay
b0737efb4e add missing spread operator 2018-01-25 15:39:48 +01:00
GotPPay
5d2a15bc93 apply comment from PR 2018-01-25 15:19:30 +01:00
GotPPay
145fff3b51 fix alexa bug with no speak action 2018-01-24 13:14:47 +01:00
GotPPay
4f6c714fa3 Rephrase continuation question 2018-01-24 13:11:35 +01:00
GotPPay
f714fdf70a improve No intent 2018-01-24 13:07:08 +01:00
GotPPay
adc1f1c099 improve default built-in intents 2018-01-24 13:02:46 +01:00
GotPPay
c0a177d39b experiment with yes no help cancel 2018-01-23 14:40:01 +01:00
GotPPay
3700d9bb58 Simulate built-in intents 2018-01-23 13:46:02 +01:00
GotPPay
7a5ddc6b52 Experiment with user-defined help intent 2018-01-23 13:33:53 +01:00
GotPPay
39b8e7608e Test built-in intents 2018-01-23 13:24:56 +01:00
MirnaM
a8ffe0a5c0 Merge pull request #11 from GotPPay/send-message-feature
Send message feature
2018-01-23 12:19:57 +01:00
MirnaM
def591224e Merge pull request #12 from GotPPay/question-explanation
Question explanation
2018-01-23 12:19:14 +01:00
GotPPay
d8b2f5f0b4 fix typo 2018-01-23 12:18:20 +01:00
MirnaM
f6bf3a05b2 Merge pull request #10 from GotPPay/switch-to-alexa-sdk
Switch to alexa sdk
2018-01-19 11:24:23 +01:00
13 changed files with 363 additions and 65 deletions

View File

@@ -1,6 +1,11 @@
To obtain new Auth Code :
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
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
To obtain new Auth Code :
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) :

View File

@@ -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_cTBqjIc9pXljqe7yEVk6JDs7q1zKbBibx_AQm57TO79IzWyLBzBM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gywS-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;

View File

@@ -1,42 +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 : 'Would you like to continue'
}
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,
module.exports = constants;
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;

View File

@@ -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)

View File

@@ -68,6 +68,34 @@ var generateInteractionModel = function (skill) {
allIntents.push ({name: intent.intentName, samples: intent.questions});
});
//Built-In like intents (Amazon built-in don't work, probably something related to existance of dialog intent
allIntents.push ({
name: 'HelpIntent',
samples: ['Help', 'Can you help me', 'I need help'],
slots: [],
},
{
name: 'CancelIntent',
samples: ['Cancel', 'Stop', 'Please stop'],
slots: [],
},
{
name: 'YesIntent',
samples: [
'Yes',
'Yes please',
'I would like that',
'Yes I would like that',
],
slots: [],
},
{
name: 'NoIntent',
samples: ['No', 'No thank you'],
slots: [],
});
//Special intent for sending message (Dialog)
allIntents.push ({

View File

@@ -26,7 +26,7 @@ module.exports = {
return validEmailRegex.test (email);
},
sendEmal: function (name, fromEmail, message, toEmail) {
sendEmail: function (name, fromEmail, message, toEmail) {
return new Promise ((resolve, reject) => {
fromEmail = this.transformEmailFromAlexaResponse(fromEmail);
let messageBody =

View 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;
}
},
};

View File

@@ -34,7 +34,7 @@ module.exports = {
destinationEmail = activeSkill.contactEmail;
let listOfPossibleQuestions = '';
activeSkill.intents.forEach(intent => {
activeSkill.intents.forEach (intent => {
if (intent.questions.length > 0 && intent.intentExplanation) {
listOfPossibleQuestions +=
intent.intentExplanation +
@@ -44,8 +44,7 @@ module.exports = {
'ms"/>';
}
});
console.log(listOfPossibleQuestions);
listOfPossibleQuestions += 'If you dont know what to do, just say help or stop';
//Handler for launch requestconsole.log()
handlers = {
@@ -56,9 +55,10 @@ module.exports = {
'<break time="' +
constants.voiceResponseTimings.PAUSE_AFTER_WELCOME_MESSAGE +
'ms"/>' +
listOfPossibleQuestions
'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.emit (':responseReady');
},
};
@@ -66,6 +66,9 @@ module.exports = {
//Handlers for user defined questions
activeSkill.intents.map (intent => {
handlers[intent.intentName] = function () {
if (this.attributes['LaunchRequestYesNo']){
this.attributes['LaunchRequestYesNo'] = false;
}
this.response
.speak (intent.answer)
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
@@ -75,6 +78,10 @@ module.exports = {
//Handler for sending message
handlers.SendMessageIntent = function () {
if (this.attributes['LaunchRequestYesNo']){
this.attributes['LaunchRequestYesNo'] = false;
}
let intent = this.event.request.intent;
console.log ('Dialog state : ' + this.event.request.dialogState);
@@ -138,7 +145,7 @@ module.exports = {
console.log ('Email : ' + intent.slots.Email.value);
console.log ('Message : ' + intent.slots.Message.value);
emailHelper
.sendEmal (
.sendEmail (
intent.slots.Name.value,
intent.slots.Email.value,
intent.slots.Message.value,
@@ -161,7 +168,48 @@ module.exports = {
}
};
//Default handlers for unknown questions and session close
//Built-In intents
handlers.CancelIntent = function () {
if (this.attributes['LaunchRequestYesNo']){
this.attributes['LaunchRequestYesNo'] = false;
}
this.response.speak ('Thank you for using Saburly');
this.emit (':responseReady');
};
handlers.HelpIntent = function () {
if (this.attributes['LaunchRequestYesNo']){
this.attributes['LaunchRequestYesNo'] = false;
}
this.response
.speak (listOfPossibleQuestions)
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
this.emit (':responseReady');
};
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');
}
}
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');
}
}
//Default handler for unknown question
handlers.Unhandled = function () {
this.response
@@ -169,6 +217,8 @@ module.exports = {
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
};
//Session handlers
handlers.SessionEndedRequest = function () {
//We don't care for now
};

View File

@@ -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,17 +173,21 @@ class App extends Component {
}
handleSaveEmailClick (email) {
this.setState ({waiting: true});
this.sendSkill (
this.state.allIntents,
true,
{contactEmail: email, waiting: false},
{waiting: false},
this.state.invocationName,
this.state.invocationAnswer,
email,
false
);
if (isEmailValid(email)){
this.setState ({waiting: true});
this.sendSkill (
this.state.allIntents,
true,
{contactEmail: email, waiting: false},
{waiting: false},
this.state.invocationName,
this.state.invocationAnswer,
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 resolveState = null;
let rejectState = {waiting:false}
let newState = null;
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,

View File

@@ -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});

View File

@@ -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});
}
}

View File

@@ -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
View 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);
};