node-red-contrib-chatbot icon indicating copy to clipboard operation
node-red-contrib-chatbot copied to clipboard

Facebook Receive does not receive message

Open webfrank opened this issue 5 years ago • 6 comments

Hi, I have Node-Red 0.20.2 and node-red-contrib-chatbot 0.16.6 and I cannot receive messages with facebook. If I sniff with tcpdump I can see facebook post but inside the code lib/platforms/facebook/facebook.js at line 45: var json = req.body I see req.body is undefined but facebook posts a correct json.

webfrank avatar Mar 27 '19 16:03 webfrank

I did a quick test with the sandbox

https://github.com/guidone/redbot-facebook-sandbox

and following the tutorial

https://github.com/guidone/node-red-contrib-chatbot/wiki/Facebook-Receiver-node

And it worked. Are you using Node-RED standalone or in an Express instance? Other users had this error using Node-RED in a custom instance of Express, in that case they solved the problem by adding the bodyparser middleware.

guidone avatar Mar 28 '19 08:03 guidone

I'm using Node-red standalone and I followed the wiki (prior to upgrading to latest version it was working fine)

webfrank avatar Mar 28 '19 09:03 webfrank

Does it work if you downgrade? There are no changes in the Fb engine in the last versions

guidone avatar Apr 01 '19 07:04 guidone

Yes, if downgrade works again

webfrank avatar Apr 04 '19 14:04 webfrank

Hi, I solved this way, in file lib/chat-platform/chat-platform.js:

  • added var bodyParser = require('body-parser');
  • in function mountRoutes before RED.httpNode.use(route, middleware.bind(chatServer)); I added RED.httpNode.use(bodyParser.json());

This way I can receive Facebook Messenger messages and bot returned to work properly

webfrank avatar Apr 24 '19 14:04 webfrank

OK thanks, this is strange, node-red should already have the body parsers in the middlewares. Let me check if it conflicts with my version of node-red/red-bot and then let's add to master

guidone avatar Apr 24 '19 14:04 guidone