webitel-sdk 0.1.92 → 0.1.93

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.
@@ -22485,6 +22485,7 @@ class Task {
22485
22485
  this.lastStatusChange = Date.now();
22486
22486
  }
22487
22487
  setProcessing(p) {
22488
+ this.state = 'processing'; // todo
22488
22489
  if (!this.startProcessingAt) {
22489
22490
  this.startProcessingAt = Date.now();
22490
22491
  }
@@ -23250,7 +23251,13 @@ class Conversation {
23250
23251
  this.members = (members || []).map((i) => wrapChannelMember(i));
23251
23252
  this._messages = messages || [];
23252
23253
  this.state = ConversationState.Invite;
23253
- this.variables = variables;
23254
+ this.variables = {};
23255
+ this._hasReporting = !!(variables && variables.cc_reporting === 'true');
23256
+ for (const k in variables) {
23257
+ if (!k.startsWith('cc_') && variables.hasOwnProperty(k)) {
23258
+ this.variables[k] = variables[k];
23259
+ }
23260
+ }
23254
23261
  if (variables &&
23255
23262
  variables.hasOwnProperty('cc_attempt_id') &&
23256
23263
  this.client.agent) {
@@ -23273,7 +23280,7 @@ class Conversation {
23273
23280
  this.closedAt = timestamp;
23274
23281
  }
23275
23282
  get id() {
23276
- return this.conversationId;
23283
+ return this.channelId || this.inviteId || this.conversationId;
23277
23284
  }
23278
23285
  get messages() {
23279
23286
  return this.getMessages();
@@ -23287,6 +23294,7 @@ class Conversation {
23287
23294
  channelId: i.channel_id,
23288
23295
  createdAt: i.created_at,
23289
23296
  updatedAt: i.updated_at,
23297
+ contact: null,
23290
23298
  };
23291
23299
  if (i.hasOwnProperty('file')) {
23292
23300
  i.file.url = this.client.fileUrlDownload(i.file.id);
@@ -23295,6 +23303,9 @@ class Conversation {
23295
23303
  if (i.hasOwnProperty('text')) {
23296
23304
  msg.text = i.text;
23297
23305
  }
23306
+ if (i.hasOwnProperty('contact')) {
23307
+ msg.contact = i.contact;
23308
+ }
23298
23309
  return msg;
23299
23310
  });
23300
23311
  }
@@ -23320,7 +23331,14 @@ class Conversation {
23320
23331
  return this.answeredAt > 0 && this.hasReporting;
23321
23332
  }
23322
23333
  get hasReporting() {
23323
- return this.variables && this.variables.cc_reporting === 'true';
23334
+ return this._hasReporting;
23335
+ }
23336
+ get membersId() {
23337
+ const res = [this.id];
23338
+ for (const m of this.members) {
23339
+ res.push(m.id);
23340
+ }
23341
+ return res;
23324
23342
  }
23325
23343
  /*
23326
23344
  Actions
@@ -23344,7 +23362,7 @@ class Conversation {
23344
23362
  throw new Error('This conversation not active');
23345
23363
  return this.client.request(`close_chat`, {
23346
23364
  channel_id: this.channelId,
23347
- conversation_id: this.id,
23365
+ conversation_id: this.conversationId,
23348
23366
  cause,
23349
23367
  });
23350
23368
  }
@@ -23353,7 +23371,7 @@ class Conversation {
23353
23371
  throw new Error('This conversation not active');
23354
23372
  return this.client.request(`leave_chat`, {
23355
23373
  channel_id: this.channelId,
23356
- conversation_id: this.id,
23374
+ conversation_id: this.conversationId,
23357
23375
  cause,
23358
23376
  });
23359
23377
  }
@@ -23373,12 +23391,12 @@ class Conversation {
23373
23391
  }
23374
23392
  }
23375
23393
  async sendFile(file, cb) {
23376
- const storedFiles = await this.client.storeFile(this.id, [file], cb);
23394
+ const storedFiles = await this.client.storeFile(this.conversationId, [file], cb);
23377
23395
  const f = storedFiles[0];
23378
23396
  // todo bug if chat response error
23379
23397
  return this.client.request(`send_file_chat`, {
23380
23398
  channel_id: this.channelId,
23381
- conversation_id: this.id,
23399
+ conversation_id: this.conversationId,
23382
23400
  id: f.id,
23383
23401
  name: file.name,
23384
23402
  mime: f.mime,
@@ -23400,7 +23418,7 @@ class Conversation {
23400
23418
  async addToChat(userId, title) {
23401
23419
  return this.client.request(`add_to_chat`, {
23402
23420
  channel_id: this.channelId,
23403
- conversation_id: this.id,
23421
+ conversation_id: this.conversationId,
23404
23422
  user_id: userId,
23405
23423
  title,
23406
23424
  });
@@ -23430,7 +23448,7 @@ class Conversation {
23430
23448
  sendMessageTextChunk(text) {
23431
23449
  return this.client.request(`send_text_chat`, {
23432
23450
  channel_id: this.channelId,
23433
- conversation_id: this.id,
23451
+ conversation_id: this.conversationId,
23434
23452
  text,
23435
23453
  });
23436
23454
  }
@@ -24119,7 +24137,7 @@ class Client extends EventEmitter {
24119
24137
  break;
24120
24138
  case ChatActions.Joined:
24121
24139
  const joined = event.data;
24122
- conversation = this.conversationById(joined.conversation_id);
24140
+ conversation = this.conversationById(joined.member.id);
24123
24141
  if (conversation) {
24124
24142
  conversation.setAnswered(joined.member.id, timestamp, joined.member);
24125
24143
  }
@@ -24127,17 +24145,38 @@ class Client extends EventEmitter {
24127
24145
  case ChatActions.Message:
24128
24146
  const message = event.data;
24129
24147
  message.timestamp = timestamp;
24130
- conversation = this.conversationById(message.conversation_id);
24148
+ // fixme
24149
+ for (const v of this.allConversations()) {
24150
+ if (!v.closedAt && v.membersId.indexOf(message.channel_id) > -1) {
24151
+ conversation = v;
24152
+ }
24153
+ }
24131
24154
  if (conversation) {
24132
24155
  conversation.newMessage(message);
24133
24156
  }
24134
24157
  break;
24135
24158
  case ChatActions.Close:
24159
+ const c = event.data;
24160
+ // fixme
24161
+ for (const v of this.allConversations()) {
24162
+ if (!v.closedAt && v.membersId.indexOf(c.from_channel_id) > -1) {
24163
+ conversation = v;
24164
+ }
24165
+ }
24166
+ if (conversation) {
24167
+ conversation.setClosed(timestamp);
24168
+ }
24169
+ break;
24136
24170
  case ChatActions.Leave:
24171
+ const l = event.data;
24172
+ conversation = this.conversationById(l.leaved_channel_id);
24173
+ if (conversation) {
24174
+ conversation.setClosed(timestamp);
24175
+ }
24176
+ break;
24137
24177
  case ChatActions.Decline:
24138
- // TODO leave & CLOSE:
24139
24178
  const e = event.data;
24140
- conversation = this.conversationById(e.conversation_id);
24179
+ conversation = this.conversationById(e.invite_id);
24141
24180
  if (conversation) {
24142
24181
  conversation.setClosed(timestamp);
24143
24182
  }