Skip to content

Commit

Permalink
Various bugfixes on find-artist, sentences, logger fields and languag…
Browse files Browse the repository at this point in the history
…e detection.
  • Loading branch information
Claudio Scalzo committed Jun 22, 2018
1 parent 2475ea6 commit 8920e02
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fbController.setupWebserver(
);

// LOAD 'SpellChecker' MIDDLEWARE
var spellCheckerMiddleware = require('./spell-checker-middleware.js')()
var spellCheckerMiddleware = require('./spell-checker-middleware.js')();

// LOAD 'Dialogflow' MIDDLEWARE
var dialogflowMiddleware = require('botkit-middleware-dialogflow')({
Expand Down
2 changes: 1 addition & 1 deletion dialogflow/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.showWorks = function showWorks(request, response, askForAdditiona

if (filterCounter <= 2 && askForAdditionalFilters == true) {

const speech = "Uhm... sure! Do you want to add some filters?";
const speech = "Uhm... sure! Do you want to add some filters? Like the artist, instruments, genre or composition period.";
const message = request.body.result.resolvedQuery;
const lang = request.body.lang.slice(0,2);
const confidence = request.body.result.score;
Expand Down
15 changes: 7 additions & 8 deletions doremus/bot_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const slackCards = require("../slack/slack_cards.js");
const fbCards = require("../facebook/facebook_cards.js");
const botVars = require("../bot.js");
var spellCheckerMiddleware = botVars.spellCheckerMiddleware
var spellCheckerMiddleware = botVars.spellCheckerMiddleware;

// FUNCTIONS

Expand All @@ -23,8 +23,7 @@ module.exports.sendClearContext = function sendClearContext(sessionID) {

function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
console.log(response);
console.log("Context successfully deleted.");
}
}
request(options, callback);
Expand Down Expand Up @@ -160,7 +159,7 @@ module.exports.doQuery = function doQuery(artist, number, instrument, strictly,
// RESPONSE
if (json["results"]["bindings"].length === 0) {

var currentLang = spellCheckerMiddleware.currentLang;
var currentLang = spellCheckerMiddleware.currentLang();
if (currentLang === "fr") {
bot.reply(message, "Desolé... Je n'ai trouvé rien!");
} else {
Expand Down Expand Up @@ -240,7 +239,7 @@ module.exports.doQueryPerformance = function doQueryPerformance(number, city, st
// RESPONSE
if (json["results"]["bindings"].length === 0) {

var currentLang = botVars.currentLang;
var currentLang = spellCheckerMiddleware.currentLang();
if (currentLang === "fr") {
bot.reply(message, "Desolé... Je n'ai trouvé rien!");
} else {
Expand Down Expand Up @@ -336,7 +335,7 @@ module.exports.doQueryFindArtist = function doQueryFindArtist(num, startdate, en
// RESPONSE
if (json["results"]["bindings"].length === 0) {

var currentLang = botVars.currentLang;
var currentLang = spellCheckerMiddleware.currentLang();
if (currentLang === "fr") {
bot.reply(message, "Desolé... Je n'ai trouvé rien!");
} else {
Expand Down Expand Up @@ -416,7 +415,7 @@ module.exports.answerBio = function answerBio(artist, platform, bot, message) {

var row = json["results"]["bindings"][0];
if (row == undefined) {
bot.reply(message, "Sorry, there was an error! Retry later.");
bot.reply(message, "Sorry, I can't find the artist you're looking for!");
} else {
name = row["name"]["value"];
bio = row["bio"]["value"];
Expand Down Expand Up @@ -471,7 +470,7 @@ module.exports.answerBioSmallAsText = function answerBioSmallAsText(artist, bot,

var row = json["results"]["bindings"][0];
if (row == undefined) {
bot.reply(message, "Sorry, there was an error! Retry later.");
bot.reply(message, "Sorry, I can't find the artist you're looking for!");
} else bot.reply(message, row["bio"]["value"]);
});
}
3 changes: 3 additions & 0 deletions facebook/facebook_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ module.exports.findPerformance = botVars.fbController.hears('find-performance',
// HELLO INTENT
module.exports.hello = botVars.fbController.hears('hello', 'message_received', botVars.dialogflowMiddleware.hears, function(bot, message) {

// Clear the context
botFunctions.sendClearContext(message.nlpResponse.sessionId);

bot.reply(message, message['fulfillment']['speech']);
log.write(bot.type, message.user, message.channel, "hello",
'"' + message['fulfillment']['speech'] + '"',
Expand Down
3 changes: 1 addition & 2 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require('path');
const underscore = require('underscore');
const logFile = {};
const logDir = process.env.log_folder;
const threshold = 100*1024*1024;

// FUNCTION TO CHECK IF DIRECTORY EXISTS
function directoryExists(path) {
Expand Down Expand Up @@ -41,7 +40,7 @@ module.exports = function() {
fs.mkdirSync(logDir);
}

logger.write = function(platform, user, team, intent, response, rawMessage, cleanMessage, lang, confidence) {
logger.write = function(platform, user, team, intent, response, cleanMessage, rawMessage, lang, confidence) {

// sanitize
response = response.replace(',','');
Expand Down
25 changes: 20 additions & 5 deletions slack/slack_io.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SLACK HEARS */

var botVars = require("../bot.js");
var spellCheckerMiddleware = botVars.spellCheckerMiddleware
var spellCheckerMiddleware = botVars.spellCheckerMiddleware;
var botFunctions = require("../doremus/bot_functions.js");

var log = botVars.log;
Expand All @@ -10,9 +10,12 @@ var log = botVars.log;
module.exports.worksBy = botVars.slackController.hears(['works-by'], 'direct_message, direct_mention, mention', botVars.dialogflowMiddleware.hears, function(bot, message) {

if (message.text !== message.old) {

var understoodText = (spellCheckerMiddleware.currentLang() === "en") ? "I understood: " : "J'ai compris: ";

bot.reply(message, {
"attachments": [{
text: "I understood: " + message["text"],
text: understoodText + message["text"],
color: "warning"
}]
});
Expand Down Expand Up @@ -147,9 +150,12 @@ module.exports.worksBySomething = botVars.slackController.hears(['works-by-artis
module.exports.findArtist = botVars.slackController.hears(['find-artist'], 'direct_message, direct_mention, mention', botVars.dialogflowMiddleware.hears, function(bot, message) {

if (message.text !== message.old) {

var understoodText = (spellCheckerMiddleware.currentLang() === "en") ? "I understood: " : "J'ai compris: ";

bot.reply(message, {
"attachments": [{
text: "I understood: " + message["text"],
text: understoodText + message["text"],
color: "warning"
}]
});
Expand Down Expand Up @@ -192,9 +198,12 @@ module.exports.findArtist = botVars.slackController.hears(['find-artist'], 'dire
module.exports.discoverArtist = botVars.slackController.hears(['discover-artist'], 'direct_message, direct_mention, mention', botVars.dialogflowMiddleware.hears, function(bot, message) {

if (message.text !== message.old) {

var understoodText = (spellCheckerMiddleware.currentLang() === "en") ? "I understood: " : "J'ai compris: ";

bot.reply(message, {
"attachments": [{
text: "I understood: " + message["text"],
text: understoodText + message["text"],
color: "warning"
}]
});
Expand Down Expand Up @@ -227,9 +236,12 @@ module.exports.discoverArtist = botVars.slackController.hears(['discover-artist'
module.exports.findPerformance = botVars.slackController.hears(['find-performance'], 'direct_message, direct_mention, mention', botVars.dialogflowMiddleware.hears, function(bot, message) {

if (message.text !== message.old) {

var understoodText = (spellCheckerMiddleware.currentLang() === "en") ? "I understood: " : "J'ai compris: ";

bot.reply(message, {
"attachments": [{
text: "I understood: " + message["text"],
text: understoodText + message["text"],
color: "warning"
}]
});
Expand Down Expand Up @@ -277,6 +289,9 @@ module.exports.findPerformance = botVars.slackController.hears(['find-performanc
// HELLO INTENT
module.exports.hello = botVars.slackController.hears(['hello'], 'direct_message, direct_mention, mention', botVars.dialogflowMiddleware.hears, function(bot, message) {

// Clear the context
botFunctions.sendClearContext(message.nlpResponse.sessionId);

bot.reply(message, message['fulfillment']['speech']);
log.write(bot.type, message.user, message.channel, "hello",
'"' + message['fulfillment']['speech'] + '"',
Expand Down
9 changes: 4 additions & 5 deletions spell-checker-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ greetings["good evening"] = true;
greetings["hey"] = true;
greetings["bonjour"] = true;
greetings["bonsoir"] = true;
greetings["salut"] = true;


// FUNCTION TO DETECT IF MESSAGE IS GREETING
var isGreetings = function(message) {
var lowerCaseMessage = message.text.toLowerCase();
var lowerCaseMessage = message.text.toLowerCase().replace(/[.,\/#!?$%\^&\*;:{}=_`~()]/g,'');
if (greetings[lowerCaseMessage]) return true;
return false;
}
Expand Down Expand Up @@ -110,7 +109,7 @@ module.exports = function() {
qs: parameters
}, function(err, response, body) {
if (err) {
console.error("Error during language detection");
console.error("Error during language detection!");
next(err);
}

Expand All @@ -130,7 +129,7 @@ module.exports = function() {

// SPELL CHECKING
// perform the misspelling with the (potentially) updated speller
var strippedMessage = message.text.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,'');
var strippedMessage = message.text.replace(/[.,\/#!?$%\^&\*;:{}=_`~()]/g,'');
var cleanMessage = performMisspellingCheck(strippedMessage);

message.old = strippedMessage;
Expand All @@ -156,7 +155,7 @@ module.exports = function() {
return;
}

middleware.currectLang = function() {
middleware.currentLang = function() {
return currentLang;
}

Expand Down

0 comments on commit 8920e02

Please sign in to comment.