Schmavery / facebook-chat-api

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

Cannot read property 'id' of null #743

Open k0l0r3k99 opened 4 years ago

k0l0r3k99 commented 4 years ago

When I tried "getThreadHistory", I got:

TypeError: Cannot read property 'id' of null
    at formatEventData (D:\git\fb-api\node_modules\facebook-chat-api\src\getThreadHistory.js:292:28)
    at D:\git\fb-api\node_modules\facebook-chat-api\src\getThreadHistory.js:566:22
    at Array.map (<anonymous>)
    at formatMessagesGraphQLResponse (D:\git\fb-api\node_modules\facebook-chat-api\src\getThreadHistory.js:361:47)
    at D:\git\fb-api\node_modules\facebook-chat-api\src\getThreadHistory.js:624:24
    at tryCatcher (D:\git\fb-api\node_modules\bluebird\js\main\util.js:26:23)
    at Promise._settlePromiseFromHandler (D:\git\fb-api\node_modules\bluebird\js\main\promise.js:510:31)
    at Promise._settlePromiseAt (D:\git\fb-api\node_modules\bluebird\js\main\promise.js:584:18)
    at Promise._settlePromises (D:\git\fb-api\node_modules\bluebird\js\main\promise.js:700:14)
    at Async._drainQueue (D:\git\fb-api\node_modules\bluebird\js\main\async.js:123:16)
    at Async._drainQueues (D:\git\fb-api\node_modules\bluebird\js\main\async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (D:\git\fb-api\node_modules\bluebird\js\main\async.js:15:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)

It's:


    case "InstantGameUpdateExtensibleMessageAdminText":
      return {
        gameID: event.game.id,
        update_type: event.update_type,
        collapsed_text: event.collapsed_text,
        expanded_text: event.expanded_text,
        instant_game_update_data: event.instant_game_update_data
      };

So, event.game can be null. I added console.log(event) and I got:

{ __typename: 'InstantGameUpdateExtensibleMessageAdminText',
  game: null,
  update_type: 'CUSTOM_MESSAGE',
  collapsed_text: 'Przemek officially challenged you to a Wank Match.',
  expanded_text: 'Przemek officially challenged you to a Wank Match.',
  instant_game_update_data:
   { cta_url:
      'fb-messenger://instant_games/play?game_id=2121644868163149&payload=%7B%22data1%22%3A%22challenge%22%2C%22score1%22%3A188%2C%22player1%22%3A%221929104770502011%22%7D',
     cta_title: 'Play',
     photo: { image: [Object] },
     template: 'challenge' } }

JSON.stringify:

{
  "__typename": "InstantGameUpdateExtensibleMessageAdminText",
  "game": null,
  "update_type": "CUSTOM_MESSAGE",
  "collapsed_text": "Przemek officially challenged you to a Wank Match.",
  "expanded_text": "Przemek officially challenged you to a Wank Match.",
  "instant_game_update_data": {
    "cta_url": "fb-messenger://instant_games/play?game_id=2121644868163149&payload=%7B%22data1%22%3A%22challenge%22%2C%22score1%22%3A188%2C%22player1%22%3A%221929104770502011%22%7D",
    "cta_title": "Play",
    "photo": {
      "image": {
        "uri": "https://scontent-vie1-1.xx.fbcdn.net/v/t1.0-9/44089931_1769933356466132_388327672771510272_n.jpg?_nc_cat=108&_nc_oc=AQmQnxyjwoF6qBbvIFU8kvNiBqgRgDidbcuIz7cs6C-QujFEv81SUQCI3ceeUeGt4B4&_nc_ht=scontent-vie1-1.xx&oh=e464d6531defca7745a2798851217d60&oe=5DA3BA6F"
      }
    },
    "template": "challenge"
  }
}
Schmavery commented 4 years ago

Seems like this might be fixed by https://github.com/Schmavery/facebook-chat-api/pull/721