@onereach/step-voice 4.0.29 → 4.0.32
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 +0 -1
- package/dst/Cancel.js +25 -6
- package/dst/Choice.js +4 -4
- package/dst/Conference Dial.js +1 -1
- package/dst/Global Command.d.ts +1 -2
- package/dst/Global Command.js +13 -40
- package/dst/Hangup.d.ts +1 -0
- package/dst/Hangup.js +6 -3
- package/dst/Initiate Call.d.ts +0 -1
- package/dst/Initiate Call.js +5 -4
- package/dst/Join Conference.js +1 -1
- package/dst/Keypad Input.js +4 -4
- package/dst/Kick From Conference.js +1 -1
- package/dst/Say Message.js +5 -4
- package/dst/Transfer.js +1 -1
- package/dst/Voice Recording.js +1 -1
- package/dst/Wait For Call.d.ts +0 -1
- package/dst/Wait For Call.js +7 -7
- package/dst/step.d.ts +11 -6
- package/dst/step.js +105 -80
- package/dst/voice.d.ts +0 -2
- package/dst/voice.js +1 -4
- package/package.json +7 -7
package/dst/Cancel.d.ts
CHANGED
package/dst/Cancel.js
CHANGED
|
@@ -3,14 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
5
5
|
class VoiceCancel extends voice_1.default {
|
|
6
|
-
get useQueue() {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
6
|
async runStep() {
|
|
7
|
+
const conv = await this.getConversation();
|
|
8
|
+
if (conv.lcl.length <= 1) {
|
|
9
|
+
this.log.debug('nothing to cancel');
|
|
10
|
+
this.exitStep('next');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
10
13
|
const channel = await this.fetchData();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
this.triggers.once(`in/voice/${channel.id}/event`, async (event) => {
|
|
15
|
+
switch (event.params.type) {
|
|
16
|
+
case 'hangup':
|
|
17
|
+
await this.handleHangup(channel);
|
|
18
|
+
return await this.waitConvEnd();
|
|
19
|
+
case 'error':
|
|
20
|
+
return this.throwError(event.params.error);
|
|
21
|
+
case 'cancel': {
|
|
22
|
+
await this.popConvStep(); // pop current command (cancel)
|
|
23
|
+
await this.cancel(); // cancel previous command
|
|
24
|
+
return this.exitStep('next');
|
|
25
|
+
}
|
|
26
|
+
default:
|
|
27
|
+
return this.exitFlow();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
this.triggers.otherwise(async () => {
|
|
31
|
+
await this.sendCommands(channel, [{ name: 'cancel' }]);
|
|
32
|
+
});
|
|
14
33
|
}
|
|
15
34
|
}
|
|
16
35
|
exports.default = VoiceCancel;
|
package/dst/Choice.js
CHANGED
|
@@ -230,11 +230,11 @@ class Choice extends voice_1.default {
|
|
|
230
230
|
}
|
|
231
231
|
case 'hangup': {
|
|
232
232
|
await this.handleHangup(channel);
|
|
233
|
-
return this.
|
|
234
|
-
}
|
|
235
|
-
case 'cancel': {
|
|
236
|
-
return this.exitStep('cancel');
|
|
233
|
+
return await this.waitConvEnd();
|
|
237
234
|
}
|
|
235
|
+
// case 'cancel': {
|
|
236
|
+
// return this.data.handleCancel === true && this.exitStep('cancel')
|
|
237
|
+
// }
|
|
238
238
|
case 'error':
|
|
239
239
|
return this.throwError(event.params.error);
|
|
240
240
|
default:
|
package/dst/Conference Dial.js
CHANGED
|
@@ -11,7 +11,7 @@ class ConferenceDial extends voice_1.default {
|
|
|
11
11
|
switch (event.params.type) {
|
|
12
12
|
case 'hangup':
|
|
13
13
|
await this.handleHangup(channel);
|
|
14
|
-
return this.
|
|
14
|
+
return await this.waitConvEnd();
|
|
15
15
|
case 'conference-start':
|
|
16
16
|
if (this.data.stayInConference) {
|
|
17
17
|
return this.exitFlow();
|
package/dst/Global Command.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ITypedEvent } from '@onereach/flow-sdk/dst/types';
|
|
|
2
2
|
import VoiceStep, { IVoiceChannel, TODO, VoiceEvent } from './voice';
|
|
3
3
|
interface INPUT {
|
|
4
4
|
asr: TODO;
|
|
5
|
-
processHangUp: 'user' | 'bot' | 'both' | 'none';
|
|
5
|
+
processHangUp: 'user' | 'bot' | 'both' | 'none' | string;
|
|
6
6
|
recordAfterTransfer: boolean;
|
|
7
7
|
recordCall: boolean;
|
|
8
8
|
choices: TODO[];
|
|
@@ -27,7 +27,6 @@ interface EVENT extends VoiceEvent {
|
|
|
27
27
|
}
|
|
28
28
|
export default class GlobalCommand extends VoiceStep<Partial<INPUT>, OUTPUT, EVENT> {
|
|
29
29
|
get isGlobal(): boolean;
|
|
30
|
-
get autoCancel(): boolean | undefined;
|
|
31
30
|
runStep(): Promise<void>;
|
|
32
31
|
initThread(): Promise<void>;
|
|
33
32
|
globThread(): Promise<void>;
|
package/dst/Global Command.js
CHANGED
|
@@ -9,16 +9,10 @@ class GlobalCommand extends voice_1.default {
|
|
|
9
9
|
get isGlobal() {
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
|
-
get autoCancel() {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
12
|
async runStep() {
|
|
16
13
|
this._clearCache();
|
|
17
14
|
await this.process.runThread({
|
|
18
15
|
id: `G:${this.dataThreadId}`,
|
|
19
|
-
local: {
|
|
20
|
-
background: true
|
|
21
|
-
},
|
|
22
16
|
state: {
|
|
23
17
|
name: 'initThread',
|
|
24
18
|
step: this.step.id,
|
|
@@ -30,10 +24,6 @@ class GlobalCommand extends voice_1.default {
|
|
|
30
24
|
}
|
|
31
25
|
async initThread() {
|
|
32
26
|
const channel = await this.fetchData();
|
|
33
|
-
// if (recordCall || _.includes(['bot', 'both'], processHangUp)) {
|
|
34
|
-
// // prevent delete of session by "End" step
|
|
35
|
-
// this.session.set('keepAlive', true);
|
|
36
|
-
// }
|
|
37
27
|
const choices = this.buildChoices({ choices: this.data.choices });
|
|
38
28
|
const grammar = await this.buildGrammar(channel, choices);
|
|
39
29
|
// set grammar into voice conversation
|
|
@@ -65,30 +55,15 @@ class GlobalCommand extends voice_1.default {
|
|
|
65
55
|
}
|
|
66
56
|
async globThread() {
|
|
67
57
|
const channel = await this.fetchData();
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
if (channel.autoHangup) {
|
|
73
|
-
this.triggers.local('thread/end/main', async () => {
|
|
74
|
-
delete this.thread.waits['thread/end/main'];
|
|
75
|
-
const channel = await this.fetchData();
|
|
76
|
-
if (!channel.hangup) {
|
|
77
|
-
channel.autoHangup = false;
|
|
78
|
-
await this.updateData();
|
|
79
|
-
this.local.background = undefined;
|
|
80
|
-
await this.sendCommands(channel, [{ name: 'hangup' }]);
|
|
81
|
-
void this.process.main.enqueueAndRun({ name: 'ending' });
|
|
82
|
-
this.exitFlow();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
58
|
+
const findExit = (exitId) => {
|
|
59
|
+
return lodash_1.default.find(this.step.exits, (exit) => exitId === exit.stepId);
|
|
60
|
+
};
|
|
86
61
|
this.triggers.once(`in/voice/${channel.id}/event`, async (event) => {
|
|
87
62
|
event.processed = undefined;
|
|
88
63
|
switch (event.params.type) {
|
|
89
64
|
case 'hangup': {
|
|
90
65
|
await this.hangup(channel);
|
|
91
|
-
await this.
|
|
66
|
+
await this.notifyConvEnd();
|
|
92
67
|
return this.end();
|
|
93
68
|
}
|
|
94
69
|
case 'avm-detected':
|
|
@@ -98,7 +73,7 @@ class GlobalCommand extends voice_1.default {
|
|
|
98
73
|
case 'digits': {
|
|
99
74
|
const params = event.params;
|
|
100
75
|
const exitId = params.exitId ?? '';
|
|
101
|
-
if (
|
|
76
|
+
if (findExit(exitId)) {
|
|
102
77
|
await this.transcript(channel, {
|
|
103
78
|
previousTranscriptId: channel.lastTranscriptId,
|
|
104
79
|
keyPress: params.digit,
|
|
@@ -114,7 +89,7 @@ class GlobalCommand extends voice_1.default {
|
|
|
114
89
|
case 'recognition': {
|
|
115
90
|
const params = event.params;
|
|
116
91
|
const exitId = params.exitId ?? '';
|
|
117
|
-
if (
|
|
92
|
+
if (findExit(exitId)) {
|
|
118
93
|
const voiceProcessResult = lodash_1.default.chain(params.phrases)
|
|
119
94
|
.map((p) => p.lexical)
|
|
120
95
|
.join(' | ')
|
|
@@ -140,10 +115,6 @@ class GlobalCommand extends voice_1.default {
|
|
|
140
115
|
}
|
|
141
116
|
async hangup(channel) {
|
|
142
117
|
await this.handleHangup(channel);
|
|
143
|
-
// if (channel.recordCall || _.includes(['bot', 'both'], processHangUp)) {
|
|
144
|
-
// // turn off protection of session deletion by "End" step
|
|
145
|
-
// this.session.unset('keepAlive');
|
|
146
|
-
// }
|
|
147
118
|
const isHangedUpByBot = channel.sessionEndedBy === 'Bot';
|
|
148
119
|
const hangUpType = isHangedUpByBot ? 'bot hang up' : 'user hang up';
|
|
149
120
|
// process call recording in hangup event
|
|
@@ -163,7 +134,7 @@ class GlobalCommand extends voice_1.default {
|
|
|
163
134
|
return await this.exitThread(this.event, hangUpType, 'hang up');
|
|
164
135
|
case 'none':
|
|
165
136
|
default:
|
|
166
|
-
return this.
|
|
137
|
+
return this.end();
|
|
167
138
|
}
|
|
168
139
|
}
|
|
169
140
|
async exitThread(event, type, stepExit) {
|
|
@@ -195,16 +166,18 @@ class GlobalCommand extends voice_1.default {
|
|
|
195
166
|
// params: {}
|
|
196
167
|
// }])
|
|
197
168
|
// channel.global = null;
|
|
198
|
-
await this.updateData()
|
|
169
|
+
// await this.updateData()
|
|
170
|
+
const exitLabel = this.getExitStepLabel(stepExit) ?? stepExit;
|
|
199
171
|
await this.process.runThread({
|
|
200
|
-
id: `${
|
|
172
|
+
id: `${exitLabel}_${(0, nanoid_1.nanoid)(8)}`,
|
|
201
173
|
state: {
|
|
202
174
|
name: 'exitToThread',
|
|
175
|
+
direct: true,
|
|
203
176
|
result: {
|
|
204
177
|
conversation: this.conversation,
|
|
205
178
|
conversationThreadId: this.dataThreadId
|
|
206
179
|
},
|
|
207
|
-
exitStep:
|
|
180
|
+
exitStep: stepExit,
|
|
208
181
|
step: this.currentStepId
|
|
209
182
|
}
|
|
210
183
|
});
|
|
@@ -213,7 +186,7 @@ class GlobalCommand extends voice_1.default {
|
|
|
213
186
|
// this.gotoState(this.state, { name: 'exiting' })
|
|
214
187
|
}
|
|
215
188
|
exitToThread() {
|
|
216
|
-
this.thread.
|
|
189
|
+
this.thread.exitStep(this.state.exitStep, this.state.result);
|
|
217
190
|
}
|
|
218
191
|
async buildGrammar(channel, choices) {
|
|
219
192
|
const { asr } = this.data;
|
package/dst/Hangup.d.ts
CHANGED
package/dst/Hangup.js
CHANGED
|
@@ -12,9 +12,9 @@ class Hangup extends voice_1.default {
|
|
|
12
12
|
return this.exitStep('next');
|
|
13
13
|
case 'error':
|
|
14
14
|
return this.throwError(event.params.error);
|
|
15
|
-
case 'cancel': {
|
|
16
|
-
|
|
17
|
-
}
|
|
15
|
+
// case 'cancel': {
|
|
16
|
+
// return this.data.handleCancel === true && this.exitStep('cancel')
|
|
17
|
+
// }
|
|
18
18
|
default:
|
|
19
19
|
return this.exitFlow();
|
|
20
20
|
}
|
|
@@ -32,5 +32,8 @@ class Hangup extends voice_1.default {
|
|
|
32
32
|
return this.exitFlow();
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
async onConvEnd() {
|
|
36
|
+
this.exitStep('next');
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
exports.default = Hangup;
|
package/dst/Initiate Call.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ interface INPUT {
|
|
|
20
20
|
}
|
|
21
21
|
export default class InitiateCall extends VoiceStep<INPUT, TODO, CallStartEvent> {
|
|
22
22
|
get conversation(): string | import("@onereach/flow-sdk/dst/types").IMergeField;
|
|
23
|
-
get autoCancel(): undefined;
|
|
24
23
|
runStep(): Promise<void>;
|
|
25
24
|
waitForCall(): Promise<void>;
|
|
26
25
|
}
|
package/dst/Initiate Call.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable
|
|
2
|
+
/* eslint-disable
|
|
3
|
+
@typescript-eslint/strict-boolean-expressions,
|
|
4
|
+
@typescript-eslint/explicit-function-return-type,
|
|
5
|
+
@typescript-eslint/no-misused-promises
|
|
6
|
+
*/
|
|
3
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
8
|
const tslib_1 = require("tslib");
|
|
5
9
|
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
@@ -13,9 +17,6 @@ class InitiateCall extends voice_1.default {
|
|
|
13
17
|
throw new Error('missing conversation');
|
|
14
18
|
return this.step.dataOut;
|
|
15
19
|
}
|
|
16
|
-
get autoCancel() {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
20
|
async runStep() {
|
|
20
21
|
const { channelId = uuid.v4() } = this.data;
|
|
21
22
|
if (!this.session.key) {
|
package/dst/Join Conference.js
CHANGED
|
@@ -11,7 +11,7 @@ class JoinConference extends voice_1.default {
|
|
|
11
11
|
switch (event.params.type) {
|
|
12
12
|
case 'hangup':
|
|
13
13
|
await this.handleHangup(channel);
|
|
14
|
-
return this.
|
|
14
|
+
return await this.waitConvEnd();
|
|
15
15
|
case 'conference-start':
|
|
16
16
|
await this.transcript(channel, {
|
|
17
17
|
conferenceId: conferenceName,
|
package/dst/Keypad Input.js
CHANGED
|
@@ -152,11 +152,11 @@ class KeypadInput extends voice_1.default {
|
|
|
152
152
|
}
|
|
153
153
|
case 'hangup': {
|
|
154
154
|
await this.handleHangup(channel);
|
|
155
|
-
return this.
|
|
156
|
-
}
|
|
157
|
-
case 'cancel': {
|
|
158
|
-
return this.exitStep('cancel');
|
|
155
|
+
return await this.waitConvEnd();
|
|
159
156
|
}
|
|
157
|
+
// case 'cancel': {
|
|
158
|
+
// return this.data.handleCancel === true && this.exitStep('cancel')
|
|
159
|
+
// }
|
|
160
160
|
case 'error':
|
|
161
161
|
return this.throwError(event.params.error);
|
|
162
162
|
default:
|
|
@@ -11,7 +11,7 @@ class KickFromConference extends voice_1.default {
|
|
|
11
11
|
switch (event.params.type) {
|
|
12
12
|
case 'hangup':
|
|
13
13
|
await this.handleHangup(channel);
|
|
14
|
-
return this.
|
|
14
|
+
return await this.waitConvEnd();
|
|
15
15
|
case 'conference-end':
|
|
16
16
|
await this.transcript(channel, {
|
|
17
17
|
conferenceId: room,
|
package/dst/Say Message.js
CHANGED
|
@@ -21,14 +21,15 @@ class SayMessage extends voice_1.default {
|
|
|
21
21
|
switch (event.params.type) {
|
|
22
22
|
case 'hangup':
|
|
23
23
|
await this.handleHangup(channel);
|
|
24
|
-
return this.
|
|
24
|
+
return await this.waitConvEnd();
|
|
25
25
|
case 'playback':
|
|
26
26
|
return this.exitStep('next');
|
|
27
27
|
case 'error':
|
|
28
28
|
return this.throwError(event.params.error);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
//
|
|
30
|
+
// case 'cancel': {
|
|
31
|
+
// return this.data.handleCancel === true && this.exitStep('cancel')
|
|
32
|
+
// }
|
|
32
33
|
default:
|
|
33
34
|
return this.exitFlow();
|
|
34
35
|
}
|
package/dst/Transfer.js
CHANGED
package/dst/Voice Recording.js
CHANGED
|
@@ -39,7 +39,7 @@ class Recording extends voice_1.default {
|
|
|
39
39
|
// TODO do we need zombie?
|
|
40
40
|
this.state.zombie = true;
|
|
41
41
|
await this.handleHangup(channel);
|
|
42
|
-
return this.
|
|
42
|
+
return await this.waitConvEnd();
|
|
43
43
|
case 'record':
|
|
44
44
|
if (!lodash_1.default.isEmpty(url)) {
|
|
45
45
|
await this.transcript(channel, {
|
package/dst/Wait For Call.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import VoiceStep, { CallStartEvent, TODO } from './voice';
|
|
|
2
2
|
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
|
-
get autoCancel(): boolean;
|
|
6
5
|
runStep(): Promise<void>;
|
|
7
6
|
onCall(event: ITypedEvent<CallStartEvent>): Promise<unknown>;
|
|
8
7
|
}
|
package/dst/Wait For Call.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable
|
|
2
|
+
/* eslint-disable
|
|
3
|
+
@typescript-eslint/strict-boolean-expressions,
|
|
4
|
+
@typescript-eslint/explicit-function-return-type,
|
|
5
|
+
@typescript-eslint/no-misused-promises
|
|
6
|
+
*/
|
|
3
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
8
|
const tslib_1 = require("tslib");
|
|
5
9
|
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
@@ -11,21 +15,17 @@ class WaitForCall extends voice_1.default {
|
|
|
11
15
|
throw new Error('missing conversation');
|
|
12
16
|
return this.step.dataOut;
|
|
13
17
|
}
|
|
14
|
-
get autoCancel() {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
18
|
async runStep() {
|
|
18
19
|
const selectedNumbers = this.data.selectedNumbers;
|
|
19
20
|
lodash_1.default.forEach(selectedNumbers, number => {
|
|
20
|
-
this.triggers.on(`in/voice/${number.value}/call`,
|
|
21
|
+
this.triggers.on(`in/voice/${number.value}/call`, this.onCall);
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
async onCall(event) {
|
|
24
|
-
const {
|
|
25
|
+
const { asr, tts, endOfInputTimeout } = this.data;
|
|
25
26
|
const channel = {
|
|
26
27
|
headers: event.params.headers,
|
|
27
28
|
...event.params.channel,
|
|
28
|
-
autoHangup,
|
|
29
29
|
asr: asr.getSettings(),
|
|
30
30
|
tts: tts.getVoice(),
|
|
31
31
|
botNumber: event.params.channel.to ?? 'unknown',
|
package/dst/step.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export default class ConvStep<TData = unknown, TIn = unknown, TOut = unknown, TP
|
|
|
10
10
|
get conversation(): IMergeFieldKey | IMergeField;
|
|
11
11
|
/** id of the thread where conversation data is stored */
|
|
12
12
|
get dataThreadId(): IThreadId;
|
|
13
|
-
get autoCancel(): boolean | undefined;
|
|
14
13
|
get isGlobal(): boolean;
|
|
15
14
|
get useQueue(): boolean;
|
|
16
15
|
fetchData(): Promise<TData & IConversationData>;
|
|
16
|
+
getConversation(): Promise<IConversation>;
|
|
17
17
|
updateData(): Promise<void>;
|
|
18
18
|
hasConversation(): Promise<boolean>;
|
|
19
19
|
runBefore(): Promise<void>;
|
|
@@ -24,7 +24,14 @@ export default class ConvStep<TData = unknown, TIn = unknown, TOut = unknown, TP
|
|
|
24
24
|
onSkipEvent(): Promise<void>;
|
|
25
25
|
cancel(): Promise<void>;
|
|
26
26
|
onCancel(): Promise<void>;
|
|
27
|
-
|
|
27
|
+
onSleep(): Promise<void>;
|
|
28
|
+
onAwake(): Promise<void>;
|
|
29
|
+
onPause(): Promise<void>;
|
|
30
|
+
onResume(): Promise<void>;
|
|
31
|
+
notifyConvEnd(): Promise<void>;
|
|
32
|
+
waitConvEnd(): Promise<void>;
|
|
33
|
+
waitGlobEnd(): Promise<void>;
|
|
34
|
+
onConvEnd(): Promise<void>;
|
|
28
35
|
pause(): Promise<void>;
|
|
29
36
|
resume(): Promise<void>;
|
|
30
37
|
sendEventToStep({ toGlobal, toStep, action, event }: {
|
|
@@ -37,13 +44,11 @@ export default class ConvStep<TData = unknown, TIn = unknown, TOut = unknown, TP
|
|
|
37
44
|
/** @returns true if current conv is active */
|
|
38
45
|
pushConvStep(): Promise<boolean>;
|
|
39
46
|
/** @returns true if current conv was active */
|
|
40
|
-
popConvStep(): Promise<boolean>;
|
|
41
|
-
startConversation(data: TData, {
|
|
42
|
-
autoCancel?: boolean;
|
|
47
|
+
popConvStep(popStep?: IConversationStep): Promise<boolean>;
|
|
48
|
+
startConversation(data: TData, { events }: {
|
|
43
49
|
events: Record<string, {}>;
|
|
44
50
|
thread?: IThreadId;
|
|
45
51
|
}): Promise<void>;
|
|
46
52
|
_fetchData(): Promise<(TData & IConversationData) | undefined>;
|
|
47
|
-
_getConversation(): Promise<IConversation>;
|
|
48
53
|
_clearCache(): void;
|
|
49
54
|
}
|
package/dst/step.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const step_1 = tslib_1.__importDefault(require("@onereach/flow-sdk/dst/step"));
|
|
6
|
-
const event_1 = tslib_1.__importDefault(require("@onereach/flow-sdk/dst/event"));
|
|
7
6
|
class ConvStep extends step_1.default {
|
|
8
7
|
get conversation() {
|
|
9
8
|
if (this.data.conversation == null)
|
|
@@ -15,9 +14,6 @@ class ConvStep extends step_1.default {
|
|
|
15
14
|
const dataThreadId = this.state.thread ?? this.data.conversationThread;
|
|
16
15
|
return dataThreadId || this.thread.id;
|
|
17
16
|
}
|
|
18
|
-
get autoCancel() {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
17
|
get isGlobal() {
|
|
22
18
|
return false;
|
|
23
19
|
}
|
|
@@ -30,6 +26,9 @@ class ConvStep extends step_1.default {
|
|
|
30
26
|
throw new Error(`missing conversation data in state ${this.state.name}`);
|
|
31
27
|
return data;
|
|
32
28
|
}
|
|
29
|
+
async getConversation() {
|
|
30
|
+
return (await this.fetchData())._conv;
|
|
31
|
+
}
|
|
33
32
|
async updateData() {
|
|
34
33
|
if (this.convDataCache == null)
|
|
35
34
|
throw new Error(`missing conversation cache in state ${this.state.name}`);
|
|
@@ -42,6 +41,8 @@ class ConvStep extends step_1.default {
|
|
|
42
41
|
}
|
|
43
42
|
async runBefore() {
|
|
44
43
|
await super.runBefore();
|
|
44
|
+
if (this.state.ending)
|
|
45
|
+
return;
|
|
45
46
|
// ensure cache is reset between step runs, just in case
|
|
46
47
|
this._clearCache();
|
|
47
48
|
this.triggers.local('_conv');
|
|
@@ -50,14 +51,15 @@ class ConvStep extends step_1.default {
|
|
|
50
51
|
this.log.debug('conv.runBefore', { state: this.state, conv: this.convDataCache?._conv });
|
|
51
52
|
if (this.state.direct)
|
|
52
53
|
return;
|
|
53
|
-
if (this.event.action === '
|
|
54
|
-
this.
|
|
54
|
+
if (!this.event.processed && this.event.action && typeof this[this.event.action] === 'function') {
|
|
55
|
+
this.event.processed = true;
|
|
56
|
+
this.state.name = this.event.action;
|
|
55
57
|
return;
|
|
56
58
|
}
|
|
57
59
|
if (this.useQueue && !await this.pushConvStep()) {
|
|
58
60
|
return await this.waitForConversation();
|
|
59
61
|
}
|
|
60
|
-
if (this.event.action == null && this.event.processed
|
|
62
|
+
if (this.event.action == null && !this.event.processed && this.convDataCache?._conv?.trg?.[this.event.name] != null) {
|
|
61
63
|
if (this.isGlobal)
|
|
62
64
|
return;
|
|
63
65
|
const hasGlobal = await this.sendEventToStep({ event: { ...this.event, action: 'global' }, toGlobal: true }); // redirect to global (1)
|
|
@@ -77,17 +79,18 @@ class ConvStep extends step_1.default {
|
|
|
77
79
|
if (!await this.hasConversation())
|
|
78
80
|
return await super.runAfter();
|
|
79
81
|
if (this.thread.hasControlAction()) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
82
|
+
await this.popConvStep();
|
|
83
|
+
// if (await this.popConvStep()) {
|
|
84
|
+
// await this.sendEventToStep({ toGlobal: this.isGlobal, action: 'onAwake' })
|
|
85
|
+
// }
|
|
83
86
|
}
|
|
84
|
-
if (this.isGlobal && !
|
|
87
|
+
if (this.isGlobal && !this.event.processed) {
|
|
85
88
|
await this.sendEventToStep({ toGlobal: false, event: { ...this.event, processed: undefined, action: 'local' } });
|
|
86
89
|
}
|
|
87
90
|
await super.runAfter();
|
|
88
91
|
}
|
|
89
92
|
async hasActiveGlobal() {
|
|
90
|
-
const globalLength = (await this.
|
|
93
|
+
const globalLength = (await this.getConversation())?.glb?.length ?? 0;
|
|
91
94
|
return globalLength > 0;
|
|
92
95
|
}
|
|
93
96
|
async setLocalTriggers() {
|
|
@@ -119,59 +122,88 @@ class ConvStep extends step_1.default {
|
|
|
119
122
|
this.log.debug('conv.cannot cancel global');
|
|
120
123
|
return;
|
|
121
124
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
if (activeStep != null) {
|
|
125
|
-
this.log.debug('conv.cancel', activeStep);
|
|
126
|
-
conv.lcl.splice(0);
|
|
127
|
-
await this.updateData();
|
|
128
|
-
await this.sendEventToStep({ toGlobal: false, action: 'cancel', toStep: activeStep });
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
this.log.debug('conv.nothing to cancel');
|
|
132
|
-
}
|
|
125
|
+
const activeStep = await this.activeStep();
|
|
126
|
+
await this.sendEventToStep({ event: { name: '_conv', action: 'onCancel', params: { byStep: this.step.label } }, toStep: activeStep });
|
|
133
127
|
}
|
|
134
128
|
async onCancel() {
|
|
129
|
+
await this.popConvStep();
|
|
135
130
|
if (this.getExitStepId('cancel')) {
|
|
136
131
|
this.log.debug('conv.cancel exit');
|
|
137
132
|
this.exitStep('cancel');
|
|
138
133
|
}
|
|
139
134
|
else {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
return await this.waitConvEnd();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async onSleep() {
|
|
139
|
+
// sleep
|
|
140
|
+
}
|
|
141
|
+
async onAwake() {
|
|
142
|
+
// wakeup
|
|
143
|
+
}
|
|
144
|
+
async onPause() {
|
|
145
|
+
// return await this.waitConvEnd()
|
|
146
|
+
}
|
|
147
|
+
async onResume() {
|
|
148
|
+
// resume
|
|
149
|
+
}
|
|
150
|
+
async notifyConvEnd() {
|
|
151
|
+
await this.popConvStep();
|
|
152
|
+
const conv = await this.getConversation();
|
|
153
|
+
const lcl = conv.lcl.splice(0);
|
|
154
|
+
const glb = conv.glb.splice(0);
|
|
155
|
+
if (lcl.length > 0 || glb.length > 0) {
|
|
156
|
+
await this.updateData();
|
|
157
|
+
for (const step of lcl) {
|
|
158
|
+
await this.sendEventToStep({ toStep: step, action: 'onConvEnd' });
|
|
144
159
|
}
|
|
145
|
-
|
|
146
|
-
this.
|
|
147
|
-
this.end();
|
|
160
|
+
for (const step of glb) {
|
|
161
|
+
await this.sendEventToStep({ toStep: step, action: 'onConvEnd' });
|
|
148
162
|
}
|
|
149
163
|
}
|
|
150
164
|
}
|
|
151
|
-
async
|
|
152
|
-
this.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const activeStep = await this.activeStep(false);
|
|
157
|
-
if (activeStep != null) {
|
|
158
|
-
this.log.debug('conv.pause', activeStep);
|
|
159
|
-
conv.stk.push(conv.lcl.splice(0)); // save que to stk
|
|
160
|
-
await this.sendEventToStep({ toGlobal: false, action: 'pause', toStep: activeStep });
|
|
165
|
+
async waitConvEnd() {
|
|
166
|
+
const conversationThread = this.state.thread ?? this.thread.id;
|
|
167
|
+
if (!this.isGlobal && conversationThread === this.thread.id && this.thread.id !== 'main') {
|
|
168
|
+
this.log.debug('conv.wait for end', this.conversation);
|
|
169
|
+
this.gotoState({ ...this.state, name: 'waitGlobEnd', direct: true });
|
|
161
170
|
}
|
|
162
171
|
else {
|
|
163
|
-
this.log.debug('conv.
|
|
172
|
+
this.log.debug('conv.end', this.conversation);
|
|
173
|
+
await this.onConvEnd();
|
|
164
174
|
}
|
|
165
175
|
}
|
|
176
|
+
async waitGlobEnd() {
|
|
177
|
+
const gcThreadId = `G:${this.thread.id}`;
|
|
178
|
+
// wait for glob thread end (if exists)
|
|
179
|
+
this.triggers.local(`thread/end/${gcThreadId}`, async () => await this.onConvEnd());
|
|
180
|
+
if (!this.process.getThread(gcThreadId))
|
|
181
|
+
await this.onConvEnd();
|
|
182
|
+
}
|
|
183
|
+
async onConvEnd() {
|
|
184
|
+
this.end();
|
|
185
|
+
}
|
|
186
|
+
async pause() {
|
|
187
|
+
// const conv = await this._getConversation()
|
|
188
|
+
// const activeStep = await this.activeStep(false)
|
|
189
|
+
// if (activeStep != null) {
|
|
190
|
+
// this.log.debug('conv.pause', activeStep)
|
|
191
|
+
// conv.stk.push(conv.lcl.splice(0)) // save que to stk
|
|
192
|
+
// await this.updateData()
|
|
193
|
+
// await this.sendEventToStep({ action: 'onPause', toStep: activeStep })
|
|
194
|
+
// } else {
|
|
195
|
+
// this.log.debug('conv.nothing to pause')
|
|
196
|
+
// }
|
|
197
|
+
}
|
|
166
198
|
async resume() {
|
|
167
|
-
const conv = await this._getConversation()
|
|
168
|
-
if (conv.stk.length > 0) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
|
|
174
|
-
}
|
|
199
|
+
// const conv = await this._getConversation()
|
|
200
|
+
// if (conv.stk.length > 0) {
|
|
201
|
+
// conv.lcl.unshift(...(conv.stk.pop() ?? [])) // restore que from stk
|
|
202
|
+
// await this.updateData()
|
|
203
|
+
// await this.sendEventToStep({ toGlobal: false, action: 'onResume' })
|
|
204
|
+
// } else {
|
|
205
|
+
// this.log.debug('conv.nothing to resume')
|
|
206
|
+
// }
|
|
175
207
|
}
|
|
176
208
|
async sendEventToStep({ toGlobal, toStep, action, event = { name: '_conv', action } }) {
|
|
177
209
|
toStep || (toStep = await this.activeStep(toGlobal));
|
|
@@ -182,63 +214,59 @@ class ConvStep extends step_1.default {
|
|
|
182
214
|
return undefined;
|
|
183
215
|
}
|
|
184
216
|
async activeStep(isGlobal = this.isGlobal) {
|
|
185
|
-
const conv = await this.
|
|
186
|
-
return isGlobal ? conv.glb[conv.glb.length - 1] : conv.lcl[
|
|
217
|
+
const conv = await this.getConversation();
|
|
218
|
+
return isGlobal ? conv.glb[conv.glb.length - 1] : conv.lcl[conv.lcl.length - 1];
|
|
187
219
|
}
|
|
188
220
|
/** @returns true if current conv is active */
|
|
189
221
|
async pushConvStep() {
|
|
190
|
-
const conv = await this.
|
|
222
|
+
const conv = await this.getConversation();
|
|
191
223
|
const sessionKey = this.session.key;
|
|
192
224
|
if (sessionKey == null)
|
|
193
225
|
throw new Error('session is required');
|
|
194
226
|
const que = this.isGlobal ? conv.glb : conv.lcl;
|
|
195
227
|
const queIndex = que.findIndex(stp => stp.key === sessionKey && this.thread.id === stp.thread);
|
|
196
228
|
if (queIndex < 0) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
que.push({ key: sessionKey, thread: this.thread.id });
|
|
229
|
+
await this.sendEventToStep({ toGlobal: false, event: { name: '_conv', action: 'onPause', params: { byStep: this.step.label } } });
|
|
230
|
+
que.push({ key: sessionKey, thread: this.thread.id, name: this.constructor.name, label: this.label, step: this.id });
|
|
200
231
|
await this.updateData();
|
|
201
|
-
return
|
|
232
|
+
return true;
|
|
202
233
|
}
|
|
203
|
-
return queIndex ===
|
|
234
|
+
return queIndex === que.length - 1;
|
|
204
235
|
}
|
|
205
236
|
/** @returns true if current conv was active */
|
|
206
|
-
async popConvStep() {
|
|
207
|
-
const conv = await this.
|
|
237
|
+
async popConvStep(popStep) {
|
|
238
|
+
const conv = await this.getConversation();
|
|
208
239
|
const sessionKey = this.session.key;
|
|
209
240
|
if (sessionKey == null)
|
|
210
241
|
throw new Error('session is required');
|
|
242
|
+
popStep || (popStep = { key: sessionKey, thread: this.thread.id });
|
|
211
243
|
const que = this.isGlobal ? conv.glb : conv.lcl;
|
|
212
|
-
const queIndex = que.findIndex(stp => stp.key ===
|
|
244
|
+
const queIndex = que.findIndex(stp => stp.key === popStep?.key && stp.thread === popStep.thread);
|
|
213
245
|
if (queIndex >= 0) {
|
|
214
246
|
// console.log('SPLICE1', this.thread.id, this.step.label, que)
|
|
215
247
|
que.splice(queIndex, 1);
|
|
216
248
|
await this.updateData();
|
|
217
|
-
return
|
|
249
|
+
return queIndex === que.length;
|
|
218
250
|
}
|
|
219
|
-
let updated = false
|
|
220
|
-
conv.stk.forEach((steps, stepsIdx) => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
if (updated)
|
|
231
|
-
await this.updateData();
|
|
251
|
+
// let updated = false
|
|
252
|
+
// conv.stk.forEach((steps, stepsIdx) => {
|
|
253
|
+
// const stpIdx = steps.findIndex(stp => stp.key === sessionKey && this.thread.id === stp.thread)
|
|
254
|
+
// if (stpIdx >= 0) {
|
|
255
|
+
// if (steps.length > 1) steps.splice(stpIdx, 1)
|
|
256
|
+
// else conv.stk.splice(stepsIdx, 1)
|
|
257
|
+
// updated = true
|
|
258
|
+
// }
|
|
259
|
+
// })
|
|
260
|
+
// if (updated) await this.updateData()
|
|
232
261
|
return false;
|
|
233
262
|
}
|
|
234
|
-
async startConversation(data, {
|
|
263
|
+
async startConversation(data, { events }) {
|
|
235
264
|
this.convDataCache = {
|
|
236
265
|
...data,
|
|
237
266
|
_conv: {
|
|
238
|
-
acl: (autoCancel ? 1 : undefined),
|
|
239
267
|
trg: events,
|
|
240
268
|
glb: [],
|
|
241
|
-
stk: [],
|
|
269
|
+
// stk: [],
|
|
242
270
|
lcl: []
|
|
243
271
|
}
|
|
244
272
|
};
|
|
@@ -253,9 +281,6 @@ class ConvStep extends step_1.default {
|
|
|
253
281
|
// console.log('FETCH', this.conversation, this.thread.id, this.step.label, this.convDataCache?._conv.que)
|
|
254
282
|
return this.convDataCache;
|
|
255
283
|
}
|
|
256
|
-
async _getConversation() {
|
|
257
|
-
return (await this.fetchData())._conv;
|
|
258
|
-
}
|
|
259
284
|
_clearCache() {
|
|
260
285
|
this.convDataCache = undefined;
|
|
261
286
|
}
|
package/dst/voice.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import BasicError from '@onereach/flow-sdk/dst/errors/base';
|
|
|
4
4
|
export declare type TODO = any;
|
|
5
5
|
export interface IVoiceChannel {
|
|
6
6
|
id: string;
|
|
7
|
-
autoHangup: boolean;
|
|
8
7
|
hangup: boolean;
|
|
9
8
|
endUserNumber: string;
|
|
10
9
|
botNumber: string;
|
|
@@ -34,7 +33,6 @@ export interface CallStartEvent extends VoiceEvent {
|
|
|
34
33
|
export default class VoiceStep<TIn = unknown, TOut = unknown, TParams = VoiceEvent> extends ConvStep<IVoiceChannel, TIn & {
|
|
35
34
|
handleCancel?: boolean;
|
|
36
35
|
}, TOut, TParams> {
|
|
37
|
-
get autoCancel(): boolean | undefined;
|
|
38
36
|
sendCommands({ id, type, callback }: IVoiceChannel, commands: TODO[]): Promise<unknown>;
|
|
39
37
|
extractSectionMessages(sections: IPromtpSection[]): string;
|
|
40
38
|
extractSectionFiles(sections: IPromtpSection[]): Array<{
|
package/dst/voice.js
CHANGED
|
@@ -13,9 +13,6 @@ class VoiceStepError extends base_1.default {
|
|
|
13
13
|
exports.VoiceStepError = VoiceStepError;
|
|
14
14
|
class VoiceStep extends step_1.default {
|
|
15
15
|
// static Error = VoiceStepError
|
|
16
|
-
get autoCancel() {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
16
|
async sendCommands({ id, type, callback }, commands) {
|
|
20
17
|
if (lodash_1.default.isEmpty(commands))
|
|
21
18
|
return;
|
|
@@ -24,7 +21,7 @@ class VoiceStep extends step_1.default {
|
|
|
24
21
|
name: `out/voice/${type}`,
|
|
25
22
|
params: {
|
|
26
23
|
id,
|
|
27
|
-
cancel: this.
|
|
24
|
+
cancel: this.isGlobal ? undefined : true,
|
|
28
25
|
commands
|
|
29
26
|
},
|
|
30
27
|
reporting: this.session.getSessionRef()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onereach/step-voice",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.32",
|
|
4
4
|
"author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Roman Zolotarov",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
"uuid": "^8.3.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@onereach/flow-sdk": "^3.1.
|
|
21
|
+
"@onereach/flow-sdk": "^3.1.54",
|
|
22
22
|
"@swc/cli": "^0.1.57",
|
|
23
|
-
"@swc/core": "^1.2.
|
|
23
|
+
"@swc/core": "^1.2.210",
|
|
24
24
|
"@swc/jest": "^0.2.21",
|
|
25
|
-
"@types/jest": "^28.1.
|
|
25
|
+
"@types/jest": "^28.1.4",
|
|
26
26
|
"@types/lodash": "^4.14.182",
|
|
27
27
|
"@types/timestring": "^6.0.2",
|
|
28
28
|
"@types/uuid": "^8.3.4",
|
|
29
|
-
"aws-sdk": "^2.
|
|
29
|
+
"aws-sdk": "^2.1168.0",
|
|
30
30
|
"babel-runtime": "^6.26.0",
|
|
31
31
|
"docdash": "^1.2.0",
|
|
32
32
|
"husky": "^8.0.1",
|
|
33
|
-
"jest": "^28.1.
|
|
33
|
+
"jest": "^28.1.2",
|
|
34
34
|
"pinst": "^3.0.0",
|
|
35
35
|
"ts-standard": "^11.0.0",
|
|
36
36
|
"typescript": "^4.7.4"
|
|
@@ -75,4 +75,4 @@
|
|
|
75
75
|
"node_modules"
|
|
76
76
|
]
|
|
77
77
|
}
|
|
78
|
-
}
|
|
78
|
+
}
|