npm package: @onyxplatform/dialer-sdk
Description: SDK for integrating with the Onyx Chrome Extension Dialer
Author: Onyx Platform
Latest version: 0.0.8

# @onyxplatform/dialer-sdk

TypeScript SDK that lets third-party CRMs communicate with the [Onyx Chrome Extension Dialer](https://chromewebstore.google.com/detail/onyx-platform-dialer/gjnegjjmdbhjilnbpcnbmccpeofihddp).

## Installation

```bash
npm install @onyxplatform/dialer-sdk
```

## Browser Support

The SDK requires a Chrome browser. The user must have the Onyx Chrome Dialer installed prior for the SDK to work.

```typescript
import { isBrowserSupported } from '@onyxplatform/dialer-sdk';

if (!isBrowserSupported()) {
  // Show a message telling the user to switch to Chrome
}
```

## Getting Started

```typescript
import { createOnyxSDK, isBrowserSupported } from '@onyxplatform/dialer-sdk';

if (!isBrowserSupported()) {
  console.error('Onyx SDK requires a Chromium-based browser.');
} else {
  const sdk = createOnyxSDK();

  // Listen for new calls
  sdk.onCallStarted((callState) => {
    console.log('Call started:', callState.call.id, callState.call.direction);
    console.log('Participants:', callState.participants);
  });

  // Clean up when done
  window.addEventListener('beforeunload', () => {
    sdk.destroy();
  });
}
```

### `createOnyxSDK(extensionId?: string): OnyxSDK`

Factory function. Creates and returns an `OnyxSDK` instance connected to the extension. Call `destroy()` when done.

### `isBrowserSupported(): boolean`

Returns `true` if the required Chrome extension APIs are available. Call this before `createOnyxSDK()`.

### `onCallStarted(callback: CallStartedCallback): () => void`

Convenience listener that fires when the user first connects to a call. The callback receives the initial `CallState` as its argument.

Returns an unsubscribe function.

```typescript
const unsubscribe = sdk.onCallStarted((callState) => {
  console.log('Direction:', callState.call.direction);
  console.log('Status:', callState.call.status);
  console.log('Participants:', callState.participants);
});

// Later:
unsubscribe();
```

## Types

### `CallState`

```typescript
interface CallState {
  call: {
    id: number;
    direction: CallDirection;
    status: CallStatus;
    onyxPhoneNumber: string;
  };
  lead: CallLead;
  source?: CallSource;
  campaign?: CallCampaign;
  participants: Participant[];
}
```

### `CallLead`

A Lead is a customer interest in a line of insurance at a point in time.

```typescript
interface CallLead {
  id: number;
  phoneNumber: string;
  lineOfInsurance: LineOfInsurance;
  state: string | null;
  externalId: string | null;
}
```

### `Participant`

```typescript
interface Participant {
  type: ParticipantType;
  label: string;
  hold: boolean;
  muted: boolean;
  status: ParticipantStatus;
}
```

### `CallSource`

```typescript
interface CallSource {
  id: number;
  name: string;
  billingType: SourceBillingType;
  billingCostDollars?: number;
  billingDurationTimeSeconds?: number;
}
```

### `CallCampaign`

```typescript
interface CallCampaign {
  id: number;
  name: string;
  direction: CampaignDirection;
}
```

### Key Enums

| Enum | Values |
|------|--------|
| `CallDirection` | `INBOUND`, `DIRECT_INBOUND`, `AUTO_OUTBOUND`, `MANUAL_OUTBOUND`, `OUTBOUND_CAMPAIGN_CALLBACK` |
| `CallStatus` | `RINGING`, `IN_PROGRESS`, `DISPOSITIONING` |
| `ParticipantType` | `AGENT`, `LEAD`, `EXTERNAL` |
| `ParticipantStatus` | `RINGING`, `IN_PROGRESS`, `COMPLETED` |