botkit-sms:集成中间件插件

botkit-sms: Integrating middleware plugin

我正在尝试 api.ai 带有 botkit-sms 的中间件插件,我正在尝试调试源代码,为什么这不起作用,但如果您能提供一些输入会有所帮助

库的源代码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')
})

在这里将 apiai.hears 传递给 hears 函数会改变模式匹配和 hears 的工作方式。您现在正在匹配意图,而不是用户在用户输入时使用正则表达式。

但问题是 API.ai middleware uses an === operator 匹配时,不是正则表达式。所以模式 .* 不会匹配任何东西,除非你有一个命名的意图。