Nerixyz / instagram_mqtt

Realtime and Push Notification (FBNS) support for the instagram-private-api
MIT License
244 stars 49 forks source link

"replied_to_message" field missing for messages on /ig_message_sync #93

Open motiwalam opened 2 years ago

motiwalam commented 2 years ago

When replying to a message, there should be a "replied_to_message" field that is not present when listening with this API.

I know the field should be present because I see it in the browser.

I also know the field is actually missing and not just discarded in the parsing process because I am listening for messages emitted at "/ig_message_sync" (this is also the path the browser listens at) directly through the mqtt client and the field is still absent.

Any ideas on why this field is missing?

Nerixyz commented 2 years ago

This might be because the capabilities of the client aren't updated.

motiwalam commented 2 years ago

Can you direct me to as to where I should start on fixing this?

Nerixyz commented 2 years ago

There's

  1. client_capabilities here
  2. capabilitiesHeader from the parent library here
  3. And the app constants here

Most of them are probably outdated.

Keep in mind I haven't tinkered that much with instagram lately.

motiwalam commented 2 years ago

Okay, I've got it working. I'll issue a pull request sometime later, but until then I'll detail the changes I made for anyone else who has this problem.

First, I updated the capabilitiesHeader to be the one used by my app. It is now 3brTv10=. Then, I updated the app constants to be the one used by my app. These are now:

Now, the real problem is that, given these app constants, the server expects a different authorization system. Cookies are no longer used: instead, the server sends custom headers that contain the relevant information.

Updating the codebase to reflect this change will probably require a lot more changes, but so far, it seems the bare minimum is the following:

  1. change this line to authorization=${this.ig.state.authorization}
  2. change this line to return this.dsUserId;
  3. update this function to include a new if clause for the ig-set-ig-u-ds-user-id header and use its value to set the dsUserId on this.client.state
  4. add a line after this one to throw an error if uid is undefined. This is so the catch statement fires.

I believe that's all. I also changed the BLOKS_VERSION_ID constant but am unsure if that makes a difference.

Needless to say, these are really quite hacky changes, and I will be working on fully updating the codebase. I am not yet fully acquainted with all the code though, so I'd appreciate any pointers you have as to where and how to update everything.

I am also not entirely sure if this is everything needed. Since the cookie jar is now perpetually empty, any other calls to extract something from the cookie jar will result in an error. It hasn't caused a problem in my use cases so far, but I have not done exhaustive testing.

Until then, it seems that, having done this, the message events emitted by the realtime client will now contain the "replied_to_message" field if such a field exists. Presumably, other events will also be updated.