I am working on a console bot (it's the console_bot.js example from Botkit). Setup agent on DialogFlow console, downloaded son file with private key, downloaded botkit-middleware-dialogflow.
This is the actual code:
var Botkit = require('./lib/Botkit.js');
var os = require('os');
var controller = Botkit.consolebot({
debug: true,
});
const dialogflowMiddleware = require('botkit-middleware-dialogflow')({
keyFilename: './botkit-test-file.json', // service account private key file from Google Cloud Console
});
//******************* */
var bot = controller.spawn();
controller.middleware.receive.use(dialogflowMiddleware.receive);
controller.middleware.send.use(function(bot, message, next) {
if (message.intent == 'hey') {
message.text = 'Hello from DialogFlow!!!';
}
console.log('SENDING ', message.text,'TO USER', message.text);
next();
});
//lifecycle convo events
controller.on('conversationStarted', function(bot, convo) {
console.log('----------------> A conversation started with ', convo.context.user);
});
controller.on('conversationEnded', function(bot, convo) {
console.log('<----------------- A conversation ended with ', convo.context.user);
});
controller.hears(['Default Welcome Intent'], 'direct_message', dialogflowMiddleware.hears, function(bot, message) {
var replyText = message.fulfillment.text; // message object has new fields added by Dialogflow
bot.reply(message, replyText);
});
After setting debug mode on, i got these lines in the console:
debug: Setting up a handler for conversationStarted
debug: Setting up a handler for conversationEnded
debug: Setting up a handler for direct_message
hey
debug: RECEIVED MESSAGE
debug: CUSTOM FIND CONVO user text
This is the problem: when i type the utterances that should trigger the DF intent ('hey', for example), the bot doesn't reply anything