02 Quick Start


02 Quick Start

Goal: get you to a minimal end-to-end flow as quickly as possible: Sign in → subscribe to key events → place a Preview Outbound Call → answer/hang up (softphone).

0. Prerequisites

  • HTTPS is required (especially for WebRTC softphone scenarios)
  • baseURL must be reachable
  • Prepare sign-in parameters: tenantId, agentNo, sessionKey, bindEndpoint

1. Install / Include

1.1 UMD

<!-- UMD global: window.AgentSDK (subject to your actual build artifact) -->
<script src="/path/to/agent-sdk.umd.min.js"></script>

1.2 npm / ESM

pnpm add @cc/agent-sdk
# or npm i / yarn add
import { AgentJsSDK as AgentSDK } from '@cc/agent-sdk';

2. Initialize (setup)

Call setup() once at application startup to configure the SDK:

// UMD example
const AgentSDK = window.AgentSDK;

AgentSDK.setup({
  baseURL: 'https://api.example.com',
  debug: false,
  webrtc: true,
  webrtcStats: false,
  audio_debug: false,
  observability: false
});

See 04-API-Operations.md → setup for configuration details.

3. Sign in (login)

await AgentSDK.login({
  tenantId: 'your_tenantId',
  agentNo: 'your_agentNo',
  sessionKey: 'your_sessionKey',
  bindEndpoint: { endpointType: 1, endpoint: '13600000000' }, // 1 PSTN; 2 Extension; 3 Softphone
  initialStatus: 1 // 1 idle; 2 busy (requires pauseDescription); 3 wrap-up
  // pauseDescription: 'MEETING'
});

4. Subscribe to key events

Subscribe as early as possible (before/after login) to avoid missing early events. Always off on unload.

const { EventType } = AgentSDK;

AgentSDK.on(EventType.AGENT_STATUS, (e) => console.log('agentStatus', e));
AgentSDK.on(EventType.PREVIEW_OBCALL_RINGING, (e) => console.log('ringing', e));
AgentSDK.on(EventType.PREVIEW_OBCALL_BRIDGE, (e) => console.log('bridge', e));
AgentSDK.on(EventType.RECONNECT_ATTEMPT, (e) => console.log('reconnect', e));

Full event list and payloads: 05-Events.md. Types: 06-Types.md.

5. Place a Preview Outbound Call (previewObCall)

const res = await AgentSDK.previewObCall({
  customerNumber: '13800138000',
  agentAnswerTimeout: 30,
  customerAnswerTimeout: 45,
  // Channel variables (example). See ChannelVariable in `06-Types.md`.
  // chanVariables: [{ name: 'k1', value: 'v1', type: 1 }]
});

if (res.code !== 0) {
  console.error('previewObCall failed:', res.errorCode, res.message);
}

For the typical event sequence, see 10-Key-Flows-Sequence-Diagrams.md.

6. Answer / Hang up (WebRTC softphone)

When bindEndpoint.endpointType = 3 (softphone):

await AgentSDK.sipLink();    // answer
await AgentSDK.sipUnlink();  // hang up

7. Sign out and cleanup

await AgentSDK.logout({ logoutMode: 1, unbindEndpoint: 0 });

// Cleanup example:
// AgentSDK.off(EventType.AGENT_STATUS, handler);

8. Recommended error-handling pattern

You must handle both:

  • Promise resolves but res.code !== 0 (server-side business failure)
  • Promise rejects / throws (SDK local error or runtime exception)
try {
  const res = await AgentSDK.previewObCall({ customerNumber: '13800138000' });
  if (res.code !== 0) {
    console.error('[server failed]', res.errorCode, res.message);
    return;
  }
} catch (err) {
  console.error('[sdk error or runtime error]', err);
}

See 07-Error-Handling.md.