@onereach/step-voice 4.0.0 → 4.0.3

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.
package/dst/Cancel.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export default class VoiceCancel extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
3
- runStep(): Promise<unknown>;
1
+ import VoiceStep from './voice';
2
+ export default class VoiceCancel extends VoiceStep {
3
+ get useQueue(): boolean;
4
+ runStep(): Promise<void>;
4
5
  }
5
- import VoiceStep from "./voice";
package/dst/Cancel.js CHANGED
@@ -10,7 +10,7 @@ class VoiceCancel extends voice_1.default {
10
10
  const channel = await this.fetchData();
11
11
  await this.cancel();
12
12
  await this.sendCommands(channel, [{ name: 'cancel' }]);
13
- return this.exitStep('next');
13
+ this.exitStep('next');
14
14
  }
15
15
  }
16
16
  exports.default = VoiceCancel;
package/dst/Choice.d.ts CHANGED
@@ -1,5 +1,30 @@
1
- export default class Choice extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
3
- runStep(): Promise<import("@onereach/flow-sdk/dst/types").ITriggers>;
1
+ import VoiceStep, { TODO, VoiceEvent } from './voice';
2
+ interface INPUT {
3
+ textType: string;
4
+ asr: TODO;
5
+ tts: TODO;
6
+ audio: TODO[];
7
+ choices: TODO[];
8
+ prompts: TODO[];
9
+ sensitiveData: {
10
+ muteStep: boolean;
11
+ muteUser: boolean;
12
+ muteBot: boolean;
13
+ };
14
+ noReplyDelay: number;
15
+ promptsTriggers: TODO[];
16
+ usePromptsTriggers: boolean;
4
17
  }
5
- import VoiceStep from "./voice";
18
+ interface EVENT extends VoiceEvent {
19
+ callRecording?: TODO;
20
+ exitId?: string;
21
+ digit?: string;
22
+ digits?: string;
23
+ phrases?: TODO[];
24
+ tags?: string[];
25
+ out?: string;
26
+ }
27
+ export default class Choice extends VoiceStep<INPUT, {}, EVENT> {
28
+ runStep(): Promise<void>;
29
+ }
30
+ export {};
package/dst/Choice.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
4
5
  const voice_1 = tslib_1.__importDefault(require("./voice"));
5
- const _ = require('lodash');
6
6
  const digitWords = [
7
7
  'zero',
8
8
  'one',
@@ -28,7 +28,7 @@ const containsOnlyDigits = (stringsList) => {
28
28
  return isOnlyDigits;
29
29
  };
30
30
  const getPhrasesForSpeechRec = (choices) => {
31
- const texts = _.flatMap(choices, (choice) => choice.options.map((opt) => opt.text));
31
+ const texts = lodash_1.default.flatMap(choices, (choice) => choice.options.map((opt) => opt.text));
32
32
  if (containsOnlyDigits(texts)) {
33
33
  return ['$OOV_CLASS_DIGIT_SEQUENCE'];
34
34
  }
@@ -54,7 +54,7 @@ const isRepromptTrigger = (recogResult, promptsTriggers) => {
54
54
  return r.lexical;
55
55
  });
56
56
  const triggers = promptsTriggers.flatMap((trigger) => {
57
- if (_.isEmpty(trigger.grammar)) {
57
+ if (lodash_1.default.isEmpty(trigger.grammar)) {
58
58
  return trigger.text.replace(/`/g, '');
59
59
  }
60
60
  else {
@@ -63,14 +63,14 @@ const isRepromptTrigger = (recogResult, promptsTriggers) => {
63
63
  });
64
64
  }
65
65
  });
66
- return !_.isEmpty(phrases.filter((e) => triggers.indexOf(e) !== -1));
66
+ return !lodash_1.default.isEmpty(phrases.filter((e) => triggers.includes(e)));
67
67
  };
68
68
  class Choice extends voice_1.default {
69
69
  async runStep() {
70
70
  const channel = await this.fetchData();
71
71
  const { textType, asr, tts, sensitiveData, noReplyDelay, usePromptsTriggers } = this.data;
72
72
  const exitExists = (exitId) => {
73
- return _.some(choices, (choice) => choice.exitId === exitId);
73
+ return lodash_1.default.some(choices, (choice) => choice.exitId === exitId);
74
74
  };
75
75
  const choices = this.buildChoices({ choices: this.data.choices });
76
76
  const ttsSettings = tts.getSettings(channel.tts);
@@ -90,8 +90,7 @@ class Choice extends voice_1.default {
90
90
  }
91
91
  };
92
92
  // There's a specific need to do so. There might be ${variable} section
93
- return this.triggers
94
- .once(`in/voice/${channel.id}/event`, async (event) => {
93
+ this.triggers.once(`in/voice/${channel.id}/event`, async (event) => {
95
94
  if (channel.recordCall && sensitiveData?.muteStep) {
96
95
  await this.sendCommands(channel, [{
97
96
  name: 'resume-record-session',
@@ -106,13 +105,13 @@ class Choice extends voice_1.default {
106
105
  case 'digit':
107
106
  case 'digits': {
108
107
  const params = event.params;
109
- const digit = params.digit || params.digits;
110
- const exitId = params.exitId;
108
+ const digit = params.digit ?? params.digits;
109
+ const exitId = params.exitId ?? '';
111
110
  // On bargeIn, we should stop playback
112
111
  if (exitExists(exitId)) {
113
112
  await this.transcript(channel, {
114
113
  keyPress: digit,
115
- message: _.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
114
+ message: lodash_1.default.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
116
115
  reportingSettingsKey,
117
116
  action: 'Call DTMF',
118
117
  actionFromBot: false
@@ -150,19 +149,19 @@ class Choice extends voice_1.default {
150
149
  }
151
150
  case 'recognition': {
152
151
  const params = event.params;
153
- const exitId = params.exitId;
152
+ const exitId = params.exitId ?? '';
154
153
  const phrases = params.phrases;
155
- if (_.isEmpty(phrases)) {
154
+ if (lodash_1.default.isEmpty(phrases)) {
156
155
  return this.exitStep('unrecognized', {});
157
156
  }
158
- const voiceProcessResult = _.chain(phrases)
157
+ const voiceProcessResult = lodash_1.default.chain(phrases)
159
158
  .map((p) => p.lexical)
160
159
  .join(' | ')
161
160
  .value();
162
161
  // On bargeIn, we should stop playback
163
162
  if (exitExists(exitId)) {
164
163
  await this.transcript(channel, {
165
- message: _.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
164
+ message: lodash_1.default.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
166
165
  voiceProcessResult,
167
166
  reportingSettingsKey,
168
167
  action: 'Call Recognition',
@@ -241,8 +240,8 @@ class Choice extends voice_1.default {
241
240
  default:
242
241
  return this.exitFlow();
243
242
  }
244
- })
245
- .otherwise(async () => {
243
+ });
244
+ this.triggers.otherwise(async () => {
246
245
  await this.transcript(channel, {
247
246
  sections: speechSections,
248
247
  reprompt: {
@@ -256,13 +255,15 @@ class Choice extends voice_1.default {
256
255
  command.params.sections = speechSections;
257
256
  command.params.timeout = this.rptsTimeout({ noReplyDelay, repromptsList });
258
257
  await this.sendCommands(channel, [
259
- ...channel.recordCall && sensitiveData?.muteStep ? [{
260
- name: 'stop-record-session',
261
- params: {
262
- muteUser: sensitiveData.muteUser,
263
- muteBot: sensitiveData.muteBot
264
- }
265
- }] : [],
258
+ ...channel.recordCall && sensitiveData?.muteStep
259
+ ? [{
260
+ name: 'stop-record-session',
261
+ params: {
262
+ muteUser: sensitiveData.muteUser,
263
+ muteBot: sensitiveData.muteBot
264
+ }
265
+ }]
266
+ : [],
266
267
  command
267
268
  ]);
268
269
  return this.exitFlow();
@@ -1,5 +1,10 @@
1
- export default class ConferenceDial extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
1
+ import VoiceStep from './voice';
2
+ export default class ConferenceDial extends VoiceStep<{
3
+ stayInConference: boolean;
4
+ sourceConf: string;
5
+ botNumber: string;
6
+ headers?: Record<string, string>;
7
+ hearOnly: boolean;
8
+ }> {
3
9
  runStep(): Promise<void>;
4
10
  }
5
- import VoiceStep from "./voice";
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
4
5
  const voice_1 = tslib_1.__importDefault(require("./voice"));
5
- const _ = require('lodash');
6
6
  class ConferenceDial extends voice_1.default {
7
7
  async runStep() {
8
8
  const channel = await this.fetchData();
@@ -17,7 +17,7 @@ class ConferenceDial extends voice_1.default {
17
17
  return this.exitFlow();
18
18
  }
19
19
  else {
20
- return this.exitStep('next', _.omit(event.params, ['type']));
20
+ return this.exitStep('next', lodash_1.default.omit(event.params, ['type']));
21
21
  }
22
22
  case 'conference-end':
23
23
  return this.data.stayInConference ? this.exitStep('next') : this.exitFlow();
@@ -1,15 +1,39 @@
1
- export default class GlobalCommand extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
1
+ import { ITypedEvent } from '@onereach/flow-sdk/dst/types';
2
+ import VoiceStep, { IVoiceChannel, TODO, VoiceEvent } from './voice';
3
+ interface INPUT {
4
+ asr: TODO;
5
+ processHangUp: 'user' | 'bot' | 'both' | 'none';
6
+ recordAfterTransfer: boolean;
7
+ recordCall: boolean;
8
+ choices: TODO[];
9
+ }
10
+ interface OUTPUT {
11
+ type: string;
12
+ digit?: string;
13
+ value?: string;
14
+ interpretation?: TODO[];
15
+ callRecording?: TODO;
16
+ tags?: string[];
17
+ out?: string;
18
+ }
19
+ interface EVENT extends VoiceEvent {
20
+ callRecording?: TODO;
21
+ exitId?: string;
22
+ digit?: string;
23
+ digits?: string;
24
+ phrases?: TODO[];
25
+ tags?: string[];
26
+ out?: string;
27
+ }
28
+ export default class GlobalCommand extends VoiceStep<INPUT, OUTPUT, EVENT> {
29
+ get isGlobal(): boolean;
30
+ get autoCancel(): boolean | undefined;
3
31
  runStep(): Promise<void>;
4
32
  globThread(): Promise<void>;
5
- hangup(channel: any, event: any): Promise<unknown>;
6
- exitThread(event: any, type: any, stepExit: any): Promise<void>;
7
- exitToThread(): Promise<void>;
8
- buildGrammar(channel: any, choices: any): Promise<{
9
- id: string;
10
- choices: any;
11
- asr: any;
12
- }>;
33
+ hangup(channel: IVoiceChannel): Promise<unknown>;
34
+ exitThread(event: ITypedEvent<EVENT>, type: string, stepExit: string): Promise<void>;
35
+ exitToThread(): void;
36
+ buildGrammar(channel: IVoiceChannel, choices: TODO[]): Promise<any>;
13
37
  exitFlow(): unknown;
14
38
  }
15
- import VoiceStep from "./voice";
39
+ export {};
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
5
+ const nanoid_1 = require("nanoid");
4
6
  const voice_1 = tslib_1.__importDefault(require("./voice"));
5
- const { nanoid } = require('nanoid');
6
- const _ = require('lodash');
7
7
  class GlobalCommand extends voice_1.default {
8
8
  get isGlobal() {
9
9
  return true;
10
10
  }
11
+ get autoCancel() {
12
+ return undefined;
13
+ }
11
14
  async runStep() {
12
15
  const channel = await this.fetchData();
13
16
  // if (recordCall || _.includes(['bot', 'both'], processHangUp)) {
@@ -57,9 +60,9 @@ class GlobalCommand extends voice_1.default {
57
60
  async globThread() {
58
61
  const channel = await this.fetchData();
59
62
  const choices = this.buildChoices({ choices: this.data.choices });
60
- const exitExists = (exitId) => {
61
- return _.some(choices, (choice) => choice.exitId === exitId);
62
- };
63
+ function exitExists(exitId) {
64
+ return lodash_1.default.some(choices, (choice) => choice.exitId === exitId);
65
+ }
63
66
  if (channel.autoHangup) {
64
67
  this.triggers.local('thread/end/main', async () => {
65
68
  delete this.thread.waits['thread/end/main'];
@@ -68,8 +71,8 @@ class GlobalCommand extends voice_1.default {
68
71
  channel.autoHangup = false;
69
72
  await this.updateData();
70
73
  this.local.background = undefined;
71
- this.sendCommands(channel, [{ name: 'hangup' }]);
72
- this.process.main.enqueueAndRun({ name: 'ending' });
74
+ await this.sendCommands(channel, [{ name: 'hangup' }]);
75
+ void this.process.main.enqueueAndRun({ name: 'ending' });
73
76
  this.exitFlow();
74
77
  }
75
78
  });
@@ -78,46 +81,46 @@ class GlobalCommand extends voice_1.default {
78
81
  event.processed = undefined;
79
82
  switch (event.params.type) {
80
83
  case 'hangup': {
81
- await this.hangup(channel, event);
84
+ await this.hangup(channel);
82
85
  return this.end();
83
86
  }
84
87
  case 'avm-detected':
85
88
  // this.event = {};
86
- return this.exitThread(event, 'AMD', 'AMD');
89
+ return await this.exitThread(event, 'AMD', 'AMD');
87
90
  case 'digit':
88
91
  case 'digits': {
89
92
  const params = event.params;
90
- const exitId = params.exitId;
91
- if (exitExists(params.exitId)) {
93
+ const exitId = params.exitId ?? '';
94
+ if (exitExists(exitId)) {
92
95
  await this.transcript(channel, {
93
96
  previousTranscriptId: channel.lastTranscriptId,
94
97
  keyPress: params.digit,
95
- message: _.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
98
+ message: lodash_1.default.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
96
99
  action: 'Call DTMF',
97
100
  reportingSettingsKey: 'transcript',
98
101
  actionFromBot: false
99
102
  });
100
- return this.exitThread(event, 'digit', params.exitId);
103
+ return await this.exitThread(event, 'digit', exitId);
101
104
  }
102
105
  return {};
103
106
  }
104
107
  case 'recognition': {
105
108
  const params = event.params;
106
- const exitId = params.exitId;
107
- if (exitExists(params.exitId)) {
108
- const voiceProcessResult = _.chain(params.phrases)
109
+ const exitId = params.exitId ?? '';
110
+ if (exitExists(exitId)) {
111
+ const voiceProcessResult = lodash_1.default.chain(params.phrases)
109
112
  .map((p) => p.lexical)
110
113
  .join(' | ')
111
114
  .value();
112
115
  await this.transcript(channel, {
113
116
  previousTranscriptId: channel.lastTranscriptId,
114
- message: _.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
117
+ message: lodash_1.default.replace(this.getExitStepLabel(exitId), /^(\d+\. )?(~ )?/, ''),
115
118
  action: 'Call Recognition',
116
119
  voiceProcessResult,
117
120
  reportingSettingsKey: 'transcript',
118
121
  actionFromBot: false
119
122
  });
120
- return this.exitThread(event, 'voice', params.exitId);
123
+ return await this.exitThread(event, 'voice', exitId);
121
124
  }
122
125
  return {};
123
126
  }
@@ -128,7 +131,7 @@ class GlobalCommand extends voice_1.default {
128
131
  }
129
132
  });
130
133
  }
131
- async hangup(channel, event) {
134
+ async hangup(channel) {
132
135
  await this.handleHangup(channel);
133
136
  // if (channel.recordCall || _.includes(['bot', 'both'], processHangUp)) {
134
137
  // // turn off protection of session deletion by "End" step
@@ -137,20 +140,20 @@ class GlobalCommand extends voice_1.default {
137
140
  const isHangedUpByBot = channel.sessionEndedBy === 'Bot';
138
141
  const hangUpType = isHangedUpByBot ? 'bot hang up' : 'user hang up';
139
142
  // process call recording in hangup event
140
- if (channel.recordCall && event.params.callRecording) {
141
- return this.exitThread(event, hangUpType, 'hang up');
143
+ if (channel.recordCall && this.event.params.callRecording != null) {
144
+ return await this.exitThread(this.event, hangUpType, 'hang up');
142
145
  }
143
146
  switch (this.data.processHangUp) {
144
147
  case 'user':
145
148
  return isHangedUpByBot
146
149
  ? this.exitFlow()
147
- : this.exitThread({}, hangUpType, 'hang up');
150
+ : await this.exitThread(this.event, hangUpType, 'hang up');
148
151
  case 'bot':
149
152
  return isHangedUpByBot
150
- ? this.exitThread({}, hangUpType, 'hang up')
153
+ ? await this.exitThread(this.event, hangUpType, 'hang up')
151
154
  : this.exitFlow();
152
155
  case 'both':
153
- return this.exitThread({}, hangUpType, 'hang up');
156
+ return await this.exitThread(this.event, hangUpType, 'hang up');
154
157
  case 'none':
155
158
  default:
156
159
  return this.exitFlow();
@@ -158,28 +161,26 @@ class GlobalCommand extends voice_1.default {
158
161
  }
159
162
  async exitThread(event, type, stepExit) {
160
163
  // this.log.warn('EXIT HOOK', type, stepExit);
161
- const params = event.params || {};
162
- const data = {
163
- type
164
- };
165
- if (!_.isEmpty(params.tags)) {
164
+ const params = event.params;
165
+ const data = { type };
166
+ if (!lodash_1.default.isEmpty(params.tags)) {
166
167
  data.tags = params.tags;
167
168
  }
168
- if (!_.isEmpty(params.out)) {
169
+ if (!lodash_1.default.isEmpty(params.out)) {
169
170
  data.out = params.out;
170
171
  }
171
- const digits = params.digits || params.digit;
172
- if (!_.isEmpty(digits)) {
172
+ const digits = params.digits ?? params.digit;
173
+ if (!lodash_1.default.isEmpty(digits)) {
173
174
  data.digit = digits;
174
175
  data.value = digits;
175
176
  }
176
- if (!_.isEmpty(params.phrases)) {
177
+ if (!lodash_1.default.isEmpty(params.phrases)) {
177
178
  const phrases = params.phrases;
178
179
  data.value = phrases[0].text;
179
180
  data.interpretation = phrases;
180
181
  }
181
182
  // add information about call recording to a merge field
182
- if (!_.isEmpty(params.callRecording)) {
183
+ if (!lodash_1.default.isEmpty(params.callRecording)) {
183
184
  data.callRecording = params.callRecording;
184
185
  }
185
186
  // await this.sendCommands(channel, [{
@@ -189,7 +190,7 @@ class GlobalCommand extends voice_1.default {
189
190
  // channel.global = null;
190
191
  await this.updateData();
191
192
  await this.process.runThread({
192
- id: `${stepExit}_${nanoid(8)}`,
193
+ id: `${stepExit}_${(0, nanoid_1.nanoid)(8)}`,
193
194
  state: {
194
195
  name: 'exitToThread',
195
196
  result: {
@@ -204,7 +205,7 @@ class GlobalCommand extends voice_1.default {
204
205
  // this is required to mark event as handled
205
206
  // this.gotoState(this.state, { name: 'exiting' })
206
207
  }
207
- async exitToThread() {
208
+ exitToThread() {
208
209
  this.thread.jumpTo(this.state.exitStep, this.state.result);
209
210
  }
210
211
  async buildGrammar(channel, choices) {
package/dst/Hangup.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export default class Hangup extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
1
+ import VoiceStep from './voice';
2
+ export default class Hangup extends VoiceStep {
3
3
  runStep(): Promise<void>;
4
4
  }
5
- import VoiceStep from "./voice";
package/dst/Hangup.js CHANGED
@@ -24,7 +24,7 @@ class Hangup extends voice_1.default {
24
24
  await this.sendCommands(channel, [{ name: 'hangup' }]);
25
25
  }
26
26
  catch (err) {
27
- this.log.warn(`Catch hangup error: ${err}`);
27
+ this.log.warn('hangup error', err);
28
28
  return this.exitStep('next');
29
29
  }
30
30
  return this.exitFlow();
@@ -1,5 +1,12 @@
1
- export default class IdleMusic extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
3
- runStep(): Promise<unknown>;
1
+ import VoiceStep from './voice';
2
+ interface INPUT {
3
+ idleDuration: number;
4
+ idleMusicDelay: number;
5
+ idleMusicEnabled: boolean;
6
+ customIdleMusic: boolean;
7
+ idleMusicUrl: string;
4
8
  }
5
- import VoiceStep from "./voice";
9
+ export default class IdleMusic extends VoiceStep<INPUT> {
10
+ runStep(): Promise<void>;
11
+ }
12
+ export {};
@@ -1,29 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
5
+ const joi_1 = tslib_1.__importDefault(require("joi"));
6
+ const timestring_1 = tslib_1.__importDefault(require("timestring"));
4
7
  const voice_1 = tslib_1.__importDefault(require("./voice"));
5
- const joi = require('joi');
6
- const timestring = require('timestring');
7
- const _ = require('lodash');
8
- const schema = joi.object().keys({
9
- idleMusicEnabled: joi.boolean().required(),
10
- idleDuration: joi.number().min(10000).max(1800000).required(),
11
- idleMusicDelay: joi.when('idleMusicEnabled', {
8
+ const schema = joi_1.default.object().keys({
9
+ idleMusicEnabled: joi_1.default.boolean().required(),
10
+ idleDuration: joi_1.default.number().min(10000).max(1800000).required(),
11
+ idleMusicDelay: joi_1.default.when('idleMusicEnabled', {
12
12
  is: true,
13
- then: joi.number().min(1).max(30000).required()
13
+ then: joi_1.default.number().min(1).max(30000).required()
14
14
  }),
15
- customIdleMusic: joi.boolean(),
16
- idleMusicUrl: joi.when('customIdleMusic', {
15
+ customIdleMusic: joi_1.default.boolean(),
16
+ idleMusicUrl: joi_1.default.when('customIdleMusic', {
17
17
  is: true,
18
- then: joi.string().uri().required()
18
+ then: joi_1.default.string().uri().required()
19
19
  })
20
20
  });
21
21
  class IdleMusic extends voice_1.default {
22
22
  async runStep() {
23
23
  const channel = await this.fetchData();
24
24
  const { idleDuration, idleMusicDelay, idleMusicEnabled, customIdleMusic, idleMusicUrl } = this.data;
25
- const idleDurationMs = timestring(_.get(idleDuration, 'input', '30s'), _.get(idleDuration, 'outputMode', 'ms'));
26
- const idleMusicDelayMs = timestring(_.get(idleMusicDelay, 'input', '3s'), _.get(idleMusicDelay, 'outputMode', 'ms'));
25
+ const idleDurationMs = (0, timestring_1.default)(lodash_1.default.get(idleDuration, 'input', '30s'), lodash_1.default.get(idleDuration, 'outputMode', 'ms'));
26
+ const idleMusicDelayMs = (0, timestring_1.default)(lodash_1.default.get(idleMusicDelay, 'input', '3s'), lodash_1.default.get(idleMusicDelay, 'outputMode', 'ms'));
27
27
  const { error: validationError } = await schema.validateAsync({
28
28
  idleMusicEnabled,
29
29
  customIdleMusic,
@@ -31,7 +31,7 @@ class IdleMusic extends voice_1.default {
31
31
  idleMusicDelay: idleMusicDelayMs,
32
32
  idleDuration: idleDurationMs
33
33
  });
34
- if (validationError)
34
+ if (validationError != null)
35
35
  throw new Error(validationError.message);
36
36
  const command = {
37
37
  name: 'idle',
@@ -39,11 +39,11 @@ class IdleMusic extends voice_1.default {
39
39
  disabled: !idleMusicEnabled,
40
40
  timeout: idleMusicDelayMs,
41
41
  maxDuration: idleDurationMs,
42
- musicUrl: idleMusicUrl || null
42
+ musicUrl: idleMusicUrl !== '' ? idleMusicUrl : undefined
43
43
  }
44
44
  };
45
45
  await this.sendCommands(channel, [command]);
46
- return this.exitStep('next');
46
+ this.exitStep('next');
47
47
  }
48
48
  }
49
49
  exports.default = IdleMusic;
@@ -1,10 +1,11 @@
1
- export default class InitiateCall extends VoiceStep<any, any> {
1
+ export default class InitiateCall extends VoiceStep<any, any, import("./voice").VoiceEvent> {
2
2
  constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
3
- get conversation(): string | undefined;
3
+ get conversation(): string;
4
+ get autoCancel(): undefined;
4
5
  runStep(): Promise<void>;
5
6
  waitForCall(): Promise<void>;
6
7
  error: {
7
- name: any;
8
+ name: string;
8
9
  message: string;
9
10
  stack: {};
10
11
  } | undefined;
@@ -8,7 +8,10 @@ const uuid = require('uuid');
8
8
  const defaultSessionTimeout = 5 * 60 * 1000;
9
9
  class InitiateCall extends voice_1.default {
10
10
  get conversation() {
11
- return this.step.dataOut.name;
11
+ return this.step.dataOut?.name ?? 'conversation';
12
+ }
13
+ get autoCancel() {
14
+ return undefined;
12
15
  }
13
16
  async runStep() {
14
17
  const { from: botNumber, endUserNumber, sipHost, sipUser, sipPassword, timeout, headers, originationId = uuid.v4(), enableSpoofCallerId, spoofCallerId } = this.data;
@@ -68,23 +71,12 @@ class InitiateCall extends voice_1.default {
68
71
  }
69
72
  });
70
73
  }
71
- this.gotoState({
72
- name: 'waitForCall',
73
- originationId
74
- });
74
+ await this.setDataOut({ id: originationId });
75
+ this.gotoState('waitForCall');
75
76
  }
76
77
  async waitForCall() {
77
78
  const { from: botNumber, endUserNumber, isAMD, asr, tts, sessionTimeout } = this.data;
78
- const originationId = this.state.originationId;
79
- const sessionTimeoutMs = timestring(`${sessionTimeout} min`, 'ms') || defaultSessionTimeout;
80
- // let channel = await this.getDataOut();
81
- // if (!_.get(channel, ['originationId'])) {
82
- // channel = {
83
- // originationId: require('uuid').v4(),
84
- // callback: {}
85
- // };
86
- // await this.setDataOut(channel);
87
- // }
79
+ const { id: originationId } = await this.getDataOut();
88
80
  this.triggers.once(`in/voice/${originationId}/event`, async (event) => {
89
81
  switch (event.params.type) {
90
82
  case 'is_flow_ready': {
@@ -111,6 +103,7 @@ class InitiateCall extends voice_1.default {
111
103
  delete channel.from;
112
104
  delete channel.to;
113
105
  if (!this.session.key) {
106
+ const sessionTimeoutMs = timestring(`${sessionTimeout} min`, 'ms') || defaultSessionTimeout;
114
107
  await this.session.start({
115
108
  key: channel.id,
116
109
  timeout: sessionTimeoutMs,
@@ -1,5 +1,9 @@
1
- export default class JoinConference extends VoiceStep<any, any> {
2
- constructor(thread: import("@onereach/flow-sdk/dst/types").IThread, stepData: import("@onereach/flow-sdk/dst/types").IStepData<any>);
3
- runStep(): Promise<import("@onereach/flow-sdk/dst/types").ITriggers>;
1
+ import VoiceStep from './voice';
2
+ interface INPUT {
3
+ conferenceName: string;
4
+ stayInConference: boolean;
4
5
  }
5
- import VoiceStep from "./voice";
6
+ export default class JoinConference extends VoiceStep<INPUT> {
7
+ runStep(): Promise<void>;
8
+ }
9
+ export {};