# `PhoenixKit.Integrations.Events`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.165/lib/phoenix_kit/integrations/events.ex#L1)

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

# `broadcast_connected`

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

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

# `broadcast_connection_added`

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

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

# `broadcast_connection_removed`

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

Broadcast that a named connection was removed from a provider.

# `broadcast_connection_renamed`

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

Broadcast that a named connection was renamed.

# `broadcast_disconnected`

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

Broadcast that an integration was disconnected (tokens removed).

# `broadcast_setup_saved`

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

Broadcast that an integration's setup credentials were saved.

# `broadcast_validated`

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

Broadcast that an integration's health check completed.

# `subscribe`

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

Subscribe to all integration change events.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
