{"id":26847767,"url":"https://github.com/nerixyz/instagram_mqtt","last_synced_at":"2025-04-06T21:14:44.867Z","repository":{"id":36382397,"uuid":"200295248","full_name":"Nerixyz/instagram_mqtt","owner":"Nerixyz","description":"Realtime and Push Notification (FBNS) support for the instagram-private-api","archived":false,"fork":false,"pushed_at":"2024-04-23T16:18:38.000Z","size":979,"stargazers_count":264,"open_issues_count":33,"forks_count":52,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-27T07:48:37.290Z","etag":null,"topics":["hacktoberfest","instagram","mqtt","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nerixyz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-02T20:39:46.000Z","updated_at":"2025-03-15T18:49:55.000Z","dependencies_parsed_at":"2024-04-06T12:26:41.834Z","dependency_job_id":"bf39ae9d-ba11-441c-813d-2084704a3587","html_url":"https://github.com/Nerixyz/instagram_mqtt","commit_stats":{"total_commits":222,"total_committers":6,"mean_commits":37.0,"dds":0.07207207207207211,"last_synced_commit":"0f80649a0f56fdb7550f9532488485b4b9f342f0"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nerixyz%2Finstagram_mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nerixyz%2Finstagram_mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nerixyz%2Finstagram_mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nerixyz%2Finstagram_mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nerixyz","download_url":"https://codeload.github.com/Nerixyz/instagram_mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550689,"owners_count":20956987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","instagram","mqtt","typescript"],"created_at":"2025-03-30T20:30:48.431Z","updated_at":"2025-04-06T21:14:44.834Z","avatar_url":"https://github.com/Nerixyz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Instagram Realtime and FBNS\n\nThis library isn't actively maintained anymore. Only bug fixes are accepted.\n\n## Getting started\n\n-  Install the library\n\n   ```sh\n   npm i instagram_mqtt\n   ```\n\n-  Extend the `IgApiClient`\n\n   ```typescript\n   import { value IgApiClient } from 'instagram-private-api';\n   import { value withFbnsAndRealtime, value withFbns, value withRealtime } from 'instagram_mqtt';\n\n   // wrap the client\n   // ig is now IgApiClientMQTT for typescript users\n   const ig = withFbnsAndRealtime(new IgApiClient());\n\n   // OR if you only want fbns/realtime\n   const igFbns = withFbns(new IgApiClient());\n   const igRealtime = withRealtime(new IgApiClient());\n\n   // login like you usually do or load the state\n\n   // use ig.realtime and ig.fbns\n   ```\n\n-  [Look at the examples](examples)\n\n## RealtimeClient\n\nThe RealtimeClient is used, as the name implies, for in-app communication.\nEverything using some kind of event is communicating over this client.\n\n### Features\n\n-  Typing Events\n-  Presence Events\n-  Direct Messaging\n-  Live Comments\n-  Live Events\n\n### Events\n\nYour IDE should be able to auto complete the event names for you as Typescript types are in the npm package.\n\n| Name               | Description                                                       | Typed?    |\n| ------------------ | ----------------------------------------------------------------- | --------- |\n| realtimeSub        | Any message sent to `/ig_realtime_sub`                            | partially |\n| direct             | Direct _events_                                                   | yes       |\n| iris               | Any message sent to `/ig_message_sync` not handled by `message`   | partially |\n| message            | Direct messages                                                   | yes       |\n| clientConfigUpdate | Updates to quick experiments (may cause the client to disconnect) | yes       |\n| appPresence        | Presence updates                                                  | yes       |\n| \\\u003ckeyof QueryIDs\\\u003e | Messages regarding the specified query id                         | no        |\n\n## FbnsClient\n\nFBNS is for notifications (so it's readonly).\nYou can subscribe to any notification using\n\n```typescript\nig.fbns.on('push' /* your handler */);\n```\n\nYou can subscribe to a specific event using\n\n```typescript\nig.fbns.on(/* desired collapseKey */, /* your handler */)\n```\n\nNote: this library provides the query (actionPath/Params) as an object (actionParams)\nso you can use `actionParams.YOUR_KEY`.\n\n## Debugging\n\nIn order to debug the clients you can set the environment variable `DEBUG`.\nRecommended is setting it to `ig:mqtt:*`. If you want to debug the entire **instagram-private-api**, set it to `ig:*`.\nCurrently, the emitted \"channels\" are:\n\n-  `ig:mqtt:realtime`\n-  `ig:mqtt:fbns`\n-  `ig:mqtt:mqttot`\n\nIf you want to debug the `mqtts` library set it either to `*` or `ig:*,mqtts:*`.\n\nAn example `.env` file would look like this:\n\n```\nDEBUG=ig:mqtt:*\n```\n\n## Extending\n\n### Mixins\n\nSince version 1.0, there is support for basic mixins.\nA mixin is a class with an `apply()` method (extends [Mixin](src/realtime/mixins/mixin.ts) base class).\nThis method is called once the RealtimeClient is constructed.\nYou can use the `hook()` function to hook into methods (pre and post) and override the return value.\nBy default, the [`MessageSyncMixin`](src/realtime/mixins/message-sync.mixin.ts) and the [`RealtimeSubMixin`](src/realtime/mixins/realtime-sub.mixin.ts) are used.\n\n### TODO\n\n-  Proper descriptions for events\n-  Error handling\n-  Testing... a lot.\n\n## Research\n\nAll scripts to research the mqtt client are in the [`/frida/`](frida) directory.\nAs the name suggests, you'll need [frida](https://frida.re/) for this.\n\nStart frida and connect to the process:\n\n```sh\n# assume frida is running on remote device...\n\nfrida -U -n com.instagram.android -l PATH_TO_SCRIPT\n\n# com.instagram.threadsapp is also valid\n```\n\n| Script                               | Description                                |\n| :----------------------------------- | ------------------------------------------ |\n| [mqttListen.js](frida/mqttListen.js) | Prints all outgoing Realtime-MQTT messages |\n\n## Architecture\n\n### MQTToT\n\nMQTToT is the underlying connection. It uses a modified version of MQTT 3.\nThe modifications are small, but (at least for javascript) may not work with regular MQTT libraries\n(or at least without core modification).\n\n#### Changes\n\n-  **The connect packet** doesn't contain a `clientId`. Instead,\n   it contains a zipped [thrift](https://people.apache.org/~thejas/thrift-0.9/javadoc/org/apache/thrift/protocol/TCompactProtocol.html)-payload.\n   The flags are set to contain a username and password which are in the payload and not as strings in the packet.\n-  **The connack packet** can contain a payload. Regular clients would throw an error\n   as the remaining length should be equal to 0 but in this case it's intended (the MQTT 3 standard doesn't specify a payload).\n\n### RealtimeClient\n\nIn earlier versions, the realtime client used an old method (built on the MQTT standard) to connect\n(it's still being used in mgp25's library), but thr RealtimeClient is using MQTToT to connect.\nIn contrast to FBNS it doesn't use a device-auth, it uses cookie-auth as it was the case with the\nold method.\n\nThe RealtimeClient communicates on different MQTT-Topics 8most of the time one for requesting and one for a response).\n\n### FbnsClient\n\nFBNS uses MQTToT to connect with a device-auth.\nA successful auth will return a payload in the CONNACK packet with values used for future connections.\nAnd a response containing a token,\nthat gets sent to an instagram api endpoint (`/api/v1/push/register/`), is sent to `/fbns_reg_resp`.\nThis completes the auth.\n\nNow, push notifications are sent to `/fbns_msg`.\n\n## Collaborating\n\n### Setting up the environment\n\nIf you're using x86, make sure to install ARM translations for yor device\nin order to get ProxyDroid to work.\n\nInstructions are [here](https://github.com/dilame/instagram-private-api/blob/master/CONTRIBUTING.md#capturing-tls-requests).\n\n## Thanks\n\nThanks to [valga](https://github.com/valga) for providing and maintaining the [PHP library](https://github.com/valga/fbns-react).\nThis library integrates with the [instagram-private-api](https://github.com/dilame/instagram-private-api).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerixyz%2Finstagram_mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnerixyz%2Finstagram_mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerixyz%2Finstagram_mqtt/lists"}