@onereach/step-voice 4.0.4 → 4.0.7
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/Initiate Call.js +61 -58
- package/package.json +1 -1
package/dst/Initiate Call.js
CHANGED
|
@@ -14,63 +14,7 @@ class InitiateCall extends voice_1.default {
|
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
16
|
async runStep() {
|
|
17
|
-
const { channelId = uuid.v4()
|
|
18
|
-
const originateTimeout = timestring(`${timeout || 30} sec`, 'ms'); // timeout or 30 seconds
|
|
19
|
-
const customHeaders = _.reduce(headers, (memo, header) => {
|
|
20
|
-
memo[header.name] = `${header.value}`;
|
|
21
|
-
return memo;
|
|
22
|
-
}, {});
|
|
23
|
-
if (endUserNumber.startsWith('user:')) {
|
|
24
|
-
await this.thread.emitAsync({
|
|
25
|
-
target: 'provider',
|
|
26
|
-
name: 'out/voice/originate',
|
|
27
|
-
params: {
|
|
28
|
-
id: channelId,
|
|
29
|
-
from: botNumber,
|
|
30
|
-
to: endUserNumber,
|
|
31
|
-
headers: customHeaders,
|
|
32
|
-
spoofCallerId: {
|
|
33
|
-
enableSpoofCallerId,
|
|
34
|
-
spoofCallerId
|
|
35
|
-
},
|
|
36
|
-
gateway: sipHost
|
|
37
|
-
? {
|
|
38
|
-
host: sipHost,
|
|
39
|
-
username: sipUser,
|
|
40
|
-
password: sipPassword
|
|
41
|
-
}
|
|
42
|
-
: undefined,
|
|
43
|
-
timeout: originateTimeout,
|
|
44
|
-
version: 2
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
await this.thread.emitAsync({
|
|
50
|
-
target: 'provider',
|
|
51
|
-
name: 'out/voice/originate',
|
|
52
|
-
params: {
|
|
53
|
-
id: channelId,
|
|
54
|
-
from: botNumber,
|
|
55
|
-
to: endUserNumber,
|
|
56
|
-
headers: customHeaders,
|
|
57
|
-
spoofCallerId: {
|
|
58
|
-
enableSpoofCallerId,
|
|
59
|
-
spoofCallerId
|
|
60
|
-
},
|
|
61
|
-
gateway: sipHost
|
|
62
|
-
? {
|
|
63
|
-
host: sipHost,
|
|
64
|
-
username: sipUser,
|
|
65
|
-
password: sipPassword
|
|
66
|
-
}
|
|
67
|
-
: undefined,
|
|
68
|
-
timeout: originateTimeout,
|
|
69
|
-
version: 2,
|
|
70
|
-
sessionExpireTime: this.session.expireTime
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
17
|
+
const { channelId = uuid.v4() } = this.data;
|
|
74
18
|
if (!this.session.key) {
|
|
75
19
|
const sessionTimeoutMs = timestring(`${this.data.sessionTimeout} min`, 'ms') || defaultSessionTimeout;
|
|
76
20
|
await this.session.start({
|
|
@@ -88,7 +32,7 @@ class InitiateCall extends voice_1.default {
|
|
|
88
32
|
this.gotoState('waitForCall');
|
|
89
33
|
}
|
|
90
34
|
async waitForCall() {
|
|
91
|
-
const { from: botNumber, endUserNumber,
|
|
35
|
+
const { asr, tts, from: botNumber, endUserNumber, sipHost, sipUser, sipPassword, timeout, headers, enableSpoofCallerId, spoofCallerId, isAMD } = this.data;
|
|
92
36
|
const { id: channelId } = await this.getDataOut();
|
|
93
37
|
this.triggers.once(`in/voice/${channelId}/event`, async (event) => {
|
|
94
38
|
switch (event.params.type) {
|
|
@@ -178,6 +122,65 @@ class InitiateCall extends voice_1.default {
|
|
|
178
122
|
return this.exitFlow();
|
|
179
123
|
}
|
|
180
124
|
});
|
|
125
|
+
this.triggers.otherwise(async () => {
|
|
126
|
+
await this.triggers.flush();
|
|
127
|
+
const originateTimeout = timestring(`${timeout || 30} sec`, 'ms'); // timeout or 30 seconds
|
|
128
|
+
const customHeaders = _.reduce(headers, (memo, header) => {
|
|
129
|
+
memo[header.name] = `${header.value}`;
|
|
130
|
+
return memo;
|
|
131
|
+
}, {});
|
|
132
|
+
if (endUserNumber.startsWith('user:')) {
|
|
133
|
+
await this.thread.emitAsync({
|
|
134
|
+
target: 'provider',
|
|
135
|
+
name: 'out/voice/originate',
|
|
136
|
+
params: {
|
|
137
|
+
id: channelId,
|
|
138
|
+
from: botNumber,
|
|
139
|
+
to: endUserNumber,
|
|
140
|
+
headers: customHeaders,
|
|
141
|
+
spoofCallerId: {
|
|
142
|
+
enableSpoofCallerId,
|
|
143
|
+
spoofCallerId
|
|
144
|
+
},
|
|
145
|
+
gateway: sipHost
|
|
146
|
+
? {
|
|
147
|
+
host: sipHost,
|
|
148
|
+
username: sipUser,
|
|
149
|
+
password: sipPassword
|
|
150
|
+
}
|
|
151
|
+
: undefined,
|
|
152
|
+
timeout: originateTimeout,
|
|
153
|
+
version: 2
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
await this.thread.emitAsync({
|
|
159
|
+
target: 'provider',
|
|
160
|
+
name: 'out/voice/originate/v2',
|
|
161
|
+
params: {
|
|
162
|
+
id: channelId,
|
|
163
|
+
from: botNumber,
|
|
164
|
+
to: endUserNumber,
|
|
165
|
+
headers: customHeaders,
|
|
166
|
+
spoofCallerId: {
|
|
167
|
+
enableSpoofCallerId,
|
|
168
|
+
spoofCallerId
|
|
169
|
+
},
|
|
170
|
+
gateway: sipHost
|
|
171
|
+
? {
|
|
172
|
+
host: sipHost,
|
|
173
|
+
username: sipUser,
|
|
174
|
+
password: sipPassword
|
|
175
|
+
}
|
|
176
|
+
: undefined,
|
|
177
|
+
timeout: originateTimeout,
|
|
178
|
+
version: 2,
|
|
179
|
+
sessionExpireTime: this.session.expireTime
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
exports.default = InitiateCall;
|