@onereach/step-voice 7.0.46-deskphoneintegration.13 → 7.0.46-deskphoneintegration.14

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.
@@ -31,7 +31,7 @@ export default class WaitForDeskPhoneCall extends VoiceStep<TODO, TODO, TODO> {
31
31
  * on the A-leg stream `in/voice/<carrierCallId>`. Returns without exitStep/exitFlow so the step
32
32
  * stays alive (mirrors Initiate Call.waitForCall).
33
33
  */
34
- awaitConsultComplete(): Promise<void>;
34
+ awaitConsultComplete(): Promise<any>;
35
35
  /** Minimal routable envelope that carries completion commands on the LIVE A-leg. */
36
36
  carrierEnvelope(x: DeskphoneXferState): CarrierEnvelope;
37
37
  onConsultEvent(event: IEvent<VoiceEvent>): Promise<any>;
@@ -34,12 +34,16 @@ class WaitForDeskPhoneCall extends voice_1.default {
34
34
  // Resume guard: a consult is already in flight (persisted across a thread resume) -> go straight
35
35
  // back to the waiting state and re-arm the completion listeners (named-state re-arm pattern).
36
36
  if (this.state.deskphoneXfer?.carrierCallId) {
37
+ const deskphoneXfer = this.state.deskphoneXfer;
37
38
  this.log.info('deskphone:trace:oncall runStep resume-guard fired', {
38
- carrierCallId: this.state.deskphoneXfer?.carrierCallId,
39
- consultCallId: this.state.deskphoneXfer?.consultCallId ?? null,
40
- phase: this.state.deskphoneXfer?.phase ?? null
39
+ carrierCallId: deskphoneXfer.carrierCallId,
40
+ consultCallId: deskphoneXfer.consultCallId ?? null,
41
+ phase: deskphoneXfer.phase ?? null,
42
+ carriedVia: 'gotoState-payload'
41
43
  });
42
- return this.gotoState('awaitConsultComplete');
44
+ // Re-pass the payload INTO the gotoState argument: `gotoState('awaitConsultComplete')` would
45
+ // replace `this.state` with `{ name, step }` and drop deskphoneXfer (thread.js:1053/1540).
46
+ return this.gotoState({ name: 'awaitConsultComplete', deskphoneXfer });
43
47
  }
44
48
  }
45
49
  async onCall(event) {
@@ -142,18 +146,27 @@ class WaitForDeskPhoneCall extends voice_1.default {
142
146
  carrierCallId: entry.callId,
143
147
  entry
144
148
  });
145
- this.state.deskphoneXfer = {
149
+ // NOTE: `gotoState(state)` REPLACES `this.state` entirely with the object passed to it
150
+ // (flow-sdk thread.js:1053 builds the action with `state: state`; the runner's `goto` handler
151
+ // at thread.js:1523/1540 does `const nextState = action.state; ... this.state = nextState`).
152
+ // Any field set on `this.state` BEFORE the transition is therefore DISCARDED. The payload must
153
+ // ride ALONG with the state object we hand to gotoState so it survives onto `this.state` in the
154
+ // next state (and across a thread resume, since the whole state object is what persists).
155
+ const deskphoneXfer = {
146
156
  fromUser,
147
157
  entry,
158
+ // C = the dialed PSTN target, surfaced on `channel.to` (same value previously stored on
159
+ // `this.state.deskphoneXfer` when it was typed TODO). Cast preserves the exact prior value.
148
160
  C: event.params.channel.to,
149
161
  consultCallId: call.id,
150
162
  carrierCallId: entry.callId,
151
163
  phase: 'await-bye'
152
164
  };
153
165
  this.log.info('deskphone:trace:xfer state stashed; transitioning to awaitConsultComplete', {
154
- deskphoneXfer: this.state.deskphoneXfer
166
+ deskphoneXfer,
167
+ carriedVia: 'gotoState-payload'
155
168
  });
156
- return this.gotoState('awaitConsultComplete');
169
+ return this.gotoState({ name: 'awaitConsultComplete', deskphoneXfer });
157
170
  }
158
171
  /**
159
172
  * Named waiting state (resolves MEDIUM-1). Re-armed on every entry so the thread parks here across
@@ -163,14 +176,28 @@ class WaitForDeskPhoneCall extends voice_1.default {
163
176
  */
164
177
  async awaitConsultComplete() {
165
178
  this.log.warn("awaitConsultComplete Wait for desk phone");
166
- const { carrierCallId, consultCallId } = this.state.deskphoneXfer;
179
+ // `deskphoneXfer` rides on `this.state` because it was carried in as part of the gotoState
180
+ // payload (see onCall / resume-guard). Read it defensively: never destructure a possibly-absent
181
+ // object (that threw `Cannot destructure property 'carrierCallId' of ... as it is undefined`).
182
+ const deskphoneXfer = this.state.deskphoneXfer;
167
183
  this.log.info('deskphone:trace:xfer awaitConsultComplete entry', {
168
- carrierCallId,
169
- consultCallId,
170
- carrierTrigger: `in/voice/${carrierCallId}`,
171
- consultTrigger: `in/voice/${consultCallId}`,
172
- phase: this.state.deskphoneXfer?.phase ?? null
184
+ present: deskphoneXfer != null,
185
+ carriedVia: 'this.state.deskphoneXfer',
186
+ carrierCallId: deskphoneXfer?.carrierCallId ?? null,
187
+ consultCallId: deskphoneXfer?.consultCallId ?? null,
188
+ carrierTrigger: deskphoneXfer != null ? `in/voice/${deskphoneXfer.carrierCallId}` : null,
189
+ consultTrigger: deskphoneXfer != null ? `in/voice/${deskphoneXfer.consultCallId}` : null,
190
+ phase: deskphoneXfer?.phase ?? null
173
191
  });
192
+ if (deskphoneXfer == null) {
193
+ // Should not happen now that the payload is carried through gotoState; guard rather than throw
194
+ // a TypeError so the step exits safely instead of crashing the thread.
195
+ this.log.warn('deskphone:trace:xfer deskphoneXfer missing in awaitConsultComplete', {
196
+ state: this.state ?? null
197
+ });
198
+ return this.exitStep('trigger');
199
+ }
200
+ const { carrierCallId, consultCallId } = deskphoneXfer;
174
201
  this.triggers.local(`in/voice/${carrierCallId}`, this.onConsultEvent);
175
202
  this.triggers.local(`in/voice/${consultCallId}`, this.onConsultEvent);
176
203
  this.log.info('deskphone:trace:xfer awaitConsultComplete both triggers.local registered', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.46-deskphoneintegration.13",
3
+ "version": "7.0.46-deskphoneintegration.14",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",