@onereach/step-voice 7.0.50 → 7.0.51
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/Voice Live Translation.d.ts +64 -0
- package/dst/Voice Live Translation.js +149 -0
- package/dst/voice.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import VoiceStep, { VoiceEvent } from './voice';
|
|
2
|
+
declare const enum GATEWAY_SETTINGS_MODE {
|
|
3
|
+
DEFAULT = "default",
|
|
4
|
+
CUSTOM = "custom",
|
|
5
|
+
INHERIT = "inherit",
|
|
6
|
+
PROFILE = "profile"
|
|
7
|
+
}
|
|
8
|
+
declare const enum SIP_PROFILE {
|
|
9
|
+
DEFAULT = "default",
|
|
10
|
+
INTERNAL = "internal",
|
|
11
|
+
EXTERNAL = "external"
|
|
12
|
+
}
|
|
13
|
+
interface INPUT {
|
|
14
|
+
destination: string;
|
|
15
|
+
phoneNumber: string;
|
|
16
|
+
sessionTimeout: number;
|
|
17
|
+
sipHeaders: Array<{
|
|
18
|
+
name: string;
|
|
19
|
+
value: string;
|
|
20
|
+
}>;
|
|
21
|
+
from?: string;
|
|
22
|
+
gatewaySettingsMode?: GATEWAY_SETTINGS_MODE;
|
|
23
|
+
sipHost?: string;
|
|
24
|
+
sipUser?: string;
|
|
25
|
+
sipPassword?: string;
|
|
26
|
+
sipProfile?: SIP_PROFILE;
|
|
27
|
+
muteRecording?: boolean;
|
|
28
|
+
disableRingback?: boolean;
|
|
29
|
+
caller_language: string;
|
|
30
|
+
destination_language: string;
|
|
31
|
+
translator?: Partial<TranslatorConfig>;
|
|
32
|
+
echo_protection?: boolean;
|
|
33
|
+
dub?: Partial<DubConfig>;
|
|
34
|
+
agent_url_overwritten?: boolean;
|
|
35
|
+
agent_url?: string;
|
|
36
|
+
}
|
|
37
|
+
interface TranslatorConfig {
|
|
38
|
+
provider: 'pinch' | 'passthrough';
|
|
39
|
+
model: string;
|
|
40
|
+
api_key?: string;
|
|
41
|
+
options?: {
|
|
42
|
+
voice_type?: '' | 'male' | 'female';
|
|
43
|
+
voice_id?: string;
|
|
44
|
+
context?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
interface DubConfig {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
original_level: number | string;
|
|
50
|
+
original_level_while_translating: number | string;
|
|
51
|
+
volume_change_ms: number | string;
|
|
52
|
+
restore_delay_ms: number | string;
|
|
53
|
+
}
|
|
54
|
+
interface EVENT extends VoiceEvent {
|
|
55
|
+
originateDisposition?: string;
|
|
56
|
+
reason?: string;
|
|
57
|
+
}
|
|
58
|
+
export default class VoiceLiveTranslation extends VoiceStep<INPUT, {}, EVENT> {
|
|
59
|
+
runStep(): Promise<void>;
|
|
60
|
+
translationParams(): Record<string, unknown>;
|
|
61
|
+
private isStepFlagEnabled;
|
|
62
|
+
private isValidAgentUrl;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
5
|
+
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
6
|
+
class VoiceLiveTranslation extends voice_1.default {
|
|
7
|
+
async runStep() {
|
|
8
|
+
const call = await this.fetchData();
|
|
9
|
+
this.triggers.local(`in/voice/${call.id}`, async (event) => {
|
|
10
|
+
switch (event.params.type) {
|
|
11
|
+
case 'bridge': {
|
|
12
|
+
await this.transcript(call, {
|
|
13
|
+
action: 'Live Translation Answered',
|
|
14
|
+
actionFromBot: true,
|
|
15
|
+
reportingSettingsKey: 'transcriptAnswered'
|
|
16
|
+
});
|
|
17
|
+
// Maximum call duration
|
|
18
|
+
this.triggers.timeout(60 * 60 * 1000, () => { });
|
|
19
|
+
return this.exitFlow();
|
|
20
|
+
}
|
|
21
|
+
case 'bridge/ended': {
|
|
22
|
+
const { error, originateDisposition } = event.params;
|
|
23
|
+
const isSuccess = error === 'NORMAL_CLEARING' &&
|
|
24
|
+
(lodash_1.default.isUndefined(originateDisposition) || originateDisposition === 'SUCCESS');
|
|
25
|
+
if (isSuccess) {
|
|
26
|
+
await this.transcript(call, {
|
|
27
|
+
action: 'Live Translation Ended - Answered',
|
|
28
|
+
actionFromBot: true,
|
|
29
|
+
reportingSettingsKey: 'transcriptEndedAnswered'
|
|
30
|
+
});
|
|
31
|
+
return this.exitStep('success');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await this.transcript(call, {
|
|
35
|
+
action: 'Live Translation Ended - Not Answered',
|
|
36
|
+
actionFromBot: true,
|
|
37
|
+
reportingSettingsKey: 'transcriptEndedNotAnswered'
|
|
38
|
+
});
|
|
39
|
+
return this.exitStep('no answer');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
case 'translation/started':
|
|
43
|
+
this.log.info('translation started');
|
|
44
|
+
break;
|
|
45
|
+
case 'translation/error':
|
|
46
|
+
this.log.warn('translation error', { message: event.params.error?.message });
|
|
47
|
+
break;
|
|
48
|
+
case 'translation/stopped':
|
|
49
|
+
this.log.info('translation stopped', { reason: event.params.reason });
|
|
50
|
+
break;
|
|
51
|
+
case 'hangup': {
|
|
52
|
+
await this.handleHangup(call);
|
|
53
|
+
return await this.waitConvEnd();
|
|
54
|
+
}
|
|
55
|
+
case 'error':
|
|
56
|
+
return this.throwError(event.params.error);
|
|
57
|
+
}
|
|
58
|
+
return this.exitFlow();
|
|
59
|
+
});
|
|
60
|
+
this.triggers.otherwise(async () => {
|
|
61
|
+
const { phoneNumber, sessionTimeout, destination, sipHeaders = [], sipHost, sipUser, sipPassword, sipProfile, gatewaySettingsMode, from, muteRecording, disableRingback, } = this.data;
|
|
62
|
+
const timeout = Number(sessionTimeout);
|
|
63
|
+
const inheritGatewaySetting = gatewaySettingsMode === 'inherit';
|
|
64
|
+
const headers = Object.fromEntries(sipHeaders.map(({ name, value }) => [name, value]));
|
|
65
|
+
let gateway;
|
|
66
|
+
const profile = sipProfile !== "default" /* SIP_PROFILE.DEFAULT */ ? sipProfile : undefined;
|
|
67
|
+
switch (gatewaySettingsMode) {
|
|
68
|
+
case "custom" /* GATEWAY_SETTINGS_MODE.CUSTOM */:
|
|
69
|
+
gateway = {
|
|
70
|
+
host: sipHost,
|
|
71
|
+
user: sipUser,
|
|
72
|
+
username: sipUser,
|
|
73
|
+
password: sipPassword,
|
|
74
|
+
profile
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
case "profile" /* GATEWAY_SETTINGS_MODE.PROFILE */:
|
|
78
|
+
gateway = profile != null ? { profile } : undefined;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const botNumber = inheritGatewaySetting ? from : call.botNumber;
|
|
82
|
+
const maxLoops = this.session.data?.loopPrevention?.enabled
|
|
83
|
+
? this.session.data.loopPrevention.maxLoops
|
|
84
|
+
: undefined;
|
|
85
|
+
const command = {
|
|
86
|
+
name: 'bridgeTranslated',
|
|
87
|
+
params: {
|
|
88
|
+
botNumber,
|
|
89
|
+
transferFrom: phoneNumber,
|
|
90
|
+
transferTo: destination,
|
|
91
|
+
headers,
|
|
92
|
+
gateway,
|
|
93
|
+
timeout,
|
|
94
|
+
maxLoops,
|
|
95
|
+
...(disableRingback && { ringback: 'silence_stream://-1' }),
|
|
96
|
+
...this.translationParams()
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const muteAfterAnswer = !!muteRecording;
|
|
100
|
+
await this.pauseRecording(call, command, {
|
|
101
|
+
muteStep: muteAfterAnswer,
|
|
102
|
+
muteBot: muteAfterAnswer,
|
|
103
|
+
muteUser: muteAfterAnswer
|
|
104
|
+
});
|
|
105
|
+
await this.transcript(call, {
|
|
106
|
+
action: 'Live Translation Start',
|
|
107
|
+
actionFromBot: true,
|
|
108
|
+
reportingSettingsKey: 'transcript'
|
|
109
|
+
});
|
|
110
|
+
return this.exitFlow();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
translationParams() {
|
|
114
|
+
const { caller_language, destination_language, translator = {}, echo_protection = true, dub, agent_url_overwritten = false, agent_url = '', } = this.data;
|
|
115
|
+
let agentCustomUrl = '';
|
|
116
|
+
if (this.isStepFlagEnabled(agent_url_overwritten)) {
|
|
117
|
+
if (!this.isValidAgentUrl(agent_url)) {
|
|
118
|
+
this.throwError(new Error(`Voice Live Translation: invalid agent url "${agent_url}"`));
|
|
119
|
+
}
|
|
120
|
+
agentCustomUrl = agent_url;
|
|
121
|
+
}
|
|
122
|
+
const options = lodash_1.default.omitBy(translator.options, lodash_1.default.isEmpty);
|
|
123
|
+
return {
|
|
124
|
+
...(agentCustomUrl && { agent_url: agentCustomUrl }),
|
|
125
|
+
caller_language,
|
|
126
|
+
destination_language,
|
|
127
|
+
translator: lodash_1.default.omitBy({
|
|
128
|
+
provider: translator.provider || 'pinch',
|
|
129
|
+
model: translator.model,
|
|
130
|
+
api_key: translator.api_key,
|
|
131
|
+
options: lodash_1.default.isEmpty(options) ? undefined : options
|
|
132
|
+
}, lodash_1.default.isEmpty),
|
|
133
|
+
echo_protection,
|
|
134
|
+
...(dub?.enabled && {
|
|
135
|
+
dub: {
|
|
136
|
+
enabled: true,
|
|
137
|
+
...lodash_1.default.mapValues(lodash_1.default.omitBy(lodash_1.default.omit(dub, 'enabled'), value => value === '' || lodash_1.default.isNil(value)), Number)
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
isStepFlagEnabled(value) {
|
|
143
|
+
return value === true || value === 'true';
|
|
144
|
+
}
|
|
145
|
+
isValidAgentUrl(value) {
|
|
146
|
+
return /^wss?:\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+|\[[a-fA-F0-9:]+\])(:\d+)?(\/\S*)?$/.test(value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.default = VoiceLiveTranslation;
|
package/dst/voice.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface IVoiceCall extends IConversationData {
|
|
|
33
33
|
user: string;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export type EventType = 'hangup' | 'ack' | 'error' | 'cancel' | 'background' | 'avm-detected' | 'recognition' | 'digit' | 'digits' | 'conference-start' | 'conference-end' | 'playback' | 'timeout' | 'record' | 'bridge' | 'bridge/ended' | 'is_flow_ready' | 'call' | 'dtmf-sent';
|
|
36
|
+
export type EventType = 'hangup' | 'ack' | 'error' | 'cancel' | 'background' | 'avm-detected' | 'recognition' | 'digit' | 'digits' | 'conference-start' | 'conference-end' | 'playback' | 'timeout' | 'record' | 'bridge' | 'bridge/ended' | 'translation/started' | 'translation/error' | 'translation/stopped' | 'is_flow_ready' | 'call' | 'dtmf-sent';
|
|
37
37
|
export declare class VoiceStepError extends BasicError {
|
|
38
38
|
}
|
|
39
39
|
export type VoicerError = Error & {
|