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.
@@ -25263,6 +25263,7 @@
25263
25263
  this.lastStatusChange = Date.now();
25264
25264
  };
25265
25265
  Task.prototype.setProcessing = function (p) {
25266
+ this.state = 'processing'; // todo
25266
25267
  if (!this.startProcessingAt) {
25267
25268
  this.startProcessingAt = Date.now();
25268
25269
  }
@@ -26284,7 +26285,13 @@
26284
26285
  this.members = (members || []).map(function (i) { return wrapChannelMember(i); });
26285
26286
  this._messages = messages || [];
26286
26287
  this.state = exports.ConversationState.Invite;
26287
- this.variables = variables;
26288
+ this.variables = {};
26289
+ this._hasReporting = !!(variables && variables.cc_reporting === 'true');
26290
+ for (var k in variables) {
26291
+ if (!k.startsWith('cc_') && variables.hasOwnProperty(k)) {
26292
+ this.variables[k] = variables[k];
26293
+ }
26294
+ }
26288
26295
  if (variables &&
26289
26296
  variables.hasOwnProperty('cc_attempt_id') &&
26290
26297
  this.client.agent) {
@@ -26308,7 +26315,7 @@
26308
26315
  };
26309
26316
  Object.defineProperty(Conversation.prototype, "id", {
26310
26317
  get: function () {
26311
- return this.conversationId;
26318
+ return this.channelId || this.inviteId || this.conversationId;
26312
26319
  },
26313
26320
  enumerable: true,
26314
26321
  configurable: true
@@ -26330,6 +26337,7 @@
26330
26337
  channelId: i.channel_id,
26331
26338
  createdAt: i.created_at,
26332
26339
  updatedAt: i.updated_at,
26340
+ contact: null,
26333
26341
  };
26334
26342
  if (i.hasOwnProperty('file')) {
26335
26343
  i.file.url = _this.client.fileUrlDownload(i.file.id);
@@ -26338,6 +26346,9 @@
26338
26346
  if (i.hasOwnProperty('text')) {
26339
26347
  msg.text = i.text;
26340
26348
  }
26349
+ if (i.hasOwnProperty('contact')) {
26350
+ msg.contact = i.contact;
26351
+ }
26341
26352
  return msg;
26342
26353
  });
26343
26354
  };
@@ -26388,7 +26399,19 @@
26388
26399
  });
26389
26400
  Object.defineProperty(Conversation.prototype, "hasReporting", {
26390
26401
  get: function () {
26391
- return this.variables && this.variables.cc_reporting === 'true';
26402
+ return this._hasReporting;
26403
+ },
26404
+ enumerable: true,
26405
+ configurable: true
26406
+ });
26407
+ Object.defineProperty(Conversation.prototype, "membersId", {
26408
+ get: function () {
26409
+ var res = [this.id];
26410
+ for (var _i = 0, _a = this.members; _i < _a.length; _i++) {
26411
+ var m = _a[_i];
26412
+ res.push(m.id);
26413
+ }
26414
+ return res;
26392
26415
  },
26393
26416
  enumerable: true,
26394
26417
  configurable: true
@@ -26425,7 +26448,7 @@
26425
26448
  throw new Error('This conversation not active');
26426
26449
  return [2 /*return*/, this.client.request("close_chat", {
26427
26450
  channel_id: this.channelId,
26428
- conversation_id: this.id,
26451
+ conversation_id: this.conversationId,
26429
26452
  cause: cause,
26430
26453
  })];
26431
26454
  });
@@ -26438,7 +26461,7 @@
26438
26461
  throw new Error('This conversation not active');
26439
26462
  return [2 /*return*/, this.client.request("leave_chat", {
26440
26463
  channel_id: this.channelId,
26441
- conversation_id: this.id,
26464
+ conversation_id: this.conversationId,
26442
26465
  cause: cause,
26443
26466
  })];
26444
26467
  });
@@ -26481,14 +26504,14 @@
26481
26504
  var storedFiles, f;
26482
26505
  return tslib.__generator(this, function (_a) {
26483
26506
  switch (_a.label) {
26484
- case 0: return [4 /*yield*/, this.client.storeFile(this.id, [file], cb)];
26507
+ case 0: return [4 /*yield*/, this.client.storeFile(this.conversationId, [file], cb)];
26485
26508
  case 1:
26486
26509
  storedFiles = _a.sent();
26487
26510
  f = storedFiles[0];
26488
26511
  // todo bug if chat response error
26489
26512
  return [2 /*return*/, this.client.request("send_file_chat", {
26490
26513
  channel_id: this.channelId,
26491
- conversation_id: this.id,
26514
+ conversation_id: this.conversationId,
26492
26515
  id: f.id,
26493
26516
  name: file.name,
26494
26517
  mime: f.mime,
@@ -26520,7 +26543,7 @@
26520
26543
  return tslib.__generator(this, function (_a) {
26521
26544
  return [2 /*return*/, this.client.request("add_to_chat", {
26522
26545
  channel_id: this.channelId,
26523
- conversation_id: this.id,
26546
+ conversation_id: this.conversationId,
26524
26547
  user_id: userId,
26525
26548
  title: title,
26526
26549
  })];
@@ -26568,7 +26591,7 @@
26568
26591
  Conversation.prototype.sendMessageTextChunk = function (text) {
26569
26592
  return this.client.request("send_text_chat", {
26570
26593
  channel_id: this.channelId,
26571
- conversation_id: this.id,
26594
+ conversation_id: this.conversationId,
26572
26595
  text: text,
26573
26596
  });
26574
26597
  };
@@ -27503,8 +27526,8 @@
27503
27526
  };
27504
27527
  Client.prototype.handleChatEvents = function (event) {
27505
27528
  return tslib.__awaiter(this, void 0, void 0, function () {
27506
- var conversation, timestamp, inv, joined, message, e;
27507
- return tslib.__generator(this, function (_a) {
27529
+ var conversation, timestamp, inv, joined, message, _i, _a, v, c, _b, _c, v, l, e;
27530
+ return tslib.__generator(this, function (_d) {
27508
27531
  timestamp = Date.now() // todo bug
27509
27532
  ;
27510
27533
  switch (event.action) {
@@ -27516,7 +27539,7 @@
27516
27539
  break;
27517
27540
  case exports.ChatActions.Joined:
27518
27541
  joined = event.data;
27519
- conversation = this.conversationById(joined.conversation_id);
27542
+ conversation = this.conversationById(joined.member.id);
27520
27543
  if (conversation) {
27521
27544
  conversation.setAnswered(joined.member.id, timestamp, joined.member);
27522
27545
  }
@@ -27524,16 +27547,40 @@
27524
27547
  case exports.ChatActions.Message:
27525
27548
  message = event.data;
27526
27549
  message.timestamp = timestamp;
27527
- conversation = this.conversationById(message.conversation_id);
27550
+ // fixme
27551
+ for (_i = 0, _a = this.allConversations(); _i < _a.length; _i++) {
27552
+ v = _a[_i];
27553
+ if (!v.closedAt && v.membersId.indexOf(message.channel_id) > -1) {
27554
+ conversation = v;
27555
+ }
27556
+ }
27528
27557
  if (conversation) {
27529
27558
  conversation.newMessage(message);
27530
27559
  }
27531
27560
  break;
27532
27561
  case exports.ChatActions.Close:
27562
+ c = event.data;
27563
+ // fixme
27564
+ for (_b = 0, _c = this.allConversations(); _b < _c.length; _b++) {
27565
+ v = _c[_b];
27566
+ if (!v.closedAt && v.membersId.indexOf(c.from_channel_id) > -1) {
27567
+ conversation = v;
27568
+ }
27569
+ }
27570
+ if (conversation) {
27571
+ conversation.setClosed(timestamp);
27572
+ }
27573
+ break;
27533
27574
  case exports.ChatActions.Leave:
27575
+ l = event.data;
27576
+ conversation = this.conversationById(l.leaved_channel_id);
27577
+ if (conversation) {
27578
+ conversation.setClosed(timestamp);
27579
+ }
27580
+ break;
27534
27581
  case exports.ChatActions.Decline:
27535
27582
  e = event.data;
27536
- conversation = this.conversationById(e.conversation_id);
27583
+ conversation = this.conversationById(e.invite_id);
27537
27584
  if (conversation) {
27538
27585
  conversation.setClosed(timestamp);
27539
27586
  }