0

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

Ethan
  • 45
  • 10
  • What do you mean by "not working"? Does it show you anything in the logs? Have you set debug to true to see what it reports? Please update your question with more information. – Prisoner Dec 17 '18 at 14:39
  • @Prisoner updated question – Ethan Dec 17 '18 at 15:08
  • Fixed it, it was the type of message, message_received instead of direct message. – Ethan Dec 19 '18 at 22:41
  • Go ahead and post an answer for your question as an answer below - that way other people who encounter the same problem will have a clear answer to it. – Prisoner Dec 20 '18 at 00:01

1 Answers1

0

Fixed it, it was the type of message, message_received instead of direct message. So this is the correction:

// USE MESSAGE_RECEIVED, NOT DIRECT MESSAGE
     controller.hears(['Default Welcome Intent'], 'message_received', dialogflowMiddleware.hears, function(bot, message) {
        var replyText = message.fulfillment.text;  
        bot.reply(message, replyText);
      });
Ethan
  • 45
  • 10