howdyai / botkit-middleware-witai

Middleware for using Wit.ai with Botkit-powered bots
MIT License
87 stars 49 forks source link

TypeError: Cannot read property 'id' of undefined #16

Closed neogeek closed 3 years ago

neogeek commented 7 years ago

I'm running into an error while using this middleware along with the example code from the README. My experience with Botkit and Wit.ai is limited so I'm not sure if it's something I'm doing incorrectly or an actual bug.

I've included the code I'm testing with and the output of the console.

const Botkit = require('botkit');

const controller = Botkit.facebookbot({
    'access_token': process.env.FACEBOOK_PAGE_TOKEN,
    'verify_token': process.env.VERIFY_TOKEN
});

const wit = require('botkit-middleware-witai')({
    'token': process.env.WITAI_TOKEN
});

controller.middleware.receive.use(wit.receive);

controller.setupWebserver(process.env.PORT, (err, webserver) => {

    controller.createWebhookEndpoints(webserver, controller.spawn());

});

controller.hears(['hello'], 'message_received', wit.hears, (bot, message) => {

    bot.reply(message, 'hi!');

});
{
  "engines": {
    "node": ">=6.0"
  },
  "dependencies": {
    "botkit": "0.4.0",
    "botkit-middleware-witai": "howdyai/botkit-middleware-witai"
  }
}
Click to expand ``` 14:55:41 web.1 | info: ERROR IN RECEIVE MIDDLEWARE: TypeError: Cannot read property 'id' of undefined 14:55:41 web.1 | at Ware.middleware.receive (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/botkit-middleware-witai/src/botkit-middleware-witai.js:34:62) 14:55:41 web.1 | at Ware. (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/wrap-fn/index.js:45:19) 14:55:41 web.1 | at next (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/ware/lib/index.js:85:20) 14:55:41 web.1 | at Ware.run (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/ware/lib/index.js:88:3) 14:55:41 web.1 | at Object.Botkit.botkit.receiveMessage (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/botkit/lib/CoreBot.js:973:35) 14:55:41 web.1 | at /Users/scottdoxey/git/github/scottdoxeybot/node_modules/botkit/lib/Facebook.js:202:45 14:55:41 web.1 | at Layer.handle [as handle_request] (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/layer.js:95:5) 14:55:41 web.1 | at next (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/route.js:131:13) 14:55:41 web.1 | at Route.dispatch (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/route.js:112:3) 14:55:41 web.1 | at Layer.handle [as handle_request] (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/layer.js:95:5) ```