06-Types


Important: this document is the single source of truth for externally exposed types.

  • If any structure described in 04-API-Operations.md / 05-Events.md differs from this document, this document prevails.
  • Types are presented in TypeScript style for readability. The SDK implementation may be JavaScript.

1. Common types

/** Standard response: base shape for all operation Promise resolves */
export interface SdkResponse {
  action: string;              // response action (aligned with EventType)
  code: number;                // 0 success; non-zero failure (commonly -1)
  message: string;             // readable message (success typically 'ok')
  errorCode?: number | string; // optional: server business error code
}

/** Agent bound endpoint */
export interface BindEndpoint {
  endpointType: 1 | 2 | 3; // 1 PSTN; 2 Extension; 3 Softphone
  endpoint: string;        // phone number / extension / softphone account, etc.
}

/** Channel variable (used by chanVariables / blxferVariables, etc.) */
export interface ChannelVariable {
  name: string;
  value: string;
  /**
   * 1 normal variable;
   * 2 PJSIP_HEADER;
   * 3 auto-wrap value with ${};
   * 4 SIP_HEADER and auto-wrap value with ${} (and no prefix per convention)
   */
  type: 1 | 2 | 3 | 4;
}

2. Agent state machine types

export type AgentState =
  | 'offline'
  | 'invalid'
  | 'idle'
  | 'busy'
  | 'calling'
  | 'ringing'
  | 'talking'
  | 'wrapup';

export type InitialStatus = 0 | 1 | 2 | 3; // 0 not logged in; 1 idle; 2 busy; 3 wrap-up

export type DeviceStatus = -1 | 0 | 1 | 2 | 3 | 4; // -1 invalid; 0 idle; 1 locked; 2 dialing; 3 ringing; 4 talking

/** `status` field structure in the agentStatus event */
export interface AgentStatusPayload {
  state: AgentState;
  stateAction: string; // see `08-State-Machine-stateAction.md`

  initialStatus: InitialStatus;
  deviceStatus: DeviceStatus;

  callType?: number;         // may appear when deviceStatus=2/3/4
  pauseDescription?: string; // may appear when initialStatus=2
  busyDescription?: string;  // may appear when deviceStatus=4
  wrapupTime?: number;       // may appear when initialStatus=3

  uniqueId?: string;      // may appear when deviceStatus=3/4
  mainUniqueId?: string;  // may appear when deviceStatus=3/4
}

3. Event payloads (selected common ones)

export interface AgentStatusEvent {
  eventType: 'agentStatus';
  tenantId: string;
  agentNo: string;
  status: AgentStatusPayload;
}

export interface PreviewObCallStartEvent {
  eventType: 'previewObCallStart';
  tenantId: string;
  agentNo: string;
  customerNumber: string;
  customerNumberType?: 0 | 1;
  obClidAreaCode?: string;
  mainUniqueId: string;
  requestUniqueId: string;
  obClid?: string;
}

export interface PreviewObCallRingingEvent {
  eventType: 'previewObCallRinging';
  tenantId: string;
  agentNo: string;
  customerNumber: string;
  customerNumberType?: 0 | 1;
  obClidAreaCode?: string;
  state: AgentState;
  stateAction: string;
  mainUniqueId: string;
}

export interface PreviewObCallBridgeEvent {
  eventType: 'previewObCallBridge';
  tenantId: string;
  agentNo: string;
  customerNumber: string;
  customerNumberType?: 0 | 1;
  obClidAreaCode?: string;
  channel: string;
  destChannel: string;
  mainUniqueId: string;
}

export interface PreviewObCallResultEvent {
  eventType: 'previewObCallResult';
  tenantId: string;
  agentNo: string;
  customerNumber: string;
  result: 'success' | 'error';
  uniqueId: string;
  obClid?: string;
}

export interface TranscriptEvent {
  eventType: 'transcript';
  text: string;
  role: 1 | 2; // 1 agent; 2 customer
  transcriptTime: number;
  beginTime: number;
  endTime: number;
  finished: 0 | 1;
  sentenceIndex: number;
  sentenceType: 'intermediateResult' | 'sentenceEnd';
  mainUniqueId: string;
  sentenceBeginTimestamp?: number;
  sentenceEndTimestamp?: number;
}

export interface WebrtcStatsEvent {
  eventType: 'webrtcStats';
  tenantId: string;
  agentNo: string;
  iceState: string;
  dtlsState: string;
  packetsSentTotal: number;
  packetsReceivedTotal: number;
  packetsSent: number;
  packetsReceived: number;
  packetsState: string;
  sentAudioEnergy: number;
  recvAudioEnergy: number;
  bytesSentInBits: number;
  bytesReceivedInBits: number;
  jitter: number;
  rtt: number;
  packetLossRateTotal: number;
  packetLossRate: number;
  sentNetworkQuality: number;
  receivedNetworkQuality: number;
  bridge: boolean;
  count: number;
}

4. Queue / supervisor types

export interface QueueParam {
  max: number;
  memberCount: number;
  availableCount: number;
  idleCount: number;
  completed: number;
  timeout: number;
  abandoned: number;
  calls: number;
  holdTime: number;
  maxHoldTime: number;
  talkTime: number;
  wrapupTime: number;
  serviceLevel: number;
  serviceLevelPerf: string;
  joinOk?: number;
  joinFull?: number;
  joinEmpty?: number;
  weight?: number;
  strategy?: string;
  completeCount?: number;
  joinCount?: number;
  queueAnswer?: number;
  queueEntryCount?: number;
}

export interface QueueEntry {
  customerNumber: string;
  areaCode?: string;
  province?: string;
  city?: string;
  startTime: string; // yyyy-MM-dd HH:mm:ss
  joinTime: string;  // yyyy-MM-dd HH:mm:ss
  waitTime: number;
  priority?: number;
  uniqueId: string;
  overflow?: number;
  position?: number;
}

/** Queue status push: queueStatus */
export type QueueStatusMap = Record<
  string,
  {
    queueParams?: QueueParam;
    agentStatuses?: any[]; // fill in as explicit type if needed
    queueEntries?: QueueEntry[];
  }
>;

export interface QueueStatusEvent {
  eventType: 'queueStatus';
  queueStatus: QueueStatusMap;
}

5. Monitoring agent status (queue members / supervisor)

Note: agentStatuses (supervisor) is not the same type as status in the agentStatus event.

export interface MonitorAgentStatus {
  agentNo: string;
  name?: string;
  agentType?: number;
  initialStatus: InitialStatus;
  loginTime?: string;
  loginStatusDuration?: number;
  stateDuration?: number;
  deviceStatus: DeviceStatus;
  state: AgentState;
  active?: '0' | '1';
  deviceStatusDuration?: number;
  endpoint?: string;
  calls?: number;
  loginType?: number;
  ibAnsweredCount?: number;
  obAnsweredCount?: number;
  pauseType?: string;
  pauseDescription?: string;
  monitoredType?: string;
  monitoredObject?: string;
  monitoredObjectType?: number;
  busyDescription?: string;
  customerNumber?: string;
  customerNumberType?: number;
  customerNumberAreaCode?: string;
  numberTrunk?: string;
  hotline?: string;
  callType?: number;
  qno?: string;
}