Search code examples
node.jsbotkit

botkit-sms: Integrating middleware plugin


I'm trying to api.ai middleware plugin with botkit-sms, I'm tryting to debug the source code, why this isn't working, but will be helpful if you can provide some input

Source code of the library https://github.com/krismuniz/botkit-sms/

var apiai = require('botkit-middleware-apiai')({
  token: '...',
  skip_bot: true // or false. If true, the middleware don't send the bot reply/says to api.ai
})

controller.middleware.receive.use(apiai.receive)

controller.hears('.*', 'message_received', apiai.hears, function (bot, message) {
  console.log('received :: ' + message)
  bot.reply(message, 'got the message')
})

Solution

  • Passing apiai.hears into the hears function here changes how pattern matching and hears works. You are now matching intents instead of user using regex on user input.

    But the issue is that API.ai middleware uses an === operator when matching, not regex. So the pattern .* won't match anything unless you have an intent named that.