@onereach/step-voice 4.0.5 → 4.0.6

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.
@@ -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(), from: botNumber, endUserNumber, sipHost, sipUser, sipPassword, timeout, headers, enableSpoofCallerId, spoofCallerId } = this.data;
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/v2',
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, isAMD, asr, tts } = this.data;
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,64 @@ class InitiateCall extends voice_1.default {
178
122
  return this.exitFlow();
179
123
  }
180
124
  });
125
+ this.triggers.otherwise(async () => {
126
+ const originateTimeout = timestring(`${timeout || 30} sec`, 'ms'); // timeout or 30 seconds
127
+ const customHeaders = _.reduce(headers, (memo, header) => {
128
+ memo[header.name] = `${header.value}`;
129
+ return memo;
130
+ }, {});
131
+ if (endUserNumber.startsWith('user:')) {
132
+ await this.thread.emitAsync({
133
+ target: 'provider',
134
+ name: 'out/voice/originate',
135
+ params: {
136
+ id: channelId,
137
+ from: botNumber,
138
+ to: endUserNumber,
139
+ headers: customHeaders,
140
+ spoofCallerId: {
141
+ enableSpoofCallerId,
142
+ spoofCallerId
143
+ },
144
+ gateway: sipHost
145
+ ? {
146
+ host: sipHost,
147
+ username: sipUser,
148
+ password: sipPassword
149
+ }
150
+ : undefined,
151
+ timeout: originateTimeout,
152
+ version: 2
153
+ }
154
+ });
155
+ }
156
+ else {
157
+ await this.thread.emitAsync({
158
+ target: 'provider',
159
+ name: 'out/voice/originate/v2',
160
+ params: {
161
+ id: channelId,
162
+ from: botNumber,
163
+ to: endUserNumber,
164
+ headers: customHeaders,
165
+ spoofCallerId: {
166
+ enableSpoofCallerId,
167
+ spoofCallerId
168
+ },
169
+ gateway: sipHost
170
+ ? {
171
+ host: sipHost,
172
+ username: sipUser,
173
+ password: sipPassword
174
+ }
175
+ : undefined,
176
+ timeout: originateTimeout,
177
+ version: 2,
178
+ sessionExpireTime: this.session.expireTime
179
+ }
180
+ });
181
+ }
182
+ });
181
183
  }
182
184
  }
183
185
  exports.default = InitiateCall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "4.0.5",
3
+ "version": "4.0.6",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",