Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking if entry is iterable before looping over it #34

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aramix
Copy link

@aramix aramix commented Mar 26, 2018

No description provided.

@rickydunlop
Copy link
Owner

I'm curious as to why you need to do this? As per the docs this will always be an

Array containing one messaging object

https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/#payload

@rickydunlop
Copy link
Owner

Closing this as it's unnecessary

@aramix
Copy link
Author

aramix commented May 31, 2018

@rickydunlop sorry just noticed this. I was actually not getting an array in some cases, that's why I added this check to avoid problems when trying to loop over a non-array values. I'll add an example tomorrow.

@aramix
Copy link
Author

aramix commented Jun 2, 2018

@rickydunlop even with the latest v5.0.1 I am still getting the error that made me add a check for it.
I have this part:

postRoutes.route("/webhook", function(params, req, res, next) {
  res.statusCode = 200;
  // console.log(JSON.stringify(req.body));
  // {"object":"page","entry":[{"id":"1961252584091590","time":1527918002661,"standby":[{"recipient":{"id":"1961252584091590"},"timestamp":1527918002661,"sender":{"id":"1705001502946197"},"postback":{"title":"Who's nearby"}}]}]}
  // as you can see in the above response there is no "messaging" array, so when it gets passed
  // to fbmessenger's handle method it tries to loop over a nonexistent key and crashes.
  cbot.handle(req.body); // <------------------- Error is being thrown here (server/router.js:98:8)
  res.end();
  // DEBUG
  console.log("END POST ROUTE");
});

where cbot is fbmessenger
error stacktrace:

2018-06-02T05:14:48.877175+00:00 app[web.1]: TypeError: Cannot read property 'forEach' of undefined
2018-06-02T05:14:48.877177+00:00 app[web.1]:     at entries.forEach.entry (/app/.meteor/heroku_build/app/programs/server/npm/node_modules/fbmessenger/dist/Messenger.js:50:23)
2018-06-02T05:14:48.877179+00:00 app[web.1]:     at Array.forEach (<anonymous>)
2018-06-02T05:14:48.877187+00:00 app[web.1]:     at Messenger.handle (/app/.meteor/heroku_build/app/programs/server/npm/node_modules/fbmessenger/dist/Messenger.js:49:13)
2018-06-02T05:14:48.877189+00:00 app[web.1]:     at server/router.js:98:8
2018-06-02T05:14:48.877191+00:00 app[web.1]:     at doCall (packages/meteorhacks_picker.js:128:14)
2018-06-02T05:14:48.877193+00:00 app[web.1]:     at PickerImp._processRoute (packages/meteorhacks_picker.js:122:5)
2018-06-02T05:14:48.877195+00:00 app[web.1]:     at processNextRoute (packages/meteorhacks_picker.js:90:14)
2018-06-02T05:14:48.877197+00:00 app[web.1]:     at processNextMiddleware (packages/meteorhacks_picker.js:78:7)
2018-06-02T05:14:48.877198+00:00 app[web.1]:     at PickerImp._dispatch (packages/meteorhacks_picker.js:72:3)
2018-06-02T05:14:48.877200+00:00 app[web.1]:     at processNextSubRouter (packages/meteorhacks_picker.js:102:17)
2018-06-02T05:14:48.877202+00:00 app[web.1]:     at PickerImp._dispatch (packages/meteorhacks_picker.js:68:14)
2018-06-02T05:14:48.877203+00:00 app[web.1]:     at processNextSubRouter (packages/meteorhacks_picker.js:102:17)
2018-06-02T05:14:48.877205+00:00 app[web.1]:     at processNextRoute (packages/meteorhacks_picker.js:95:7)
2018-06-02T05:14:48.877206+00:00 app[web.1]:     at processNextMiddleware (packages/meteorhacks_picker.js:78:7)
2018-06-02T05:14:48.877208+00:00 app[web.1]:     at urlencodedParser (/app/.meteor/heroku_build/app/programs/server/npm/node_modules/body-parser/lib/types/urlencoded.js:82:7)

@rickydunlop
Copy link
Owner

Hi @aramix, Thanks for the stacktrace, it has helped me track the issue.
It looks like you're using the handover protocol is that correct?
If so, it's currently unsupported in this lib but should be easy to add support for it

@rickydunlop rickydunlop reopened this Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants