04 API (Operations)
04 API (Operations)
Notes:
- This document describes operations initiated via SDK methods.
- All operations return Promises. Determine success/failure by
codein the resolved response. Handle local exceptions viatry/catch(see07-Error-Handling.md).- Types are defined in
06-Types.mdand take precedence over any other file if inconsistencies exist.
1. General conventions
1.1 Standard signature
AgentSDK.methodName(params?): Promise<SdkResponse & {...}>1.2 Standard response fields (summary)
action: action name (typically aligned with response events /EventType)code:0success; non-zero failure (commonly-1)message: human-readable messageerrorCode?: optional business error code (domain-specific)
See 06-Types.md.
1.3 Two ways to consume results
-
Promise (recommended):
await AgentSDK.xxx()to get the operation response -
Event: subscribe to
EventType.XXX_RESP(orxxxResp) to receive the response via events
2. Setup & event handling
2.1 setup(config)
Purpose: set global SDK configuration (recommended once at app startup).
Common parameters:
| Parameter | Type | Required | Description | Default |
|---|---|---|---|---|
| baseURL | string | Yes | Agent Gateway base URL | None |
| webrtc | boolean | No | Enable WebRTC softphone | true |
| debug | boolean | No | Enable console logging | false |
| audio_debug | boolean | No | Enable audio play/pause debug logs | false |
| observability | boolean | No | Enable observability upload (only SDK-triggered custom events/errors) | false |
| webrtcStats | boolean | No | Emit webrtcStats events (softphone call quality) | false |
Example:
AgentSDK.setup({
baseURL: 'https://api.example.com',
debug: false,
webrtc: true,
webrtcStats: false,
audio_debug: false,
observability: false
});2.2 Event APIs: on/off/once
- Subscribe:
AgentSDK.on(eventName, handler) - Unsubscribe:
AgentSDK.off(eventName, handler) - Subscribe once:
AgentSDK.once(eventName, handler)
Example:
const { EventType } = AgentSDK;
const onStatus = (e) => console.log('agentStatus', e);
AgentSDK.on(EventType.AGENT_STATUS, onStatus);
AgentSDK.once(EventType.SESSION_INIT, () => console.log('session init once'));
// Cleanup on unload
AgentSDK.off(EventType.AGENT_STATUS, onStatus);3. Agent operations (core)
3.1 login(params)
Purpose: agent sign-in (establish session, open WebSocket, subscribe server-pushed events).
Parameters (detailed)
| Parameter | Type | Required | Description |
|---|---|---|---|
| sessionKey | string | Yes | Session credential (validity controlled by server) |
| tenantId | string | Yes | Tenant ID |
| agentNo | string | Yes | Agent ID |
| webSocketUrl | string | No | WebSocket URL (derived from baseURL if omitted) |
| bindEndpoint | BindEndpoint | Yes | Agent endpoint: { endpointType: 1|2|3, endpoint: string }- 1: PSTN number- 2: Extension- 3: Softphone |
| qids | string | No | Supervisor only: queue list (call-center-id + queueNo), comma-separated |
| initialStatus | number | Yes | Initial state: 1 idle; 2 busy; 3 wrap-up |
| pauseDescription | string | Conditional | Required when initialStatus=2 (busy): reason description (must be configured in tenant) |
| workMode | string | No | Agent work mode: 0 preview + predictive; 4 preview only; 5 predictive only (comma-separated) |
Response (Promise resolve)
In addition to the base
SdkResponse, login may return softphone-related fields (softphone only).
| Field | Type | Description |
|---|---|---|
| action | string | Always loginResp |
| code | number | 0 success; -1 failure |
| message | string | Message (success typically ok) |
| tenantId | string | Tenant ID |
| agentNo | string | Agent ID |
| bindEndpoint | BindEndpoint | Echo of bindEndpoint |
| webrtcSocketUrl | string | Softphone: WebRTC socket URL |
| webrtcStunServer | string | Softphone: STUN server configuration |
| sipPwd | string | Softphone: SIP password |
| sipIp | string | Softphone: SIP IP |
Related events
loginResp(if you consume responses via events)agentStatus(continuous agent status updates after login)reconnectAttempt(reconnection attempts)
Example
const res = await AgentSDK.login({
tenantId: 'your_tenantId',
agentNo: 'your_agentNo',
sessionKey: 'your_sessionKey',
bindEndpoint: { endpointType: 1, endpoint: '13600000000' },
initialStatus: 1
// initialStatus=2 requires pauseDescription: 'MEETING'
});
if (res.code === 0) {
console.log('login ok');
} else {
console.error('login failed:', res.message);
}3.2 logout(params)
Purpose: sign out / disconnect.
Parameters (detailed)
Parameter | Type | Required | Description |
|---|---|---|---|
logoutMode | number | Yes |
|
unbindEndpoint | number | No |
|
await AgentSDK.logout({ logoutMode: 1, unbindEndpoint: 0 });3.3 pause(params) / unpause()
Purpose: set Busy / set Idle.
pause(params) parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| pauseType | number | Yes | Busy type (tenant-configured). Common: 0 productive; 2 non-productive (subject to actual enum) |
| pauseDescription | string | No | Busy reason description (default “busy”), must exist in tenant configuration |
Response message notes
message may contain (examples): ok, deviceStatus not in idle, exception, fail to get lock, already ready, not logined, no such agent.
await AgentSDK.pause({ pauseType: 1, pauseDescription: 'MEETING' });
await AgentSDK.unpause();3.4 updateBoundEndpoint(params)
Purpose: change agent’s bound endpoint (phone/extension/etc.).
| Parameter | Type | Required | Description |
|---|---|---|---|
| bindEndpoint | BindEndpoint | Yes | New endpoint |
await AgentSDK.updateBoundEndpoint({
bindEndpoint: { endpointType: 1, endpoint: '13600000000' }
});4. Call control (common)
4.1 previewObCall(params)
Purpose: Preview Outbound Call (ring agent endpoint first, then dial customer and bridge).
Softphone note: when
bindEndpoint.endpointType=3, place outbound only after the softphone is ready/registered (based on your integration).
Parameters (detailed)
| Parameter | Type | Required | Description |
|---|---|---|---|
| customerNumber | string | Yes | Customer phone number |
| agentAnswerTimeout | number | No | Ring agent timeout (default 30, range 5–60 seconds) |
| customerAnswerTimeout | number | No | Ring customer timeout (default 45, range 5–60 seconds) |
| obClid | string | No | Outbound caller ID (must belong to tenant) |
| obClidAreaCode | string | No | Outbound caller ID area code |
| obClidGroup | string | No | Caller ID group (requires tenant feature) |
| chanVariables | ChannelVariable[] | No | Channel variables for event payloads/CDR custom fields/SIP header passthrough (max 5) |
| requestUniqueId | string | No | Client request id (auto-generated if omitted) |
| backupNumber | string | No | Backup numbers (comma-separated, up to 5) |
| cdrIsAsr | number | No | ASR on recording: 0 no; 1 yes (default 1) |
const res = await AgentSDK.previewObCall({
customerNumber: '13800138000',
agentAnswerTimeout: 30,
customerAnswerTimeout: 45
});
if (res.code !== 0) console.error(res.errorCode, res.message);Related events: previewObCallStart/previewObCallRinging/previewObCallBridge/previewObCallResult (see 05-Events.md, 10-Key-Flows-Sequence-Diagrams.md).
Business error codes (preview outbound call)
When res.code !== 0, errorCode/message may be returned (examples; subject to server):
| errorCode | message | Description |
|---|---|---|
| 10001 | Please try again later | System exception |
| 20000 | bad param | Invalid parameter (e.g., special characters in number) |
| 20011 | previewOutcall agent busy | Agent is busy (on a call/dialing/etc.) |
| 20012 | no such agent | Agent does not exist or is offline |
| 20016 | permission denied | No outbound permission |
| 20024 | no ob permission | Outbound capability not enabled |
| 20025 | bad destInterface | Extension not registered |
| 20031 | restrict tel | Number is blacklisted or not whitelisted |
| 20032 | bad obClidLeftNumber | Caller ID not owned by tenant |
| 20101 | previewOutcall not within the time allowed | Outbound time restriction |
| 20102 | bad tel | Invalid phone number format |
| 20103 | fail to get lock | Failed to lock agent |
4.2 cancelPreviewObCall()
Purpose: cancel a Preview Outbound Call (typically while the agent endpoint is ringing).
await AgentSDK.cancelPreviewObCall();4.3 unlink(params)
Purpose: hang up the current call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| side | number | No | Hangup side: 1 agent side; 2 customer side (default 1) |
await AgentSDK.unlink({ side: 1 });4.4 reject(params)
Purpose: reject an inbound call while ringing.
| Parameter | Type | Required | Description |
|---|---|---|---|
| description | string | No | Reject description (length < 20) |
await AgentSDK.reject({ description: 'busy' });4.5 hold() / unhold()
Purpose: hold / retrieve the call.
await AgentSDK.hold();
await AgentSDK.unhold();4.6 mute(params) / unmute(params)
Purpose: mute / unmute the call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| direction | string | Yes | in (inbound audio), out (outbound audio), all (both). Default in. |
await AgentSDK.mute({ direction: 'in' });
await AgentSDK.unmute({ direction: 'in' });4.7 sendDtmf(params)
Purpose: send DTMF digits during a call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| digits | string | Yes | DTMF digits string (max 20) |
| target | number | Yes | 1 to local leg; 2 to remote leg |
| durationMs | number | No | Duration per digit (default 100, range 100–500 ms) |
| gapMs | number | No | Gap between digits (default 250, range 250–1000 ms) |
await AgentSDK.sendDtmf({ digits: '1#', target: 2 });4.8 performSatisfactionSurvey()
Purpose: start a customer satisfaction survey. On success, the agent-side call ends and the customer enters the survey flow.
await AgentSDK.performSatisfactionSurvey();4.9 InternalCall(params)
Purpose: internal call to another agent or an IP phone extension within the same tenant.
| Parameter | Type | Required | Description |
|---|---|---|---|
| targetType | number | Yes | 0 agent; 1 extension |
| target | string | Yes | Callee identifier: - targetType=0: agentNo- targetType=1: extension number |
| agentAnswerTimeout | number | No | Ring agent timeout (default 30, range 5–60 s) |
| customerAnswerTimeout | number | No | Ring callee timeout (default 45, range 5–60 s) |
| requestUniqueId | string | No | Request unique id (auto-generated if omitted) |
| chanVariables | ChannelVariable[] | No | Channel variables (tenant configuration required if persisted to CDR) |
await AgentSDK.InternalCall({
targetType: 0,
target: '0000',
agentAnswerTimeout: 30,
customerAnswerTimeout: 45
});4.10 prolongWrapup(params)
Purpose: extend wrap-up time.
| Parameter | Type | Required | Description |
|---|---|---|---|
| wrapupTime | number | Yes | Additional wrap-up time in seconds (range 30–600) |
await AgentSDK.prolongWrapup({ wrapupTime: 300 });4.11 startAutoObCallTask(params)
Purpose: start an agent auto outbound task.
| Parameter | Type | Required | Description |
|---|---|---|---|
| taskId | string | Yes | Auto outbound task ID |
| callParams | string | No | Call configuration (JSON string) |
await AgentSDK.startAutoObCallTask({ taskId: '11', callParams: '{"key":"value"}' });4.12 pauseAutoObCallTask(params)
Purpose: pause an agent auto outbound task.
| Parameter | Type | Required | Description |
|---|---|---|---|
| taskId | string | Yes | Auto outbound task ID |
await AgentSDK.pauseAutoObCallTask({ taskId: '11' });4.13 changeObCallMode(params)
Purpose: change agent outbound working mode.
| Parameter | Type | Required | Description |
|---|---|---|---|
| workMode | number | Yes | 0 preview + predictive; 1 preview only; 2 predictive only |
await AgentSDK.changeObCallMode({ workMode: 0 });5. Consult & transfer (call transfer features)
5.1 startAtxfer(params) / cancelAtxfer() / resumeAtxfer()
Purpose: start consult / cancel consult / resume from consult.
startAtxfer(params) parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| targetType | number | Yes | 0 PSTN; 1 agent; 2 extension |
| target | string | Yes | Target identifier based on targetType |
| chanVariables | ChannelVariable[] | No | Variables (e.g., [{ name:'test', value:'123', type:1 }]) |
await AgentSDK.startAtxfer({ targetType: 0, target: '13800138000' });
await AgentSDK.cancelAtxfer();
await AgentSDK.resumeAtxfer();5.2 completeAtxfer(params)
Purpose: complete consult transfer.
Optional parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| durationLimit | number | No | Call duration limit in seconds (default: unlimited) |
| preAlertSeconds | number | No | Pre-alert seconds (default 60, effective when durationLimit is set) |
| preAlertAudioFile | string | No | Pre-alert audio file name (effective when durationLimit is set) |
await AgentSDK.completeAtxfer();5.3 threewayAtxfer(params)
Purpose: consult three-way conference.
Optional parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| durationLimit | number | No | Call duration limit in seconds (default: unlimited) |
| preAlertSeconds | number | No | Pre-alert seconds (default 60, effective when durationLimit is set) |
| preAlertAudioFile | string | No | Pre-alert audio file name (effective when durationLimit is set) |
await AgentSDK.threewayAtxfer();5.4 blxfer(params)
Purpose: blind transfer (to customer number / agent / extension / IVR node).
Parameter | Type | Required | Description |
|---|---|---|---|
targetType | number | Yes |
|
target | string | Yes | Target identifier: |
blxferVariables | ChannelVariable[] | No | Transfer variables (cross-department, etc.; max 5) |
blxferDialSayAgent | number | No |
|
blxferDialAgentHold | number | No |
|
await AgentSDK.blxfer({ targetType: 0, target: '13800138000' });See 09-Transfer-Parameters-blxferVariables.md for details.
5.5 transferIvr(params)
Purpose: transfer to IVR for interaction and receive return variables in interactReturn.
| Parameter | Type | Required | Description |
|---|---|---|---|
| ivrTarget | object | Yes | { ivrId: string|number, ivrNode: string } |
| chanVariables | ChannelVariable[] | No | Channel variables (max 5) |
| returnVariables | object | No | Return variable mapping (returned via interactReturn) |
await AgentSDK.transferIvr({
ivrTarget: { ivrId: 1, ivrNode: '1.1' }
});Related event: interactReturn (see 05-Events.md).
6. Softphone (WebRTC)
6.1 sipLink() / sipUnlink()
Purpose: answer/hang up for softphone (bindEndpoint.endpointType=3).
await AgentSDK.sipLink();
await AgentSDK.sipUnlink();Related events: sipSessionInit/sipSessionTerminate/sipDisconnected/webrtcStats (see 05-Events.md).
7. Supervisor / Monitoring operations
Supervisor typically needs queue binding (e.g.,
qids) at login and appropriate permissions.
7.1 setPause(params) / setUnpause(params)
Purpose: supervisor sets a target agent to Busy/Idle.
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
await AgentSDK.setPause({ agentNo: '0000' });
await AgentSDK.setUnpause({ agentNo: '0000' });7.2 spy(params) / unspy()
Purpose: start/stop call monitoring (silent monitoring).
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
await AgentSDK.spy({ agentNo: '0000' });
await AgentSDK.unspy();7.3 performThreeway(params) / cancelThreeway(params)
Purpose: supervisor three-way / cancel three-way on a target agent’s call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
await AgentSDK.performThreeway({ agentNo: '0000' });
await AgentSDK.cancelThreeway({ agentNo: '0000' });7.4 whisper(params) / unWhisper()
Purpose: start/stop whisper coaching on a target agent’s call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
await AgentSDK.whisper({ agentNo: '0000' });
await AgentSDK.unWhisper();7.5 barge(params) / disconnect(params)
Purpose: barge-in / force disconnect for a target agent’s call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
await AgentSDK.barge({ agentNo: '0000' });
await AgentSDK.disconnect({ agentNo: '0000' });7.6 pickup(params)
Purpose: call pickup (answer a ringing call on behalf of a target agent).
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
await AgentSDK.pickup({ agentNo: '0000' });7.7 setOnline(params) / setOffline(params)
Purpose: force an agent online/offline.
setOnline(params)
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
| bindEndpoint | BindEndpoint | Yes | Binding endpoint (supervisor examples typically use PSTN/Extension) |
await AgentSDK.setOnline({
agentNo: '0000',
bindEndpoint: { endpointType: 1, endpoint: '1354*******' }
});setOffline(params)
| Parameter | Type | Required | Description |
|---|---|---|---|
| agentNo | string | Yes | Target agent ID |
| unbindEndpoint | number | No | 0 keep binding; 1 unbind; default 0 |
await AgentSDK.setOffline({ agentNo: '0000', unbindEndpoint: 0 });7.8 getQueueStatus(params)
Purpose: query queue status (supervisor).
| Parameter | Type | Required | Description |
|---|---|---|---|
| queueNos | any[] | No | Queue number list |
| fields | string | No | Requested sections: queueParams, agentStatuses, queueEntries (comma-separated) |
Response (summary):
action:queueStatusqueueStatus: a map of queueNo → data (see06-Types.md)
await AgentSDK.getQueueStatus({ queueNos: [0, 1, 2], fields: 'queueParams,agentStatuses,queueEntries' });7.9 ListPreviewDialingTask()
Purpose: list preview dialing tasks.
Note: the source doc indicates the return payload is not fully specified yet. This doc only states the API exists and follows standard response shape; confirm the concrete return fields with the server contract.
await AgentSDK.ListPreviewDialingTask();Updated 4 days ago