Skip to content

Add Facebook Page login via Business Suite - #313

Open
aminebalti55 wants to merge 1 commit into
mautrix:mainfrom
aminebalti55:businesssuite-page-login
Open

Add Facebook Page login via Business Suite#313
aminebalti55 wants to merge 1 commit into
mautrix:mainfrom
aminebalti55:businesssuite-page-login

Conversation

@aminebalti55

Copy link
Copy Markdown

Problem

Today the bridge can only log in as a personal Facebook or Messenger account. Businesses that manage their customer conversations through a Facebook Page have no way to bridge that Page's inbox — only a personal profile's DMs are supported.

Facebook Pages are also a materially different product surface: Page messaging is managed through business.facebook.com ("Business Suite"), and Pages still receive messages over an older real-time transport than the one personal accounts now use. Supporting Pages isn't just a new login screen — it requires a different way of receiving live messages and different handling of how threads are organized.

Solution

This PR adds Business Suite as a login option. A user can authenticate against business.facebook.com, select which Facebook Page they manage, and bridge that Page's inbox into Matrix — separately from, or alongside, a personal Messenger login.

To make that work end-to-end:

  • A dedicated real-time client is added for the transport Facebook Pages still use for live messages, since it differs from the one personal accounts use today.
  • Page-specific login and account metadata is tracked so multiple logins (a personal account and one or more Pages) stay correctly isolated from each other.
  • Threads are correctly separated when a Page's unified inbox mixes Facebook and Instagram conversations together, so messages land in the right place instead of being miscategorized.

The result is that anyone managing a Facebook Page can bridge its customer conversations the same way personal Messenger accounts are bridged today.

Testing

  • Added unit tests covering the new login flow, thread separation logic, and the new transport client, alongside the existing test suite.
  • go build, go vet, and go test pass across all changed packages.
  • Manually verified against a real Facebook Page: page selection, live message delivery, and reconnection all behave as expected.

Technical details

  • New login flow (pkg/connector/login.go, pkg/messagix/types/client.go): adds a BusinessSuite platform value alongside the existing Facebook/Messenger/MessengerLite modes. Login authenticates against business.facebook.com, discovers the account's manageable Pages via a GraphQL query, and lets the user pick one. Page identity (business ID, asset ID, page ID) is stored in login metadata so portals and future reconnects stay scoped to the correct Page.
  • Business Suite real-time transport (pkg/messagix/businesssuite_socket.go): Facebook Pages still deliver Lightspeed traffic over Meta's MQTT-3.1-over-websocket protocol, while personal accounts have moved to a newer DGW-based socket. This adds a minimal, purpose-built MQTT client (connect/subscribe/publish/ack handling, with bounds-checked frame parsing) kept isolated from the existing DGW socket so Page-specific behavior can't leak into the personal-account code path. The broker endpoint is read from the account's live config, so as a defense-in-depth measure, the dial target is validated to be a wss:// connection to a Meta-owned host before the session's cookies are attached.
  • Thread/platform separation (pkg/connector/businesssuite_filter.go, pkg/connector/ids.go): the unified Business Inbox snapshot returns Facebook and Instagram threads in the same sync group, distinguished only by a secondary marker. This tracks which threads are actually Instagram-sourced so they're routed correctly instead of being treated as Facebook Page messages.
  • Sync group handling (pkg/messagix/socket.go, pkg/messagix/syncManager.go): Business Suite requires syncing a different set of database groups than personal accounts, and its request/response flow goes through the new MQTT client rather than the DGW stream, so sync selection and response handling account for both transports.

Adds a login mode that authenticates against business.facebook.com and
bridges a managed Facebook Page's inbox, instead of or alongside a
personal Messenger account.

Pages still receive messages over Meta's MQTT-over-websocket transport
rather than the newer DGW/lightspeed socket used for personal accounts,
so a dedicated Business Suite MQTT client is added to handle that
transport, discover the Pages available to a logged-in account, and
correctly separate the mixed Facebook/Instagram threads returned by the
unified Business Inbox sync stream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant