Skip to content

Commit b88cdf8

Browse files
committed
Add Public folder
1 parent 9496e97 commit b88cdf8

File tree

17 files changed

+516
-160
lines changed

17 files changed

+516
-160
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"browser": true,
44
"commonjs": true,
55
"es2021": true,
6-
"node": true
6+
"node": true,
7+
"jquery": true
78
},
89
"extends": [
910
"airbnb-base"

index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { upperCaseFirst } = require("upper-case-first");
88

99
const cors = require("cors");
1010
const morgan = require("morgan");
11+
const dotenv = require("dotenv");
1112
const express = require("express");
1213
const compression = require("compression");
1314

@@ -16,14 +17,16 @@ const welcomeChat = require("./intents/Default_Welcome.json");
1617
const fallbackChat = require("./intents/Default_Fallback.json");
1718
const unitConverterChat = require("./intents/unit_converter.json");
1819

20+
dotenv.config();
21+
1922
const app = express();
2023
const port = process.env.PORT || 3000;
2124

2225
const allQustions = [];
2326

2427
for (let i = 0; i < mainChat.length; i++) {
25-
for (let j = 0; j < mainChat[i].qus.length; j++) {
26-
allQustions.push(mainChat[i].qus[j]);
28+
for (let j = 0; j < mainChat[i].questions.length; j++) {
29+
allQustions.push(mainChat[i].questions[j]);
2730
}
2831
}
2932

@@ -82,7 +85,8 @@ const sendAnswer = (req, res) => {
8285

8386
if (regExforUnitConverter.test(humanInput)) {
8487
const similarQuestionObj = stringSimilarity.findBestMatch(humanInput, unitConverterChat).bestMatch;
85-
const valuesObj = extractValues(humanInput, similarQuestionObj.target, {
88+
similarQuestion = similarQuestionObj.target;
89+
const valuesObj = extractValues(humanInput, similarQuestion, {
8690
delimiters: ["{", "}"],
8791
});
8892

@@ -109,15 +113,16 @@ const sendAnswer = (req, res) => {
109113

110114
if (similarQuestionRating > 0.5) {
111115
for (let i = 0; i < mainChat.length; i++) {
112-
for (let j = 0; j < mainChat[i].qus.length; j++) {
113-
if (similarQuestion == mainChat[i].qus[j]) {
114-
responseText = _.sample(mainChat[i].ans);
116+
for (let j = 0; j < mainChat[i].questions.length; j++) {
117+
if (similarQuestion == mainChat[i].questions[j]) {
118+
responseText = _.sample(mainChat[i].answers);
115119
rating = similarQuestionRating;
116120
}
117121
}
118122
}
119123
} else {
120124
isFallback = true;
125+
action = "Default_Fallback";
121126
if (humanInput.length <= 20 && !/(\s{1,})/gmi.test(humanInput)) {
122127
responseText = "You are probably hitting random keys :D";
123128
} else {
@@ -135,8 +140,12 @@ const sendAnswer = (req, res) => {
135140
similarQuestion,
136141
});
137142
} catch (error) {
138-
res.status(500).send({ error: "Internal Server Error!", code: 500 });
139143
console.log(error);
144+
if ((error.message).includes("URI")) {
145+
res.status(500).send({ error: error.message, code: 500 });
146+
} else {
147+
res.status(500).send({ error: "Internal Server Error!", code: 500 });
148+
}
140149
}
141150
};
142151

0 commit comments

Comments
 (0)