Bot - Random Salutation #2
//See:https://github.com/DanielEgan/botstarter/blob/master/app/recognizers/greeting.js
//Also: bot0
greeting.js
const greetings = [
'hi',
'hi there',
'hey',
'hey there',
'hello',
'hello hello',
'hello there',
'what up',
'what\'s up',
'whatup',
'salute',
'morning',
'good morning',
'how are you',
'how r u'
];
module.exports = {
recognize: function(context, callback) {
const text = context.message.text.replace(/[!?,.\/\\\[\]\{\}\(\)]/g, '').toLowerCase();
let isGreeting = greetings.some(g => text === g);
let recognized = {
entities: [],
intent: (isGreeting ? 'greeting' : null),
matched: undefined,
expression: undefined,
intents: [],
score: (isGreeting ? 1 : 0)
}
callback.call(null, null, recognized);
}
};
app.js
const greeting = require('./app/recognizers/greeting'); //A
var recognizerLuis = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL);
var intents = new builder.IntentDialog({
recognizers: [
greeting, //A
ending, //B
smiles, //C
startup, //D
recognizerLuis //LUIS
],
intentThreshold: 0.2,
recognizeOrder: builder.RecognizeOrder.series
});
intents.matches('Greeting', '/welcome'); //A
welcome.js
module.exports = function(bot) {
bot.dialog('/welcome', [
function (session, args, next) {
const lastVisit = session.userData.lastVisit;
session.send(['Hello!', 'Hi there!', 'Hi!']); //Choose one of the three
session.send ('Good ' + amPm());
if (!lastVisit) {
session.send('It's a pleasure to meet you');
session.userData = Object.assign({}, session.userData, {
lastVisit: new Date()
});
session.save();
} else {
session.send('Glad you\'re back!');
}
session.endDialog('How can I help you?');
}
]);
};