@webex/contact-center 3.12.0-next.73 → 3.12.0-next.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/AGENTS.md +438 -0
  2. package/ai-docs/README.md +131 -0
  3. package/ai-docs/RULES.md +455 -0
  4. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  5. package/ai-docs/patterns/testing-patterns.md +480 -0
  6. package/ai-docs/patterns/typescript-patterns.md +365 -0
  7. package/ai-docs/templates/README.md +102 -0
  8. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  9. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  10. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  11. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  12. package/ai-docs/templates/new-method/00-master.md +80 -0
  13. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  14. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  15. package/ai-docs/templates/new-method/03-tests.md +201 -0
  16. package/ai-docs/templates/new-method/04-validation.md +141 -0
  17. package/ai-docs/templates/new-service/00-master.md +109 -0
  18. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  19. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  20. package/ai-docs/templates/new-service/03-integration.md +178 -0
  21. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  22. package/ai-docs/templates/new-service/05-validation.md +145 -0
  23. package/dist/cc.js +53 -38
  24. package/dist/cc.js.map +1 -1
  25. package/dist/config.js +6 -0
  26. package/dist/config.js.map +1 -1
  27. package/dist/constants.js +14 -1
  28. package/dist/constants.js.map +1 -1
  29. package/dist/index.js +13 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/metrics/behavioral-events.js +26 -0
  32. package/dist/metrics/behavioral-events.js.map +1 -1
  33. package/dist/metrics/constants.js +9 -3
  34. package/dist/metrics/constants.js.map +1 -1
  35. package/dist/services/ApiAiAssistant.js +74 -3
  36. package/dist/services/ApiAiAssistant.js.map +1 -1
  37. package/dist/services/config/Util.js +2 -2
  38. package/dist/services/config/Util.js.map +1 -1
  39. package/dist/services/config/types.js +25 -9
  40. package/dist/services/config/types.js.map +1 -1
  41. package/dist/services/core/Utils.js +74 -27
  42. package/dist/services/core/Utils.js.map +1 -1
  43. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  44. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  45. package/dist/services/core/websocket/types.js.map +1 -1
  46. package/dist/services/index.js +1 -1
  47. package/dist/services/index.js.map +1 -1
  48. package/dist/services/task/Task.js +688 -0
  49. package/dist/services/task/Task.js.map +1 -0
  50. package/dist/services/task/TaskFactory.js +45 -0
  51. package/dist/services/task/TaskFactory.js.map +1 -0
  52. package/dist/services/task/TaskManager.js +725 -612
  53. package/dist/services/task/TaskManager.js.map +1 -1
  54. package/dist/services/task/TaskUtils.js +162 -26
  55. package/dist/services/task/TaskUtils.js.map +1 -1
  56. package/dist/services/task/constants.js +6 -1
  57. package/dist/services/task/constants.js.map +1 -1
  58. package/dist/services/task/digital/Digital.js +77 -0
  59. package/dist/services/task/digital/Digital.js.map +1 -0
  60. package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
  61. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  62. package/dist/services/task/state-machine/actions.js +543 -0
  63. package/dist/services/task/state-machine/actions.js.map +1 -0
  64. package/dist/services/task/state-machine/constants.js +161 -0
  65. package/dist/services/task/state-machine/constants.js.map +1 -0
  66. package/dist/services/task/state-machine/guards.js +340 -0
  67. package/dist/services/task/state-machine/guards.js.map +1 -0
  68. package/dist/services/task/state-machine/index.js +53 -0
  69. package/dist/services/task/state-machine/index.js.map +1 -0
  70. package/dist/services/task/state-machine/types.js +54 -0
  71. package/dist/services/task/state-machine/types.js.map +1 -0
  72. package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
  73. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  74. package/dist/services/task/taskDataNormalizer.js +99 -0
  75. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  76. package/dist/services/task/types.js +168 -16
  77. package/dist/services/task/types.js.map +1 -1
  78. package/dist/services/task/voice/Voice.js +1042 -0
  79. package/dist/services/task/voice/Voice.js.map +1 -0
  80. package/dist/services/task/voice/WebRTC.js +149 -0
  81. package/dist/services/task/voice/WebRTC.js.map +1 -0
  82. package/dist/types/cc.d.ts +19 -18
  83. package/dist/types/config.d.ts +6 -0
  84. package/dist/types/constants.d.ts +14 -1
  85. package/dist/types/index.d.ts +11 -5
  86. package/dist/types/metrics/constants.d.ts +7 -1
  87. package/dist/types/services/ApiAiAssistant.d.ts +11 -3
  88. package/dist/types/services/config/types.d.ts +113 -9
  89. package/dist/types/services/core/Utils.d.ts +23 -10
  90. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  91. package/dist/types/services/core/websocket/types.d.ts +1 -1
  92. package/dist/types/services/index.d.ts +1 -1
  93. package/dist/types/services/task/Task.d.ts +157 -0
  94. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  95. package/dist/types/services/task/TaskUtils.d.ts +46 -2
  96. package/dist/types/services/task/constants.d.ts +5 -0
  97. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  98. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
  99. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  100. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  101. package/dist/types/services/task/state-machine/guards.d.ts +90 -0
  102. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  103. package/dist/types/services/task/state-machine/types.d.ts +267 -0
  104. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  105. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  106. package/dist/types/services/task/types.d.ts +551 -78
  107. package/dist/types/services/task/voice/Voice.d.ts +184 -0
  108. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  109. package/dist/types/types.d.ts +92 -0
  110. package/dist/types/webex.d.ts +1 -0
  111. package/dist/types.js +85 -0
  112. package/dist/types.js.map +1 -1
  113. package/dist/webex.js +14 -2
  114. package/dist/webex.js.map +1 -1
  115. package/package.json +15 -12
  116. package/src/cc.ts +63 -43
  117. package/src/config.ts +6 -0
  118. package/src/constants.ts +14 -1
  119. package/src/index.ts +14 -5
  120. package/src/metrics/ai-docs/AGENTS.md +348 -0
  121. package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
  122. package/src/metrics/behavioral-events.ts +28 -0
  123. package/src/metrics/constants.ts +9 -4
  124. package/src/services/ApiAiAssistant.ts +104 -3
  125. package/src/services/agent/ai-docs/AGENTS.md +238 -0
  126. package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
  127. package/src/services/ai-docs/AGENTS.md +384 -0
  128. package/src/services/config/Util.ts +2 -2
  129. package/src/services/config/ai-docs/AGENTS.md +253 -0
  130. package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
  131. package/src/services/config/types.ts +116 -10
  132. package/src/services/core/Utils.ts +85 -34
  133. package/src/services/core/ai-docs/AGENTS.md +379 -0
  134. package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
  135. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  136. package/src/services/core/websocket/types.ts +1 -1
  137. package/src/services/index.ts +1 -1
  138. package/src/services/task/Task.ts +837 -0
  139. package/src/services/task/TaskFactory.ts +55 -0
  140. package/src/services/task/TaskManager.ts +738 -697
  141. package/src/services/task/TaskUtils.ts +205 -25
  142. package/src/services/task/ai-docs/AGENTS.md +455 -0
  143. package/src/services/task/ai-docs/ARCHITECTURE.md +585 -0
  144. package/src/services/task/constants.ts +5 -0
  145. package/src/services/task/digital/Digital.ts +95 -0
  146. package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
  147. package/src/services/task/state-machine/actions.ts +685 -0
  148. package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
  149. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
  150. package/src/services/task/state-machine/constants.ts +172 -0
  151. package/src/services/task/state-machine/guards.ts +406 -0
  152. package/src/services/task/state-machine/index.ts +28 -0
  153. package/src/services/task/state-machine/types.ts +241 -0
  154. package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
  155. package/src/services/task/taskDataNormalizer.ts +137 -0
  156. package/src/services/task/types.ts +654 -85
  157. package/src/services/task/voice/Voice.ts +1267 -0
  158. package/src/services/task/voice/WebRTC.ts +187 -0
  159. package/src/types.ts +112 -1
  160. package/src/utils/AGENTS.md +276 -0
  161. package/src/webex.js +2 -0
  162. package/test/unit/spec/cc.ts +133 -3
  163. package/test/unit/spec/logger-proxy.ts +70 -0
  164. package/test/unit/spec/services/ApiAiAssistant.ts +122 -17
  165. package/test/unit/spec/services/WebCallingService.ts +7 -1
  166. package/test/unit/spec/services/config/index.ts +27 -27
  167. package/test/unit/spec/services/core/Utils.ts +335 -1
  168. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  169. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  170. package/test/unit/spec/services/task/Task.ts +477 -0
  171. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  172. package/test/unit/spec/services/task/TaskManager.ts +821 -1936
  173. package/test/unit/spec/services/task/TaskUtils.ts +206 -0
  174. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  175. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
  176. package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
  177. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  178. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
  179. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  180. package/test/unit/spec/services/task/voice/Voice.ts +631 -0
  181. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  182. package/umd/contact-center.min.js +2 -2
  183. package/umd/contact-center.min.js.map +1 -1
  184. package/dist/services/task/index.js +0 -1530
  185. package/dist/services/task/index.js.map +0 -1
  186. package/dist/types/services/task/index.d.ts +0 -650
  187. package/src/services/task/index.ts +0 -1806
  188. package/test/unit/spec/services/task/index.ts +0 -2205
@@ -0,0 +1,455 @@
1
+ # Task Service - AI Agent Guide
2
+
3
+ ## Purpose
4
+
5
+ Manage task lifecycle including inbound/outbound calls, hold/resume, consult, transfer, conference, and wrapup.
6
+
7
+ ---
8
+
9
+ ## File Structure
10
+
11
+ ```
12
+ services/task/
13
+ ├── Task.ts # Task class (ITask implementation)
14
+ ├── TaskManager.ts # Singleton task manager
15
+ ├── contact.ts # Contact operations (AQM)
16
+ ├── dialer.ts # Outbound dialing (AQM)
17
+ ├── AutoWrapup.ts # Auto wrapup handler
18
+ ├── TaskUtils.ts # Helper functions
19
+ ├── types.ts # Task types and events
20
+ ├── constants.ts # Task constants
21
+ ├── TaskFactory.ts # Task factory
22
+ ├── taskDataNormalizer.ts # Task data normalization helpers
23
+ ├── digital/ # Digital task implementations
24
+ │ └── Digital.ts
25
+ ├── voice/ # Voice task implementations
26
+ │ ├── Voice.ts
27
+ │ └── WebRTC.ts
28
+ ├── state-machine/ # XState task lifecycle engine
29
+ │ ├── TaskStateMachine.ts
30
+ │ ├── actions.ts
31
+ │ ├── guards.ts
32
+ │ ├── uiControlsComputer.ts
33
+ │ ├── constants.ts
34
+ │ ├── types.ts
35
+ │ └── ai-docs/
36
+ │ ├── AGENTS.md
37
+ │ └── ARCHITECTURE.md
38
+ └── ai-docs/
39
+ ├── AGENTS.md # Usage documentation
40
+ └── ARCHITECTURE.md # Task service architecture
41
+ ```
42
+
43
+ ## Source of Truth
44
+
45
+ - Task creation: `TaskFactory.ts`
46
+ - Task APIs and behavior: `Task.ts`, `voice/Voice.ts`, `voice/WebRTC.ts`, `digital/Digital.ts`
47
+ - Task management: `TaskManager.ts`
48
+ - Shared task types: `types.ts`, `constants.ts`
49
+ - Task lifecycle state machine: `state-machine/TaskStateMachine.ts`
50
+ - State machine types/events: `state-machine/constants.ts`, `state-machine/types.ts`
51
+
52
+ ## Public Types and Constants
53
+
54
+ - `TASK_EVENTS` enum (`types.ts`)
55
+ - `TaskData`, `TaskId`, `TaskResponse`, `TaskUIControls` (`types.ts`)
56
+ - `ITask`, `IVoice`, `IWebRTC`, `IDigital` (`types.ts`)
57
+ - `MEDIA_CHANNEL`, `TASK_CHANNEL_TYPE`, `VOICE_VARIANT` (`types.ts`)
58
+ - State machine: `TaskState`, `TaskEvent` (`state-machine/constants.ts`)
59
+
60
+ ## Key Capabilities
61
+
62
+ - **Task Creation by Channel**: `TaskFactory.ts` chooses `WebRTC`, `Voice`, or `Digital` based on `MEDIA_CHANNEL` and `webCallingService.loginOption`, so each task class exposes the correct capabilities for the media type.
63
+ - **Task Orchestration**: `TaskManager.ts` owns task lifecycle wiring—initializes listeners, receives task events, creates/updates tasks, emits SDK events, and exposes task collections for consumers.
64
+ - **Event Emission and Public APIs**: Task objects register listeners, update context, emit SDK events (e.g., `task:*`), and expose public methods that delegate to `contact.ts` for call control and to the state machine for transition validation.
65
+ - **AQM Contact Operations**: `contact.ts` builds the AQM request surface for call control (accept, hold, consult, transfer, wrapup, end) and is the primary bridge from `Task`/`Voice`/`WebRTC`/`Digital` methods to WCC task APIs.
66
+ - **Outbound Dialing**: `dialer.ts` exposes the AQM dialer request (`startOutdial`) used by `cc.startOutdial()` to create outbound voice tasks with success/failure event mapping.
67
+ - **State Machine Driven UI Controls**: The `state-machine/` folder provides the XState engine (`TaskStateMachine.ts`) plus `actions.ts`, `guards.ts`, `uiControlsComputer.ts`, `constants.ts`, and `types.ts` to compute valid transitions and UI control state. Capability-level details live in `state-machine/ai-docs/AGENTS.md`.
68
+
69
+ ---
70
+
71
+ ## Task Layer Overview
72
+
73
+ This section describes how the task layer constructs tasks, initializes the state machine, and wires AQM calls to task methods. It provides context for how the state machine fits into the end-to-end flow.
74
+
75
+ ### Task Class Hierarchy
76
+
77
+ - **Hierarchy**: `Task` (base) → `Voice` → `WebRTC`; `Digital` extends `Task`.
78
+ - **`Task` (base)**: Holds task data, emits SDK events, and provides default (unsupported) implementations for call control APIs.
79
+ - **`Voice`**: Adds hold/resume and consult-related capabilities for telephony tasks.
80
+ - **`WebRTC`**: Overrides `accept/decline` for WebRTC calls and hooks media events.
81
+ - **`Digital`**: Implements `accept` and refreshes digital task data/UI controls.
82
+
83
+ ### Task Creation and State Machine Initialization
84
+
85
+ - **Factory**: `TaskFactory.ts` selects `WebRTC`, `Voice`, or `Digital` based on `MEDIA_CHANNEL` and `webCallingService.loginOption`.
86
+ - **Initialization**: `Task.ts` creates a state machine actor using `createTaskStateMachine(...)`, wires action overrides (emitters), and starts the actor.
87
+ - **Task State**: The task holds `stateMachineService` and uses it to send `TaskEvent` payloads.
88
+
89
+ Example (state machine init inside a task object):
90
+
91
+ ```typescript
92
+ const machine = createTaskStateMachine(uiControlConfig, {
93
+ actions: {
94
+ emitTaskIncoming: ({event}) => task.emit('task:incoming', task),
95
+ },
96
+ });
97
+ const actor = createActor(machine);
98
+ actor.start();
99
+ ```
100
+
101
+ ### TaskManager Lifecycle Orchestration
102
+
103
+ - **Listener Setup**: Registers WebSocket listeners to receive CC events and map them to `TaskEvent` payloads.
104
+ - **Task Registry**: Creates tasks via `TaskFactory`, stores them in the task collection, and updates task data on incoming events.
105
+ - **Event Emission**: Re-emits `task:*` events on the task or `cc` object for SDK consumers.
106
+ - **Hydration/Recovery**: Handles state updates and transitions during reconnect/hydrate flows.
107
+
108
+ Example (backend event to state machine):
109
+
110
+ ```typescript
111
+ const payload = TaskManager.mapEventToTaskStateMachineEvent(event, taskData);
112
+ if (payload) {
113
+ task.sendStateMachineEvent(payload);
114
+ }
115
+ ```
116
+
117
+ ### AQM Call Control Integration
118
+
119
+ - **`contact.ts`**: Builds the AQM request surface for call control (hold, consult, transfer, wrapup, end). Task methods delegate to these calls, then drive state transitions based on success/failure events.
120
+ - **`dialer.ts`**: Exposes the `startOutdial` AQM request used by `cc.startOutdial()` to create outbound tasks.
121
+
122
+ Example (task method delegating to AQM):
123
+
124
+ ```typescript
125
+ // task.hold() -> contact.hold(...) -> stateMachine events on response
126
+ await contact.hold({interactionId});
127
+ stateMachineService.send({type: TaskEvent.HOLD_INITIATED, mediaResourceId});
128
+ ```
129
+
130
+ ### Sequential Flow (End-to-End)
131
+
132
+ 1. **WebSocket event arrives** → `TaskManager` maps CC event to `TaskEvent`.
133
+ 2. **Task creation** (if new) → `TaskFactory` builds `Voice`/`WebRTC`/`Digital`.
134
+ 3. **State machine actor starts** → `Task` wires emitters + UI control updates.
135
+ 4. **Task method called** (e.g., hold/transfer) → delegates to `contact.ts` or `dialer.ts`.
136
+ 5. **State transitions** → guards/actions update context and emit `task:*` events.
137
+ 6. **SDK consumers update UI** → `TaskUIControls` reflect the latest state.
138
+
139
+ ```mermaid
140
+ flowchart TD
141
+ A[WebSocket event arrives] --> B[TaskManager maps CC event to TaskEvent]
142
+ B --> C{Task exists?}
143
+ C -- No --> D[TaskFactory creates Voice/WebRTC/Digital]
144
+ C -- Yes --> E[Use existing task]
145
+ D --> F[Task initializes state machine actor]
146
+ E --> F
147
+ F --> G[Task method called (hold/transfer/etc)]
148
+ G --> H[contact.ts or dialer.ts API call]
149
+ H --> I[State machine transition]
150
+ I --> J[Actions + guards update context]
151
+ J --> K[Emit task:* events]
152
+ K --> L[TaskUIControls updated for SDK UI]
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Quick Start
158
+
159
+ ```typescript
160
+ // Listen for incoming tasks
161
+ cc.on('task:incoming', async (task) => {
162
+ console.log('Incoming task:', task.data.interactionId);
163
+
164
+ // Accept the task
165
+ await task.accept();
166
+
167
+ // Task operations
168
+ await task.hold();
169
+ await task.resume();
170
+ await task.end();
171
+ await task.wrapup({
172
+ wrapUpReason: 'Resolved',
173
+ auxCodeId: 'wrapup-code',
174
+ });
175
+ });
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Task Events
181
+
182
+ ### Emitted on `cc` object(ContactCenter)
183
+
184
+ | Event | When Emitted |
185
+ | --------------- | ---------------------------- |
186
+ | `task:incoming` | New task offered to agent |
187
+ | `task:hydrate` | Task data updated |
188
+ | `task:merged` | Tasks merged (EPDN transfer) |
189
+
190
+ ### Emitted on `task` object(ITask)
191
+
192
+ | Event | When Emitted |
193
+ | --------------------------------------------------------------------------- | ------------------------------------------------ |
194
+ | `task:assigned` | Task assigned to agent |
195
+ | `task:media` | Media stream/track updates are available |
196
+ | `task:unassigned` | Task is unassigned from agent |
197
+ | `task:offerContact` | Contact offer received/updated |
198
+ | `task:offerConsult` | Consult offer received |
199
+ | `task:hold` | Task placed on hold |
200
+ | `task:resume` | Task resumed from hold |
201
+ | `task:end` | Task ended |
202
+ | `task:rejected` | Task rejected / failure path emitted |
203
+ | `task:wrapup` | Task entering wrapup |
204
+ | `task:wrappedup` | Wrapup completed |
205
+ | `task:consulting` | Consult is in progress |
206
+ | `task:consultAccepted` | Consult accepted by destination party |
207
+ | `task:consultCreated` | Consultation started |
208
+ | `task:consultEnd` | Consultation ended |
209
+ | `task:autoAnswered` | Task was auto-answered |
210
+ | `task:recordingStarted` / `task:recordingPaused` / `task:recordingResumed` | Recording lifecycle updates |
211
+ | `task:conferenceStarted` / `task:conferenceEnded` / `task:conferenceFailed` | Conference lifecycle updates |
212
+ | `task:participantJoined` / `task:participantLeft` | Conference participant updates |
213
+ | `task:switchCall` | Switched between consult and main call |
214
+ | `task:outdialFailed` | Outdial operation failed |
215
+ | `task:ui-controls-updated` | UI controls changed due to state transition |
216
+ | `task:cleanup` | Internal cleanup signal emitted by state machine |
217
+
218
+ > Full list is defined in `TASK_EVENTS` (`types.ts`).
219
+
220
+ ### AI Assistant events on `task`
221
+
222
+ | Event | When Emitted |
223
+ | --- | --- |
224
+ | `REAL_TIME_TRANSCRIPTION` | A realtime transcript payload is received for the task interaction |
225
+ | `SUGGESTED_RESPONSE` | A final AI Assistant suggestion payload is received for the task interaction |
226
+
227
+ ---
228
+
229
+ ## API Reference
230
+
231
+ ### `cc.startOutdial(destination, origin)`
232
+
233
+ Initiate outbound call.
234
+
235
+ **Parameters**:
236
+
237
+ - `destination` (string): Phone number to call
238
+ - `origin` (string): Outbound ANI/caller ID
239
+
240
+ **Returns**: `Promise<TaskResponse>` (AQM response, not a Task instance)
241
+
242
+ **Example**:
243
+
244
+ ```typescript
245
+ const response = await cc.startOutdial('+14155551234', '+18005551000');
246
+
247
+ // Outdial task object is created asynchronously via TaskManager.
248
+ // Listen on cc/task events instead of treating startOutdial response as an ITask.
249
+ cc.on('task:incoming', (task) => {
250
+ task.on('task:assigned', () => {
251
+ console.log('Call connected');
252
+ });
253
+
254
+ task.on('task:end', () => {
255
+ console.log('Call ended');
256
+ });
257
+ });
258
+ ```
259
+
260
+ ---
261
+
262
+ ### `task.accept()`
263
+
264
+ Accept an incoming task.
265
+
266
+ **Returns**: `Promise<TaskResponse>`
267
+
268
+ **Example**:
269
+
270
+ ```typescript
271
+ cc.on('task:incoming', async (task) => {
272
+ await task.accept();
273
+ });
274
+ ```
275
+
276
+ ---
277
+
278
+ ### `task.hold(mediaResourceId?)` / `task.resume(mediaResourceId?)`
279
+
280
+ Put task on hold or resume.
281
+
282
+ **Parameters**:
283
+
284
+ - `mediaResourceId` (optional `string`): Media resource ID for the hold/resume operation
285
+
286
+ **Returns**: `Promise<TaskResponse>`
287
+
288
+ **Example**:
289
+
290
+ ```typescript
291
+ // Put on hold
292
+ await task.hold();
293
+
294
+ // Resume
295
+ await task.resume();
296
+ ```
297
+
298
+ ---
299
+
300
+ ### `task.end()`
301
+
302
+ End the current task.
303
+
304
+ **Returns**: `Promise<TaskResponse>`
305
+
306
+ **Example**:
307
+
308
+ ```typescript
309
+ await task.end();
310
+ ```
311
+
312
+ ---
313
+
314
+ ### `task.wrapup(params)`
315
+
316
+ Complete task with wrapup code.
317
+
318
+ **Parameters**:
319
+
320
+ - `wrapUpReason` (string, required): Wrapup reason text
321
+ - `auxCodeId` (string, required): Wrapup code ID
322
+
323
+ **Returns**: `Promise<TaskResponse>`
324
+
325
+ **Example**:
326
+
327
+ ```typescript
328
+ await task.wrapup({
329
+ wrapUpReason: 'Customer issue resolved',
330
+ auxCodeId: 'resolved-code',
331
+ });
332
+ ```
333
+
334
+ ---
335
+
336
+ ### `task.transfer(params)`
337
+
338
+ Transfer task to another destination.
339
+
340
+ **Parameters**:
341
+
342
+ - `to` (string): Agent ID, queue ID, or phone number
343
+ - `destinationType` ('queue' | 'agent' | 'dialNumber'): Destination type
344
+
345
+ **Returns**: `Promise<TaskResponse>`
346
+
347
+ **Example**:
348
+
349
+ ```typescript
350
+ // Transfer to queue
351
+ await task.transfer({
352
+ to: 'queue-123',
353
+ destinationType: 'queue',
354
+ });
355
+
356
+ // Transfer to agent
357
+ await task.transfer({
358
+ to: 'agent-456',
359
+ destinationType: 'agent',
360
+ });
361
+ ```
362
+
363
+ ---
364
+
365
+ ### `task.consult(params)`
366
+
367
+ Start consultation.
368
+
369
+ **Parameters**:
370
+
371
+ - `to` (string): Agent/queue/phone to consult
372
+ - `destinationType` ('queue' | 'agent' | 'dialNumber' | 'entryPoint'): Type
373
+
374
+ **Returns**: `Promise<TaskResponse>`
375
+
376
+ **Example**:
377
+
378
+ ```typescript
379
+ await task.consult({
380
+ to: 'agent-456',
381
+ destinationType: 'agent',
382
+ });
383
+
384
+ // Later: complete transfer (consulting voice flow uses transfer())
385
+ await task.transfer({
386
+ to: 'queue-123',
387
+ destinationType: 'queue',
388
+ });
389
+ // Or end consult
390
+ await task.endConsult();
391
+ ```
392
+
393
+ ---
394
+
395
+ ### `task.endConsult(consultEndPayload?)`
396
+
397
+ End consultation without transfer.
398
+
399
+ **Parameters**:
400
+
401
+ - `consultEndPayload` (optional `ConsultEndPayload`)
402
+
403
+ **Returns**: `Promise<TaskResponse>`
404
+
405
+ ---
406
+
407
+ ## Media Channels
408
+
409
+ | Channel | Description |
410
+ | ----------- | ------------------ |
411
+ | `telephony` | Voice calls |
412
+ | `chat` | Web chat |
413
+ | `email` | Email interactions |
414
+ | `social` | Social media |
415
+ | `sms` | SMS messages |
416
+ | `facebook` | Facebook Messenger |
417
+ | `whatsapp` | WhatsApp messages |
418
+
419
+ ---
420
+
421
+ ## Error Handling
422
+
423
+ ```typescript
424
+ try {
425
+ await task.transfer({
426
+ to: 'queue-123',
427
+ destinationType: 'queue',
428
+ });
429
+ } catch (error) {
430
+ console.error('Transfer failed:', error.message);
431
+ // error.data contains structured error info
432
+ }
433
+ ```
434
+
435
+ ---
436
+
437
+ ## Auto Wrapup
438
+
439
+ If enabled in agent profile, wrapup completes automatically after timeout:
440
+
441
+ ```typescript
442
+ task.on('task:wrappedup', () => {
443
+ console.log('Task wrapup completed');
444
+ });
445
+ ```
446
+
447
+ ---
448
+
449
+ ## Related
450
+
451
+ - [ARCHITECTURE.md](ARCHITECTURE.md) - Technical deep-dive
452
+ - [TaskManager.ts](../TaskManager.ts) - Manager implementation
453
+ - [types.ts](../types.ts) - Type definitions
454
+ - [../state-machine/ai-docs/AGENTS.md](../state-machine/ai-docs/AGENTS.md) - State machine implementation guide
455
+ - [../state-machine/ai-docs/ARCHITECTURE.md](../state-machine/ai-docs/ARCHITECTURE.md) - State machine internals