messagix: Receive Instagram typing indicators#156
Merged
radon-at-beeper merged 29 commits intomainfrom Sep 10, 2025
Merged
Conversation
tulir
reviewed
Sep 9, 2025
tulir
reviewed
Sep 10, 2025
Member
tulir
left a comment
There was a problem hiding this comment.
Otherwise looks good except slightly too much of the code moved inside if platform == instagram
tulir
approved these changes
Sep 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Receive typing indicators from Instagram. This required reverse-engineering a totally novel websocket API that it seems nobody else on the Internet (that I was able to find) had published details of. Note that, surprisingly, typing indicators are sent via the same API on both Facebook and Instagram; however, they are only received using that same API on Facebook, instead being received via the other API on Instagram.
In
messagix/dgwI have provided a reusable client for interacting with this API, which is able to encode and decode a subset of the available message frame types, enough to subscribe to typing indicators and parse those received. Received DGW messages are sent back to the bridge connector and handled inhandleMetaEventsimilarly to Lightspeed messages.There are special ID schemas for Instagram, one used for user IDs and one used for thread IDs. Therefore, to interpret received typing indicators, the bridge must look up the corresponding FBIDs for these legacy IDs. The thread ID information was already being received as an additional message (
LSDeleteThenInsertIgThreadInfo) that the bridge was not previously aware of, but the user ID information is only sometimes sent (inLSDeleteThenInsertIGContactInfo), and therefore I needed to update the bridge to react toLSVerifyContactRowExistsby queuing aGetContactsFullTaskfor any contacts still missing information; this gives parity with the behavior of the web client. Instagram user and thread IDs are stored persistently in the attached database, since they are not expected to change over time. There are wrapper methods for handling both the in-memory and database caches of these ID types.I wanted to separate out the DGW socket code into a separate module, but this required moving around a few other symbols that the Lightspeed socket code was accessing as private members. Most egregiously I am passing in a
MessagixClientinterface to the DGW module, since otherwise there would be an import cycle. Let me know if you can think of a way to improve the modularity.The DGW socket code was originally based upon the Lightspeed socket code, but was rewritten to be more clearly correct to me from a concurrency perspective.
This has been tested to work with receiving Instagram typing notifications from another person who is typing in the Instagram web client, when I am using Beeper desktop with the self-hosted Instagram bridge running locally.