类型


重要:本文档是对外暴露类型的唯一事实来源

  • 如果 04-API-Operations.md / 05-Events.md 中描述的任何结构与本文档不一致,以本文档为准
  • 为了便于阅读,类型以 TypeScript 风格展示。SDK 实现可能是 JavaScript。

1. 常用类型

/** 标准响应:所有操作 Promise resolve 时的基础结构 */
export interface SdkResponse {
  action: string;              // 响应动作(与 EventType 对齐)
  code: number;                // 0 表示成功;非 0 表示失败(通常为 -1)
  message: string;             // 可读消息(成功时通常为 'ok')
  errorCode?: number | string; // 可选:服务端业务错误码
}

/** 坐席绑定的终端 */
export interface BindEndpoint {
  endpointType: 1 | 2 | 3; // 1 PSTN;2 分机;3 软电话
  endpoint: string;        // 电话号码 / 分机 / 软电话账号等
}

/** 通道变量(用于 chanVariables / blxferVariables 等) */
export interface ChannelVariable {
  name: string;
  value: string;
  /**
   * 1 普通变量;
   * 2 PJSIP_HEADER;
   * 3 自动用 ${} 包裹值;
   * 4 SIP_HEADER,并自动用 ${} 包裹值(按约定不加前缀)
   */
  type: 1 | 2 | 3 | 4;
}

2. 坐席状态机类型

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

export type InitialStatus = 0 | 1 | 2 | 3; // 0 未登录;1 空闲;2 忙碌;3 收尾

export type DeviceStatus = -1 | 0 | 1 | 2 | 3 | 4; // -1 无效;0 空闲;1 锁定;2 拨号中;3 响铃中;4 通话中

/** agentStatus 事件中 `status` 字段的结构 */
export interface AgentStatusPayload {
  state: AgentState;
  stateAction: string; // 参见 `08-State-Machine-stateAction.md`

  initialStatus: InitialStatus;
  deviceStatus: DeviceStatus;

  callType?: number;         // 可能在 deviceStatus=2/3/4 时出现
  pauseDescription?: string; // 可能在 initialStatus=2 时出现
  busyDescription?: string;  // 可能在 deviceStatus=4 时出现
  wrapupTime?: number;       // 可能在 initialStatus=3 时出现

  uniqueId?: string;      // 可能在 deviceStatus=3/4 时出现
  mainUniqueId?: string;  // 可能在 deviceStatus=3/4 时出现
}

3. 事件载荷(选取的常见类型)

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 坐席;2 客户
  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. 队列 / 主管类型

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;
}

/** 队列状态推送:queueStatus */
export type QueueStatusMap = Record<
  string,
  {
    queueParams?: QueueParam;
    agentStatuses?: any[]; // 如有需要可补充为显式类型
    queueEntries?: QueueEntry[];
  }
>;

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

5. 监控坐席状态(队列成员 / 主管)

注意:agentStatuses(主管视角)与 agentStatus 事件中的 status 不是同一种类型。

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;
}