@onereach/step-voice 6.0.10 → 6.0.11-suh.0

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.
@@ -37,6 +37,5 @@ export default class GlobalCommand extends VoiceStep<Partial<INPUT>, OUTPUT, EVE
37
37
  exitThread(event: ITypedEvent<EVENT>, type: string, stepExit: string): Promise<void>;
38
38
  exitToThread(): void;
39
39
  buildGrammar(call: IVoiceCall, choices: TODO[]): Promise<any>;
40
- sleepUntilHangup(): void;
41
40
  }
42
41
  export {};
@@ -6,10 +6,6 @@ const types_1 = require("@onereach/flow-sdk/dst/types");
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const nanoid_1 = require("nanoid");
8
8
  const voice_1 = tslib_1.__importDefault(require("./voice"));
9
- var LocalEvents;
10
- (function (LocalEvents) {
11
- LocalEvents["hangup"] = "hangup";
12
- })(LocalEvents || (LocalEvents = {}));
13
9
  class GlobalCommand extends voice_1.default {
14
10
  get isGlobal() {
15
11
  return true;
@@ -71,18 +67,6 @@ class GlobalCommand extends voice_1.default {
71
67
  this.triggers.otherwise(async () => {
72
68
  await this.initGrammar();
73
69
  });
74
- const dataThread = this.process.getThread(this.dataThreadId);
75
- if (this.dataThreadId !== types_1.MAIN_THREAD_ID && dataThread != null) {
76
- this.triggers.hook({ name: "ending" /* ACTION.ending */, thread: this.dataThreadId, sync: true }, async () => {
77
- delete this.waits['@ending'];
78
- this.log.debug('sleep data thread', { thread: this.dataThreadId });
79
- dataThread.gotoState({
80
- direct: true,
81
- step: this.currentStepId,
82
- name: this.sleepUntilHangup.name
83
- });
84
- });
85
- }
86
70
  this.triggers.hook({ name: "waitEnd" /* ACTION.waitEnd */, thread: types_1.MAIN_THREAD_ID, sync: true }, async () => {
87
71
  delete this.waits['@waitEnd']; // TODO is there beter way to unsubscribe?
88
72
  await this.sendCommands(call, [{ name: 'grammar', params: {} }]);
@@ -93,13 +77,6 @@ class GlobalCommand extends voice_1.default {
93
77
  switch (event.params.type) {
94
78
  case 'hangup': {
95
79
  await this.hangup(call);
96
- if (dataThread?.state.name === this.sleepUntilHangup.name) {
97
- this.log.debug('wake data thread', { thread: this.dataThreadId });
98
- this.process.enqueue({
99
- thread: this.dataThreadId,
100
- name: LocalEvents.hangup
101
- });
102
- }
103
80
  return;
104
81
  }
105
82
  case 'avm-detected':
@@ -249,10 +226,5 @@ class GlobalCommand extends voice_1.default {
249
226
  asr: asr.getSettings(call.asr)
250
227
  };
251
228
  }
252
- sleepUntilHangup() {
253
- this.triggers.local(LocalEvents.hangup, () => {
254
- this.end();
255
- });
256
- }
257
229
  }
258
230
  exports.default = GlobalCommand;
@@ -3,5 +3,5 @@ import { ITypedEvent } from '@onereach/flow-sdk/dst/types';
3
3
  export default class WaitForCall extends VoiceStep<TODO, TODO, TODO> {
4
4
  get conversation(): string | import("@onereach/flow-sdk/dst/types").IMergeField;
5
5
  runStep(): Promise<void>;
6
- onCall(event: ITypedEvent<CallStartEvent>): Promise<unknown>;
6
+ onCall(event: ITypedEvent<CallStartEvent>): Promise<any>;
7
7
  }
package/dst/voice.d.ts CHANGED
@@ -50,7 +50,10 @@ export default class VoiceStep<TIn = unknown, TOut = unknown, TParams extends Vo
50
50
  handleCancel?: boolean;
51
51
  }, TOut, TParams> {
52
52
  runBefore(): Promise<void>;
53
+ exitStep(step: string, data?: any): any;
53
54
  sendCommands({ id, type, callback }: IVoiceCall, commands: TODO[]): Promise<void>;
55
+ handleDataThreadStart(): void;
56
+ handleDataThreadEnd(): void;
54
57
  handleHeartbeat(call: IVoiceCall): Promise<void>;
55
58
  handleCancel(): void;
56
59
  extractSectionMessages(sections: IPromtpSection[]): string;
@@ -74,4 +77,5 @@ export default class VoiceStep<TIn = unknown, TOut = unknown, TParams extends Vo
74
77
  rptsHasMore({ repromptsList }: TODO): boolean;
75
78
  get rptsIndex(): number;
76
79
  get rptsStarted(): boolean;
80
+ sleepUntilHangup(): Promise<void>;
77
81
  }
package/dst/voice.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.VoiceStepError = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
+ const types_1 = require("@onereach/flow-sdk/dst/types");
7
8
  const uuid_1 = require("uuid");
8
9
  // TODO: !!!!! import ConvStep from '@onereach/step-conversation/dst/step' !!!!!
9
10
  const step_1 = tslib_1.__importDefault(require("./step"));
@@ -16,9 +17,16 @@ class VoiceStep extends step_1.default {
16
17
  async runBefore() {
17
18
  await super.runBefore();
18
19
  if (this.cache != null) {
20
+ this.handleDataThreadStart();
19
21
  await this.handleHeartbeat(this.cache);
20
22
  }
21
23
  }
24
+ exitStep(step, data) {
25
+ if (this.cache != null) {
26
+ this.handleDataThreadEnd();
27
+ }
28
+ return super.exitStep(step, data);
29
+ }
22
30
  async sendCommands({ id, type, callback }, commands) {
23
31
  if (lodash_1.default.isEmpty(commands))
24
32
  return;
@@ -42,6 +50,45 @@ class VoiceStep extends step_1.default {
42
50
  if (result == null)
43
51
  throw new Error(`failed to send command to call: ${id}`);
44
52
  }
53
+ handleDataThreadStart() {
54
+ if (this.dataThreadId === types_1.MAIN_THREAD_ID)
55
+ return;
56
+ const dataThread = this.process.getThread(this.dataThreadId);
57
+ if (dataThread == null)
58
+ return;
59
+ if (dataThread.state.name === this.sleepUntilHangup.name) {
60
+ dataThread.waits[`thread/end/${this.thread.id}`] = {};
61
+ return;
62
+ }
63
+ this.triggers.hook({ name: "ending" /* ACTION.ending */, thread: this.dataThreadId, sync: true }, async () => {
64
+ delete this.waits['@ending'];
65
+ if (dataThread.state.name === this.sleepUntilHangup.name) {
66
+ this.log.debug('attach to sleep data thread', { thread: this.dataThreadId });
67
+ dataThread.waits[`thread/end/${this.thread.id}`] = {};
68
+ return;
69
+ }
70
+ this.log.debug('create sleep data thread', { thread: this.dataThreadId });
71
+ dataThread.gotoState({
72
+ direct: true,
73
+ step: this.currentStepId,
74
+ name: this.sleepUntilHangup.name,
75
+ waits: {
76
+ [`thread/end/${this.thread.id}`]: {}
77
+ }
78
+ });
79
+ });
80
+ }
81
+ handleDataThreadEnd() {
82
+ if (this.dataThreadId === types_1.MAIN_THREAD_ID)
83
+ return;
84
+ const dataThread = this.process.getThread(this.dataThreadId);
85
+ if (dataThread == null)
86
+ return;
87
+ if (dataThread.state.name === this.sleepUntilHangup.name) {
88
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
89
+ delete dataThread.waits[`thread/end/${this.thread.id}`];
90
+ }
91
+ }
45
92
  async handleHeartbeat(call) {
46
93
  if (call.vv >= 1) {
47
94
  if (this.thread.background) {
@@ -306,6 +353,14 @@ class VoiceStep extends step_1.default {
306
353
  get rptsStarted() {
307
354
  return this.rptsIndex !== 0;
308
355
  }
356
+ async sleepUntilHangup() {
357
+ const threadEndPrefix = 'thread/end/';
358
+ if (this.event.name.startsWith(threadEndPrefix)) {
359
+ this.event.processed = true;
360
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
361
+ delete this.waits[this.event.name];
362
+ }
363
+ }
309
364
  }
310
365
  exports.default = VoiceStep;
311
366
  module.exports = VoiceStep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "6.0.10",
3
+ "version": "6.0.11-suh.0",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",