Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.93k stars 596 forks source link

FB contacts #569

Open IvanReznikov opened 6 years ago

IvanReznikov commented 6 years ago

Sometimes, when I'm using getThreadHistoryGraphQL, for example, if there is an attachment, the code might fail: TypeError: Cannot read property 'text' of null at formatExtensibleAttachment (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\facebook-chat-api\src\getThreadHistoryGraphQL.js:132:59) at C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\facebook-chat-api\src\getThreadHistoryGraphQL.js:231:43 at Array.map (native) at formatMessagesGraphQLResponse (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\facebook-chat-api\src\getThreadHistoryGraphQL.js:202:47) at C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\facebook-chat-api\src\getThreadHistoryGraphQL.js:351:24 at tryCatcher (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\util.js:26:23) at Promise._settlePromiseFromHandler (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\promise.js:510:31) at Promise._settlePromiseAt (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\promise.js:584:18) at Promise._settlePromises (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\promise.js:700:14) at Async._drainQueue (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\async.js:123:16) at Async._drainQueues (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\async.js:133:10) at Immediate.Async.drainQueues (C:\Users\MZuckerberg\Documents\API\fbapi\node_modules\bluebird\js\main\async.js:15:14) at runCallback (timers.js:651:20) at tryOnImmediate (timers.js:624:5) at processImmediate [as _immediateCallback] (timers.js:596:5)

Found out why! Try sending a facebook contact... Links in general work

Leo4815162342 commented 6 years ago

It should be fixed by this PR: https://github.com/Schmavery/facebook-chat-api/pull/552/files

IvanReznikov commented 6 years ago

It is still failing in the function formatExtensibleAttachment()

  type: "share",
  description: attachment.story_attachment.description.text,
Leo4815162342 commented 6 years ago

Oh, true, it's from getThreadHistoryGraphQL.js In this case it's a matter of adding the same safe check for decription key as from this PR: https://github.com/Schmavery/facebook-chat-api/pull/562/files to this line: https://github.com/Schmavery/facebook-chat-api/blob/master/src/getThreadHistoryGraphQL.js#L132

Schmavery commented 6 years ago

Even better, if we can identify a field in the object that's missing a description that could be substituted for the description, use that 😄