@onereach/step-voice 5.0.4-lcltrd.3 → 5.0.4
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/Global Command.js +3 -6
- package/dst/Transfer.d.ts +4 -2
- package/dst/Transfer.js +2 -2
- package/dst/step.d.ts +2 -2
- package/dst/step.js +23 -24
- package/dst/voice.d.ts +6 -8
- package/dst/voice.js +6 -14
- package/package.json +7 -9
package/dst/Global Command.js
CHANGED
|
@@ -7,14 +7,15 @@ const nanoid_1 = require("nanoid");
|
|
|
7
7
|
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
8
8
|
class GlobalCommand extends voice_1.default {
|
|
9
9
|
get isGlobal() {
|
|
10
|
-
return this.thread.id === this.
|
|
10
|
+
return this.thread.id === `G:${this.conversationName}`;
|
|
11
11
|
}
|
|
12
12
|
get useQueue() {
|
|
13
13
|
return this.isGlobal;
|
|
14
14
|
}
|
|
15
15
|
async runStep() {
|
|
16
|
+
const gcThreadId = `G:${this.conversationName}`;
|
|
16
17
|
await this.process.runThread({
|
|
17
|
-
id:
|
|
18
|
+
id: gcThreadId,
|
|
18
19
|
state: {
|
|
19
20
|
name: 'globThread',
|
|
20
21
|
step: this.step.id,
|
|
@@ -70,10 +71,6 @@ class GlobalCommand extends voice_1.default {
|
|
|
70
71
|
}
|
|
71
72
|
this.end();
|
|
72
73
|
});
|
|
73
|
-
// TODO remove this hack that prevents this.triggers.once execution below
|
|
74
|
-
// currently it skips logic to override triggers (is there better way to do it?)
|
|
75
|
-
if (this.event.name.startsWith('@end'))
|
|
76
|
-
return;
|
|
77
74
|
}
|
|
78
75
|
this.triggers.once(`in/voice/${call.id}/event`, async (event) => {
|
|
79
76
|
event.processed = undefined;
|
package/dst/Transfer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import VoiceStep, {
|
|
1
|
+
import VoiceStep, { EventType } from './voice';
|
|
2
2
|
interface INPUT {
|
|
3
3
|
destination: string;
|
|
4
4
|
phoneNumber: string;
|
|
@@ -14,7 +14,9 @@ interface INPUT {
|
|
|
14
14
|
sipUser?: string;
|
|
15
15
|
sipPassword?: string;
|
|
16
16
|
}
|
|
17
|
-
interface EVENT
|
|
17
|
+
interface EVENT {
|
|
18
|
+
type: EventType;
|
|
19
|
+
error?: string | Error;
|
|
18
20
|
originateDisposition?: string;
|
|
19
21
|
}
|
|
20
22
|
export default class Transfer extends VoiceStep<INPUT, {}, EVENT> {
|
package/dst/Transfer.js
CHANGED
|
@@ -23,8 +23,8 @@ class Transfer extends voice_1.default {
|
|
|
23
23
|
}
|
|
24
24
|
case 'bridge/ended': {
|
|
25
25
|
const { error, originateDisposition } = event.params;
|
|
26
|
-
const isSuccess = error === 'NORMAL_CLEARING'
|
|
27
|
-
(lodash_1.default.isUndefined(originateDisposition) || originateDisposition === 'SUCCESS');
|
|
26
|
+
const isSuccess = error === 'NORMAL_CLEARING'
|
|
27
|
+
&& (lodash_1.default.isUndefined(originateDisposition) || originateDisposition === 'SUCCESS');
|
|
28
28
|
if (isSuccess) {
|
|
29
29
|
await this.transcript(call, {
|
|
30
30
|
action: 'Transfer Ended - Answered',
|
package/dst/step.d.ts
CHANGED
|
@@ -16,8 +16,7 @@ export default class ConvStep<TData = unknown, TIn = unknown, TOut = unknown, TP
|
|
|
16
16
|
private convDataCache?;
|
|
17
17
|
get cache(): TData & IConversationData | undefined;
|
|
18
18
|
get conversation(): string | IMergeField;
|
|
19
|
-
get
|
|
20
|
-
get globalThreadId(): string;
|
|
19
|
+
get conversationName(): string;
|
|
21
20
|
/** id of the thread where conversation data is stored */
|
|
22
21
|
get dataThreadId(): IThreadId;
|
|
23
22
|
get isGlobal(): boolean;
|
|
@@ -29,6 +28,7 @@ export default class ConvStep<TData = unknown, TIn = unknown, TOut = unknown, TP
|
|
|
29
28
|
runBefore(): Promise<void>;
|
|
30
29
|
runAfter(): Promise<void>;
|
|
31
30
|
hasActiveGlobal(): Promise<boolean>;
|
|
31
|
+
setLocalTriggers(): Promise<void>;
|
|
32
32
|
waitForConversation(): Promise<void>;
|
|
33
33
|
protected onSkipEvent(): Promise<void>;
|
|
34
34
|
cancel(): Promise<void>;
|
package/dst/step.js
CHANGED
|
@@ -12,7 +12,7 @@ class ConvStep extends step_1.default {
|
|
|
12
12
|
throw new Error('missing data.conversation');
|
|
13
13
|
return this.data.conversation;
|
|
14
14
|
}
|
|
15
|
-
get
|
|
15
|
+
get conversationName() {
|
|
16
16
|
const convOrName = this.conversation;
|
|
17
17
|
const conv = (typeof convOrName === 'string')
|
|
18
18
|
? this.config.mergeFields[convOrName] ?? convOrName
|
|
@@ -25,9 +25,6 @@ class ConvStep extends step_1.default {
|
|
|
25
25
|
return convOrName;
|
|
26
26
|
throw new Error(`invalid conversation ${JSON.stringify(conv)}`);
|
|
27
27
|
}
|
|
28
|
-
get globalThreadId() {
|
|
29
|
-
return `G:${this.conversationId}`;
|
|
30
|
-
}
|
|
31
28
|
/** id of the thread where conversation data is stored */
|
|
32
29
|
get dataThreadId() {
|
|
33
30
|
const dataThreadId = this.state.thread ?? this.data.conversationThread;
|
|
@@ -79,19 +76,21 @@ class ConvStep extends step_1.default {
|
|
|
79
76
|
if (this.useQueue && !await this.pushConvStep()) {
|
|
80
77
|
return await this.waitForConversation();
|
|
81
78
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
if (this.event.action == null && !this.event.processed) {
|
|
80
|
+
if (this.isGlobal)
|
|
81
|
+
return;
|
|
82
|
+
const hasGlobal = await this.sendEventToStep({ event: { ...this.event, action: 'global' }, toGlobal: true }); // redirect to global (1)
|
|
83
|
+
if (hasGlobal != null) {
|
|
84
|
+
this.log.debug('conv.sendEventToStep toGlobal', { hasGlobal });
|
|
85
|
+
this.state.prevSkipName = this.state.name;
|
|
86
|
+
this.state.name = 'onSkipEvent';
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (this.isGlobal && this.event.action === 'global') {
|
|
91
|
+
return; // it was redirected from (1)
|
|
92
|
+
}
|
|
93
|
+
await this.setLocalTriggers();
|
|
95
94
|
}
|
|
96
95
|
async runAfter() {
|
|
97
96
|
if (this.thread.ending)
|
|
@@ -113,11 +112,11 @@ class ConvStep extends step_1.default {
|
|
|
113
112
|
const globalLength = (await this.getConversation())?.glb?.length ?? 0;
|
|
114
113
|
return globalLength > 0;
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
async setLocalTriggers() {
|
|
116
|
+
if (!this.isGlobal && await this.hasActiveGlobal()) {
|
|
117
|
+
this.triggers.config({ target: 'session' });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
121
120
|
async waitForConversation() {
|
|
122
121
|
if (this.state.name !== 'waitForConversation') {
|
|
123
122
|
this.log.debug(this.state, 'conv.begin waitForConversation');
|
|
@@ -201,9 +200,9 @@ class ConvStep extends step_1.default {
|
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
async waitGlobEnd() {
|
|
204
|
-
const gcThreadId = this.
|
|
203
|
+
const gcThreadId = `G:${this.thread.id}`;
|
|
205
204
|
// wait for glob thread end (if exists)
|
|
206
|
-
this.triggers.
|
|
205
|
+
this.triggers.local(`thread/end/${gcThreadId}`, async () => await this.onConvEnd());
|
|
207
206
|
if (!this.process.getThread(gcThreadId))
|
|
208
207
|
await this.onConvEnd();
|
|
209
208
|
}
|
package/dst/voice.d.ts
CHANGED
|
@@ -28,20 +28,15 @@ export interface IVoiceCall {
|
|
|
28
28
|
export type EventType = 'hangup' | 'error' | 'cancel' | 'avm-detected' | 'recognition' | 'digit' | 'digits' | 'conference-start' | 'conference-end' | 'playback' | 'timeout' | 'record' | 'bridge' | 'bridge/ended' | 'is_flow_ready' | 'call';
|
|
29
29
|
export declare class VoiceStepError extends BasicError {
|
|
30
30
|
}
|
|
31
|
-
export type VoicerError = Error | string & {
|
|
32
|
-
message?: never;
|
|
33
|
-
name?: never;
|
|
34
|
-
};
|
|
35
31
|
export interface VoiceEvent {
|
|
36
32
|
type: EventType;
|
|
37
|
-
|
|
38
|
-
error?: VoicerError;
|
|
33
|
+
error?: Error;
|
|
39
34
|
}
|
|
40
35
|
export interface CallStartEvent extends VoiceEvent {
|
|
41
36
|
channel: IVoiceCall;
|
|
42
37
|
headers?: Record<string, string>;
|
|
43
38
|
}
|
|
44
|
-
export default class VoiceStep<TIn = unknown, TOut = unknown, TParams
|
|
39
|
+
export default class VoiceStep<TIn = unknown, TOut = unknown, TParams = VoiceEvent> extends ConvStep<IVoiceCall, TIn & {
|
|
45
40
|
handleCancel?: boolean;
|
|
46
41
|
}, TOut, TParams> {
|
|
47
42
|
runBefore(): Promise<void>;
|
|
@@ -55,7 +50,10 @@ export default class VoiceStep<TIn = unknown, TOut = unknown, TParams extends Vo
|
|
|
55
50
|
pauseRecording(call: IVoiceCall, command: any, sensitiveData?: SensitiveData): Promise<void>;
|
|
56
51
|
resumeRecording(call: IVoiceCall, sensitiveData?: SensitiveData): Promise<void>;
|
|
57
52
|
transcript(call: IVoiceCall, data?: Partial<IVoiceReporterTranscriptEventArgs>): Promise<string>;
|
|
58
|
-
throwError(error?:
|
|
53
|
+
throwError(error?: {
|
|
54
|
+
name: string;
|
|
55
|
+
message: string;
|
|
56
|
+
}): never;
|
|
59
57
|
handleHangup(call: IVoiceCall): Promise<void>;
|
|
60
58
|
buildSections({ sections, textType, ttsSettings, allowKeypadBargeIn }: TODO): TODO;
|
|
61
59
|
buildReprompts({ prompts, allowKeypadBargeIn }: TODO): TODO;
|
package/dst/voice.js
CHANGED
|
@@ -15,17 +15,8 @@ class VoiceStep extends step_1.default {
|
|
|
15
15
|
// static Error = VoiceStepError
|
|
16
16
|
async runBefore() {
|
|
17
17
|
await super.runBefore();
|
|
18
|
-
if (this.cache != null)
|
|
19
|
-
if (!this.isGlobal && this.event.params.global && this.event.action == null) {
|
|
20
|
-
const hasGlobal = await this.sendEventToStep({ event: { ...this.event, action: 'global' }, toGlobal: true }); // redirect to global (1)
|
|
21
|
-
if (hasGlobal != null) {
|
|
22
|
-
this.log.debug('conv.sendEventToStep toGlobal', { hasGlobal });
|
|
23
|
-
this.state.prevSkipName = this.state.name;
|
|
24
|
-
this.state.name = 'onSkipEvent';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
18
|
+
if (this.cache != null)
|
|
27
19
|
await this.handleHeartbeat(this.cache);
|
|
28
|
-
}
|
|
29
20
|
}
|
|
30
21
|
async sendCommands({ id, type, callback }, commands) {
|
|
31
22
|
if (lodash_1.default.isEmpty(commands))
|
|
@@ -155,7 +146,7 @@ class VoiceStep extends step_1.default {
|
|
|
155
146
|
return eventId;
|
|
156
147
|
}
|
|
157
148
|
throwError(error = new Error('unknown')) {
|
|
158
|
-
throw new VoiceStepError(error.message
|
|
149
|
+
throw new VoiceStepError(error.message, null, { name: error.name });
|
|
159
150
|
}
|
|
160
151
|
async handleHangup(call) {
|
|
161
152
|
if (call.ended)
|
|
@@ -174,7 +165,7 @@ class VoiceStep extends step_1.default {
|
|
|
174
165
|
url: section.audioUrl,
|
|
175
166
|
textType,
|
|
176
167
|
bargeInVoice: section.allowVoiceBargeIn,
|
|
177
|
-
bargeInKeypad: section.allowKeypadBargeIn
|
|
168
|
+
bargeInKeypad: section.allowKeypadBargeIn ?? allowKeypadBargeIn,
|
|
178
169
|
...ttsSettings
|
|
179
170
|
}));
|
|
180
171
|
}
|
|
@@ -185,7 +176,7 @@ class VoiceStep extends step_1.default {
|
|
|
185
176
|
repeatMsg: prompt.item.repeat,
|
|
186
177
|
fileName: prompt.item.audioUrl || '',
|
|
187
178
|
allowVoiceBargeIn: prompt.item.allowVoiceBargeIn,
|
|
188
|
-
allowKeypadBargeIn: prompt.item.allowKeypadBargeIn
|
|
179
|
+
allowKeypadBargeIn: prompt.item.allowKeypadBargeIn ?? allowKeypadBargeIn
|
|
189
180
|
}));
|
|
190
181
|
}
|
|
191
182
|
buildChoices({ choices }) {
|
|
@@ -233,8 +224,9 @@ class VoiceStep extends step_1.default {
|
|
|
233
224
|
}
|
|
234
225
|
if (!lodash_1.default.isEmpty(params.phrases)) {
|
|
235
226
|
const phrases = params.phrases;
|
|
227
|
+
const other = params.other ?? [];
|
|
236
228
|
data.value = phrases[0].text;
|
|
237
|
-
data.interpretation = phrases;
|
|
229
|
+
data.interpretation = [...phrases, ...other];
|
|
238
230
|
}
|
|
239
231
|
return data;
|
|
240
232
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onereach/step-voice",
|
|
3
|
-
"version": "5.0.4
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Roman Zolotarov",
|
|
@@ -19,22 +19,20 @@
|
|
|
19
19
|
"uuid": "^9.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@onereach/flow-sdk": "^3.1.
|
|
23
|
-
"@swc/cli": "^0.1.
|
|
24
|
-
"@swc/core": "^1.3.
|
|
25
|
-
"@swc/helpers": "^0.4.14",
|
|
22
|
+
"@onereach/flow-sdk": "^3.1.101",
|
|
23
|
+
"@swc/cli": "^0.1.60",
|
|
24
|
+
"@swc/core": "^1.3.32",
|
|
26
25
|
"@swc/jest": "^0.2.24",
|
|
27
26
|
"@types/jest": "^29.4.0",
|
|
28
27
|
"@types/lodash": "^4.14.191",
|
|
29
28
|
"@types/timestring": "^6.0.2",
|
|
30
|
-
"@types/uuid": "^9.0.
|
|
31
|
-
"aws-sdk": "^2.
|
|
29
|
+
"@types/uuid": "^9.0.0",
|
|
30
|
+
"aws-sdk": "^2.1306.0",
|
|
32
31
|
"babel-runtime": "^6.26.0",
|
|
33
32
|
"docdash": "^2.0.1",
|
|
34
33
|
"husky": "^8.0.3",
|
|
35
|
-
"jest": "^29.4.
|
|
34
|
+
"jest": "^29.4.1",
|
|
36
35
|
"pinst": "^3.0.0",
|
|
37
|
-
"source-map-support": "^0.5.21",
|
|
38
36
|
"ts-standard": "^12.0.2",
|
|
39
37
|
"typescript": "^4.9.5"
|
|
40
38
|
},
|