Google Meet: subscribe to a Google account's events on connect

Merged
EH
21h ago
+782-7

Context

Follows https://github.com/twentyhq/twenty/pull/30602 in the Google Meet app series started in https://github.com/twentyhq/twenty/pull/30587.

The subscriptions client (https://github.com/twentyhq/twenty/pull/30600) and the Google account id on the connection (https://github.com/twentyhq/twenty/pull/30602) are in place. This PR makes the first real use of them: when a member connects their Google account, the app subscribes to that account's Meet transcript events. Nothing receives the events yet; the webhook comes later in the series.

What this PR does

  • Adds the google-meet-register-connection logic function and declares it as the provider's onConnectLogicFunction. It looks up the subscription the Google account already has. A subscription on the configured topic is renewed, one on another topic is deleted and recreated (Google does not let a subscription change topic), and an account without subscription gets one. A retried hook or a reconnect never creates a second subscription.
  • An existing subscription is claimed for the workspace before anything is changed at Google, so a workspace never renews or deletes a subscription another workspace owns.
  • Stores three entries in the app's key-value store: a server-scope claim on the subscription (so the future webhook can find the workspace), the connection that owns the subscription, and the subscription of the connection (for disconnect and renewal). A subscription the connection had before is deleted at Google and released. The connection's entry is written last, so a retry after a failed release still knows what to release.
  • Adds a required server variable GOOGLE_MEET_PUBSUB_TOPIC: the Pub/Sub topic Google publishes the events to. The hook fails with a clear error when it is missing, or when the connection has no Google account id (connected before https://github.com/twentyhq/twenty/pull/30602, fixed by reconnecting).

Follow-ups in this series

  • Next PR: an onDisconnectLogicFunction that deletes the subscription and releases its claim when the connection is removed.
  • Later PR: a daily job that renews the subscriptions before Google expires them (7 days) and catches up on calls whose event was missed.

Known limit

Google allows one subscription per Google account per Cloud project, and a server route forwards an event to one workspace. If the same Google account is connected in two workspaces of one server, the first keeps the events and the hook of the second fails when it tries to claim the subscription. That workspace will rely on the daily catch-up.

Checks

  • yarn lint, yarn typecheck, yarn test:unit (100 tests) and twenty app build pass locally.
  • Not run: integration tests (they need a running server, CI runs them), and no subscription was created against the real Google API. That needs a Google Cloud project with a Pub/Sub topic and will be tested with a real account once this is merged.