@onereach/step-voice 4.0.3 → 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,70 +14,27 @@ class InitiateCall extends voice_1.default {
14
14
  return undefined;
15
15
  }
16
16
  async runStep() {
17
- const { from: botNumber, endUserNumber, sipHost, sipUser, sipPassword, timeout, headers, originationId = uuid.v4(), 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: originationId,
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
17
+ const { channelId = uuid.v4() } = this.data;
18
+ if (!this.session.key) {
19
+ const sessionTimeoutMs = timestring(`${this.data.sessionTimeout} min`, 'ms') || defaultSessionTimeout;
20
+ await this.session.start({
21
+ key: channelId,
22
+ timeout: sessionTimeoutMs,
23
+ reporting: {
24
+ settingsKey: 'session',
25
+ startedBy: 'Bot',
26
+ sessionType: 'Phone'
45
27
  }
46
28
  });
47
29
  }
48
- else {
49
- await this.thread.emitAsync({
50
- target: 'provider',
51
- name: 'out/voice/originate',
52
- params: {
53
- id: originationId,
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
- }
74
- await this.setDataOut({ id: originationId });
30
+ await this.startConversation({ id: channelId }, { events: [] });
31
+ // await this.setDataOut()
75
32
  this.gotoState('waitForCall');
76
33
  }
77
34
  async waitForCall() {
78
- const { from: botNumber, endUserNumber, isAMD, asr, tts, sessionTimeout } = this.data;
79
- const { id: originationId } = await this.getDataOut();
80
- this.triggers.once(`in/voice/${originationId}/event`, async (event) => {
35
+ const { asr, tts, from: botNumber, endUserNumber, sipHost, sipUser, sipPassword, timeout, headers, enableSpoofCallerId, spoofCallerId, isAMD } = this.data;
36
+ const { id: channelId } = await this.getDataOut();
37
+ this.triggers.once(`in/voice/${channelId}/event`, async (event) => {
81
38
  switch (event.params.type) {
82
39
  case 'is_flow_ready': {
83
40
  // TODO this.exitFlow({is_ready : true}) should be enough
@@ -102,18 +59,6 @@ class InitiateCall extends voice_1.default {
102
59
  };
103
60
  delete channel.from;
104
61
  delete channel.to;
105
- if (!this.session.key) {
106
- const sessionTimeoutMs = timestring(`${sessionTimeout} min`, 'ms') || defaultSessionTimeout;
107
- await this.session.start({
108
- key: channel.id,
109
- timeout: sessionTimeoutMs,
110
- reporting: {
111
- settingsKey: 'session',
112
- startedBy: 'Bot',
113
- sessionType: 'Phone'
114
- }
115
- });
116
- }
117
62
  await this.startConversation(channel, {
118
63
  events: { [`in/voice/${channel.id}/event`]: {} }
119
64
  });
@@ -143,17 +88,6 @@ class InitiateCall extends voice_1.default {
143
88
  return this.exitStep('success');
144
89
  }
145
90
  case 'error': {
146
- if (!this.session.key) {
147
- await this.session.start({
148
- key: this.thread.request.requestId,
149
- timeout: sessionTimeoutMs,
150
- reporting: {
151
- settingsKey: 'session',
152
- startedBy: 'Bot',
153
- sessionType: 'Phone'
154
- }
155
- });
156
- }
157
91
  const error = _.get(event, 'params.error.originateStatus');
158
92
  const errorChannel = {
159
93
  botNumber,
@@ -188,6 +122,64 @@ class InitiateCall extends voice_1.default {
188
122
  return this.exitFlow();
189
123
  }
190
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
+ });
191
183
  }
192
184
  }
193
185
  exports.default = InitiateCall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "4.0.3",
3
+ "version": "4.0.6",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",