PhoenixKit.Integrations.Events (phoenix_kit v1.7.118)

Copy Markdown View Source

PubSub helpers for broadcasting integration changes in real-time.

Allows multiple admins viewing the Integrations settings page to see changes immediately without page refresh. Also notifies other LiveViews that depend on integration status (e.g., document creator, AI endpoints).

Topic

All events are broadcast on the "phoenix_kit:integrations" topic.

Events

  • {:integration_setup_saved, provider_key, data} — setup credentials saved (client_id/secret, API key, etc.)
  • {:integration_connected, provider_key, data} — OAuth flow completed, integration is now connected
  • {:integration_disconnected, provider_key} — integration was disconnected
  • {:integration_validated, provider_key, :ok | {:error, reason}} — health check completed

Usage

# Subscribe in a LiveView mount
if connected?(socket), do: PhoenixKit.Integrations.Events.subscribe()

# Handle events
def handle_info({:integration_connected, provider_key, _data}, socket) do
  {:noreply, reload_data(socket)}
end

Summary

Functions

Broadcast that an OAuth integration was connected (tokens obtained).

Broadcast that a new named connection was added for a provider.

Broadcast that a named connection was removed from a provider.

Broadcast that a named connection was renamed.

Broadcast that an integration was disconnected (tokens removed).

Broadcast that an integration's setup credentials were saved.

Broadcast that an integration's health check completed.

Subscribe to all integration change events.

Functions

broadcast_connected(provider_key, data)

@spec broadcast_connected(String.t(), map()) :: :ok

Broadcast that an OAuth integration was connected (tokens obtained).

broadcast_connection_added(provider_key, name)

@spec broadcast_connection_added(String.t(), String.t()) :: :ok

Broadcast that a new named connection was added for a provider.

broadcast_connection_removed(provider_key, name)

@spec broadcast_connection_removed(String.t(), String.t()) :: :ok

Broadcast that a named connection was removed from a provider.

broadcast_connection_renamed(provider_key, old_name, new_name)

@spec broadcast_connection_renamed(String.t(), String.t(), String.t()) :: :ok

Broadcast that a named connection was renamed.

broadcast_disconnected(provider_key)

@spec broadcast_disconnected(String.t()) :: :ok

Broadcast that an integration was disconnected (tokens removed).

broadcast_setup_saved(provider_key, data)

@spec broadcast_setup_saved(String.t(), map()) :: :ok

Broadcast that an integration's setup credentials were saved.

broadcast_validated(provider_key, status)

@spec broadcast_validated(String.t(), :ok | {:error, term()}) :: :ok

Broadcast that an integration's health check completed.

subscribe()

@spec subscribe() :: :ok | {:error, term()}

Subscribe to all integration change events.