@subiz/widget-v4 4.1.117 → 4.1.120

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.
Files changed (56) hide show
  1. package/assets/less/base.less +1 -0
  2. package/assets/less/chatbox.less +2 -0
  3. package/assets/less/message.less +42 -22
  4. package/assets/less/message_input.less +2 -0
  5. package/assets/less/order.less +1 -1
  6. package/assets/less/widget.less +36 -18
  7. package/assets/less/widget_header.less +35 -36
  8. package/compiled_src/chatbox/AgentsAvatar.js +1 -1
  9. package/compiled_src/chatbox/Event.js +87 -13
  10. package/compiled_src/chatbox/Events.js +106 -19
  11. package/compiled_src/chatbox/Header.js +5 -4
  12. package/compiled_src/chatbox/InfoMessage.js +2 -13
  13. package/compiled_src/chatbox/MessageInput.js +19 -9
  14. package/compiled_src/chatbox/TextMessage.js +11 -2
  15. package/compiled_src/chatbox/Widget.js +28 -23
  16. package/compiled_src/chatbox/time.js +1 -0
  17. package/compiled_src/util/common.js +89 -0
  18. package/dist/185.js +19 -19
  19. package/dist/19641cfa41e.278.js +1 -0
  20. package/dist/19641cfa41e.app.js +1 -0
  21. package/dist/{195ec5442e3.index.html → 19641cfa41e.index.html} +1 -1
  22. package/dist/{195ec5442e3.library.html → 19641cfa41e.library.html} +1 -1
  23. package/dist/19641cfa41e.library.js +1 -0
  24. package/dist/{195ec5442e3.preview.html → 19641cfa41e.preview.html} +1 -1
  25. package/dist/19641cfa41e.preview.js +1 -0
  26. package/dist/19641cfa41e.webview.js +1 -0
  27. package/dist/278.js +1 -1
  28. package/dist/HASH +1 -1
  29. package/dist/screenshoot.js +562 -185
  30. package/package.json +2 -2
  31. package/src/chatbox/AgentsAvatar.js +1 -1
  32. package/src/chatbox/Event.js +88 -14
  33. package/src/chatbox/Events.js +93 -15
  34. package/src/chatbox/Header.js +3 -2
  35. package/src/chatbox/InfoMessage.js +0 -14
  36. package/src/chatbox/MessageInput.js +18 -7
  37. package/src/chatbox/TextMessage.js +13 -0
  38. package/src/chatbox/Widget.js +16 -18
  39. package/src/chatbox/time.js +12 -8
  40. package/src/util/common.js +121 -0
  41. package/up +33 -21
  42. package/compiled_src/chatbox/Typing.js +0 -77
  43. package/dist/195ec5442e3.278.js +0 -1
  44. package/dist/195ec5442e3.app.js +0 -1
  45. package/dist/195ec5442e3.library.js +0 -1
  46. package/dist/195ec5442e3.preview.js +0 -1
  47. package/dist/195ec5442e3.webview.js +0 -1
  48. package/src/chatbox/Typing.js +0 -72
  49. /package/dist/{195ec5442e3.127.js → 19641cfa41e.127.js} +0 -0
  50. /package/dist/{195ec5442e3.132.js → 19641cfa41e.132.js} +0 -0
  51. /package/dist/{195ec5442e3.185.js → 19641cfa41e.185.js} +0 -0
  52. /package/dist/{195ec5442e3.27.js → 19641cfa41e.27.js} +0 -0
  53. /package/dist/{195ec5442e3.459.js → 19641cfa41e.459.js} +0 -0
  54. /package/dist/{195ec5442e3.490.js → 19641cfa41e.490.js} +0 -0
  55. /package/dist/{195ec5442e3.74.js → 19641cfa41e.74.js} +0 -0
  56. /package/dist/{195ec5442e3.997.js → 19641cfa41e.997.js} +0 -0
@@ -722,6 +722,7 @@ class Time extends _common_js__WEBPACK_IMPORTED_MODULE_1__/* .Com */ .Mw {
722
722
  }
723
723
  let title = new Date(this.props.time).toLocaleString(locale);
724
724
  return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("span", {
725
+ class: this.props.class,
725
726
  style: this.props.style,
726
727
  title: title
727
728
  }, this.state.t);
@@ -2521,6 +2522,7 @@ __webpack_require__.r(__webpack_exports__);
2521
2522
  /* harmony export */ getMs: () => (/* binding */ getMs),
2522
2523
  /* harmony export */ getUrlParameter: () => (/* binding */ getUrlParameter),
2523
2524
  /* harmony export */ getUserAttr: () => (/* binding */ getUserAttr),
2525
+ /* harmony export */ hslToRgb: () => (/* binding */ hslToRgb),
2524
2526
  /* harmony export */ includes: () => (/* binding */ includes),
2525
2527
  /* harmony export */ isConvoSeen: () => (/* binding */ isConvoSeen),
2526
2528
  /* harmony export */ isEmail: () => (/* binding */ isEmail),
@@ -2546,6 +2548,7 @@ __webpack_require__.r(__webpack_exports__);
2546
2548
  /* harmony export */ replaceCssVariable: () => (/* binding */ replaceCssVariable),
2547
2549
  /* harmony export */ replaceCssVariablePlugin: () => (/* binding */ replaceCssVariablePlugin),
2548
2550
  /* harmony export */ requestAnimationFrame: () => (/* binding */ requestAnimationFrame),
2551
+ /* harmony export */ rgbToHsl: () => (/* binding */ rgbToHsl),
2549
2552
  /* harmony export */ sameDay: () => (/* binding */ sameDay),
2550
2553
  /* harmony export */ scrollIntoViewIfNeeded: () => (/* binding */ scrollIntoViewIfNeeded),
2551
2554
  /* harmony export */ setCss: () => (/* binding */ setCss),
@@ -2566,6 +2569,55 @@ __webpack_require__.r(__webpack_exports__);
2566
2569
  /* harmony export */ usersOfConvo: () => (/* binding */ usersOfConvo)
2567
2570
  /* harmony export */ });
2568
2571
  var op = __webpack_require__(3259);
2572
+ function rgbToHsl(r, g, b) {
2573
+ ;
2574
+ r /= 255, g /= 255, b /= 255;
2575
+ var max = Math.max(r, g, b),
2576
+ min = Math.min(r, g, b);
2577
+ var h,
2578
+ s,
2579
+ l = (max + min) / 2;
2580
+ if (max == min) {
2581
+ h = s = 0;
2582
+ } else {
2583
+ var d = max - min;
2584
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
2585
+ switch (max) {
2586
+ case r:
2587
+ h = (g - b) / d + (g < b ? 6 : 0);
2588
+ break;
2589
+ case g:
2590
+ h = (b - r) / d + 2;
2591
+ break;
2592
+ case b:
2593
+ h = (r - g) / d + 4;
2594
+ break;
2595
+ }
2596
+ h /= 6;
2597
+ }
2598
+ return [h, s, l];
2599
+ }
2600
+ function hslToRgb(h, s, l) {
2601
+ var r, g, b;
2602
+ if (s == 0) {
2603
+ r = g = b = l;
2604
+ } else {
2605
+ function hue2rgb(p, q, t) {
2606
+ if (t < 0) t += 1;
2607
+ if (t > 1) t -= 1;
2608
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
2609
+ if (t < 1 / 2) return q;
2610
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
2611
+ return p;
2612
+ }
2613
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
2614
+ var p = 2 * l - q;
2615
+ r = hue2rgb(p, q, h + 1 / 3);
2616
+ g = hue2rgb(p, q, h);
2617
+ b = hue2rgb(p, q, h - 1 / 3);
2618
+ }
2619
+ return [r * 255, g * 255, b * 255];
2620
+ }
2569
2621
  function extractEmojis(text) {
2570
2622
  var out = [];
2571
2623
  for (var i = 0; i < text.length; i++) {
@@ -2695,6 +2747,8 @@ function parseJSON(str) {
2695
2747
  var f = document.createElement('iframe');
2696
2748
  f.style.display = 'none';
2697
2749
  document.documentElement.appendChild(f);
2750
+ const tempElement = f.contentDocument.createElement('div');
2751
+ f.contentDocument.body.appendChild(tempElement);
2698
2752
  var stringify = f.contentWindow.JSON.stringify;
2699
2753
  var parse = f.contentWindow.JSON.parse;
2700
2754
  var Date = f.contentWindow.Date;
@@ -3002,6 +3056,16 @@ function replaceCssVariablePlugin(css, setting) {
3002
3056
  tokens = tokenize(tokens, "'@spacer0'");
3003
3057
  tokens = tokenize(tokens, "'@spacer2'");
3004
3058
  tokens = tokenize(tokens, "'@spacer3'");
3059
+ var primary_color = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
3060
+ let parseColor = parseCssColor(primary_color);
3061
+ if (!parseColor) parseColor = {
3062
+ red: 238,
3063
+ blue: 238,
3064
+ green: 238
3065
+ };
3066
+ let hue = rgbToHsl(parseColor.red, parseColor.green, parseColor.blue)[0];
3067
+ let [r, g, b] = hslToRgb(hue, 0.5, 0.95);
3068
+ DEFVAL.primary_color_faded = `rgb(${r},${g},${b})`;
3005
3069
  var ret = [];
3006
3070
  for (var i = 0; i < tokens.length; i++) {
3007
3071
  var item = tokens[i];
@@ -3018,6 +3082,7 @@ function replaceCssVariablePlugin(css, setting) {
3018
3082
  function replaceCssVariable(css, setting) {
3019
3083
  var tokens = [css];
3020
3084
  tokens = tokenize(tokens, "'@primary_color'");
3085
+ tokens = tokenize(tokens, "'@primary_color_faded'");
3021
3086
  tokens = tokenize(tokens, '@esc-primary-color-esc');
3022
3087
  tokens = tokenize(tokens, "'@secondary_color'");
3023
3088
  tokens = tokenize(tokens, "'@background'");
@@ -3042,6 +3107,16 @@ function replaceCssVariable(css, setting) {
3042
3107
  tokens = tokenize(tokens, "'@z_index_3'");
3043
3108
  tokens = tokenize(tokens, "'@z_index_4'");
3044
3109
  tokens = tokenize(tokens, "'@z_index_5'");
3110
+ var primary_color = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
3111
+ let parseColor = parseCssColor(primary_color);
3112
+ if (!parseColor) parseColor = {
3113
+ red: 238,
3114
+ blue: 238,
3115
+ green: 238
3116
+ };
3117
+ let hue = rgbToHsl(parseColor.red, parseColor.green, parseColor.blue)[0];
3118
+ let [r, g, b] = hslToRgb(hue, 0.5, 0.95);
3119
+ DEFVAL.primary_color_faded = `rgb(${r},${g},${b})`;
3045
3120
  var ret = [];
3046
3121
  for (var i = 0; i < tokens.length; i++) {
3047
3122
  var item = tokens[i];
@@ -3668,6 +3743,21 @@ function _blockToText(block) {
3668
3743
  });
3669
3744
  return out;
3670
3745
  }
3746
+ function parseCssColor(color) {
3747
+ if (!color || !color.split) return '';
3748
+ tempElement.style.color = color;
3749
+ const computedColor = f.contentWindow.getComputedStyle(tempElement).color;
3750
+ const match = computedColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)/);
3751
+ if (match) {
3752
+ return {
3753
+ red: parseInt(match[1]),
3754
+ green: parseInt(match[2]),
3755
+ blue: parseInt(match[3])
3756
+ };
3757
+ } else {
3758
+ return null;
3759
+ }
3760
+ }
3671
3761
  let emojis = ['like', 'unlike', 'wink', 'tongue-out', 'tired', 'surprised', 'smiling', 'sleepy', 'sad', 'neutral', 'heart-eyes', 'grinning', 'crying', 'confused', 'angry', 'cry', 'heart_eyes', 'neutral_face', 'emoji--disappointed', 'smile', 'open_mouth', 'tired_face', 'stuck_out_tongue', 'moyai', 'thumbsdown', 'dislike', 'thumbsup', 'ok_hand', 'octopus', 'pig2', 'wave', 'mouse', 'mouse2', 'rat'];
3672
3762
  emojis = map(emojis, e => ':' + e + ':');
3673
3763
  function absLink(url) {
@@ -4918,6 +5008,15 @@ class Store {
4918
5008
  highlight(pluginid, ref) {
4919
5009
  this.pubsub.publish('highlight', pluginid, ref);
4920
5010
  }
5011
+ emitConvoEvent(ev) {
5012
+ this.pubsub.publish('events', ev);
5013
+ }
5014
+ setAIDevMode(mode) {
5015
+ this.ai_dev_mode = mode;
5016
+ }
5017
+ isAIDevMode() {
5018
+ return this.ai_dev_mode;
5019
+ }
4921
5020
  overrideDeviceType(type) {
4922
5021
  this.forceDevice = type;
4923
5022
  this.pubsub.publish('account');
@@ -5306,7 +5405,17 @@ class Store {
5306
5405
  var oldev = this.chain.match(cid, msgid);
5307
5406
  if (!util/* default */.A.get(oldev, 'data.message')) return;
5308
5407
  var pongs = util/* default */.A.get(oldev, 'data.message.pongs', []);
5309
- pongs = pongs.concat(util/* default */.A.get(ev, 'data.message.pongs', []));
5408
+ let newpongs = util/* default */.A.get(ev, 'data.message.pongs', []) || [];
5409
+ pongs = pongs.concat(newpongs);
5410
+ if (newpongs.length === 1) {
5411
+ let pongtype = newpongs[0].type;
5412
+ if (pongtype === 'like' || pongtype === 'remove_dislike') {
5413
+ pongs = pongs.filter(pong => pong.type !== 'dislike');
5414
+ }
5415
+ if (pongtype === 'dislike' || pongtype === 'remove_like') {
5416
+ pongs = pongs.filter(pong => pong.type !== 'like');
5417
+ }
5418
+ }
5310
5419
  oldev.data.message.pongs = pongs;
5311
5420
  util/* default */.A.map(pongs, pong => {
5312
5421
  if (pong.member_id == user.id && pong.type === 'seen') {
@@ -5315,6 +5424,7 @@ class Store {
5315
5424
  }
5316
5425
  });
5317
5426
  this.chain.put(cid, oldev.id, util/* default */.A.getMs(oldev.created), oldev);
5427
+ this.pubsub.publish('events', oldev);
5318
5428
  }
5319
5429
  if (ev.type === 'message_sent') {
5320
5430
  let idemkey = util/* default */.A.get(ev, 'data.message.idempotency_key');
@@ -5341,6 +5451,7 @@ class Store {
5341
5451
  this._typing(cid);
5342
5452
  }
5343
5453
  async startConvo(req) {
5454
+ if (!req) req = {};
5344
5455
  await this.readyGate.entry();
5345
5456
  this.convoGate.close();
5346
5457
  if (!req.source) req.source = document.location.href;
@@ -5366,6 +5477,9 @@ class Store {
5366
5477
  createPostback(cid, postback) {
5367
5478
  return this.api.createPostback(cid, postback);
5368
5479
  }
5480
+ sendReaction(cid, ev) {
5481
+ return this.api.sendConvoEvent(cid, ev);
5482
+ }
5369
5483
  async sendConvoEvent(cid, type, data) {
5370
5484
  await this.readyGate.entry();
5371
5485
  var idempotency = util/* default */.A.randomString(36);
@@ -6176,6 +6290,7 @@ var logo = __webpack_require__(9529);
6176
6290
 
6177
6291
  function PoweredBy(props) {
6178
6292
  if (props.store.isMobile()) return null;
6293
+ if (props.store.isAIDevMode()) return null;
6179
6294
  let user = props.store.matchUser() || {};
6180
6295
  var link = `https://subiz.com.vn/?utm_source=${window.location.host || `id-${user.account_id}`}&utm_medium=widget&utm_campaign=widget_referral`;
6181
6296
  return (0,preact_module.h)("div", {
@@ -6229,7 +6344,7 @@ function AgentsAvatar(props) {
6229
6344
  }
6230
6345
  }
6231
6346
  agents = util/* default */.A.filter(agents, ag => !!ag);
6232
- if (agents.length === 0) {
6347
+ if (agents.length === 0 || props.agent_ids === undefined || util/* default */.A.size(props.agent_ids) === 0) {
6233
6348
  return (0,preact_module.h)("div", {
6234
6349
  class: `group-avatar group-avatar--${mode}`
6235
6350
  }, (0,preact_module.h)("div", {
@@ -6370,11 +6485,12 @@ class Header extends common/* Com */.Mw {
6370
6485
  return (0,preact_module.h)("div", {
6371
6486
  class: cls,
6372
6487
  style: style
6373
- }, $back, (0,preact_module.h)(AgentsAvatar, {
6488
+ }, $back, (0,preact_module.h)("div", {
6489
+ class: "mr-2"
6490
+ }), (0,preact_module.h)(AgentsAvatar, {
6374
6491
  plugin: this.props.plugin,
6375
6492
  store: this.props.store,
6376
- mode: "secondary",
6377
- agent_ids: agentIdsJoined
6493
+ mode: "secondary"
6378
6494
  }), (0,preact_module.h)("div", {
6379
6495
  class: "widget-header--title-container"
6380
6496
  }, (0,preact_module.h)("div", {
@@ -6509,7 +6625,7 @@ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi
6509
6625
  let accSetting = this.props.plugin.chatbox || {};
6510
6626
  if (accSetting.hide_close_button) return null;
6511
6627
  return (0,preact_module.h)("div", {
6512
- class: "widget-header--button widget-header--button-close",
6628
+ class: "widget-header--button-close",
6513
6629
  "data-tooltip": this.props.t('close'),
6514
6630
  "data-tooltip-position": "bottom",
6515
6631
  onClick: e => this.onCloseClick(e)
@@ -6538,6 +6654,8 @@ let getJoinedNameMember = agents => {
6538
6654
  if (!agents.length) return null;
6539
6655
  return util/* default */.A.map(agents, agent => agent.fullname).join(', ');
6540
6656
  };
6657
+ // EXTERNAL MODULE: ./src/chatbox/spinner.js
6658
+ var spinner = __webpack_require__(4188);
6541
6659
  ;// ./src/chatbox/MessageInput.js
6542
6660
  function MessageInput_defineProperty(e, r, t) { return (r = MessageInput_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
6543
6661
  function MessageInput_toPropertyKey(t) { var i = MessageInput_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
@@ -6546,6 +6664,7 @@ function MessageInput_toPrimitive(t, r) { if ("object" != typeof t || !t) return
6546
6664
 
6547
6665
 
6548
6666
 
6667
+
6549
6668
  class MessageInput extends common/* Com */.Mw {
6550
6669
  constructor(props) {
6551
6670
  super(props);
@@ -6577,7 +6696,7 @@ class MessageInput extends common/* Com */.Mw {
6577
6696
  $input.blur();
6578
6697
  }
6579
6698
  render() {
6580
- var buttons = (0,preact_module.h)("div", {
6699
+ var $buttons = (0,preact_module.h)("div", {
6581
6700
  class: "d-flex flex-row align-self-end"
6582
6701
  }, this.renderEmoji(), (0,preact_module.h)("div", {
6583
6702
  "data-tooltip-poasition": "top-left",
@@ -6586,7 +6705,7 @@ class MessageInput extends common/* Com */.Mw {
6586
6705
  }));
6587
6706
  var msg = util/* default */.A.trim(this.state.msgValue);
6588
6707
  if (msg.length > 0) {
6589
- buttons = (0,preact_module.h)("div", {
6708
+ $buttons = (0,preact_module.h)("div", {
6590
6709
  class: "d-flex flex-row align-self-end"
6591
6710
  }, this.renderEmoji(), (0,preact_module.h)("div", {
6592
6711
  "data-tooltip-position": "top-left",
@@ -6594,9 +6713,16 @@ class MessageInput extends common/* Com */.Mw {
6594
6713
  onClick: () => this.submitMessage()
6595
6714
  }));
6596
6715
  }
6716
+ if (this.props.is_loading) {
6717
+ $buttons = (0,preact_module.h)("div", {
6718
+ class: "d-flex flex-row align-self-end"
6719
+ }, (0,preact_module.h)(spinner/* default */.A, {
6720
+ size: "32"
6721
+ }));
6722
+ }
6597
6723
  var containercls = '';
6598
6724
  var disabled = this.hasUnfinishRequiredFormOrLock() || this.props.disabled;
6599
- if (disabled) containercls = 'message-input--disabled';
6725
+ if (disabled || this.props.is_loading) containercls = 'message-input--disabled';
6600
6726
  return (0,preact_module.h)("div", {
6601
6727
  class: `message-input ${containercls}`,
6602
6728
  onClick: e => {
@@ -6612,7 +6738,7 @@ class MessageInput extends common/* Com */.Mw {
6612
6738
  disabled: disabled,
6613
6739
  class: "message-input--input",
6614
6740
  maxlength: "1024",
6615
- placeholder: this.props.t('message_input_help'),
6741
+ placeholder: this.props.t('message_input_help').substr(0, 25),
6616
6742
  ref: this.refMessageInput,
6617
6743
  rows: "1",
6618
6744
  value: this.state.msgValue,
@@ -6620,7 +6746,7 @@ class MessageInput extends common/* Com */.Mw {
6620
6746
  onPaste: e => this.pasteImage(e),
6621
6747
  "data-emojiable": "true",
6622
6748
  onKeydown: e => this.onKeydown(e)
6623
- }), buttons);
6749
+ }), $buttons);
6624
6750
  }
6625
6751
  hasUnfinishRequiredFormOrLock() {
6626
6752
  let convo = this.props.store.matchConvo(this.props.cid);
@@ -6748,6 +6874,12 @@ class MessageInput extends common/* Com */.Mw {
6748
6874
  class: "emoji-picker--item emoji--wink"
6749
6875
  })));
6750
6876
  }
6877
+ applyMessage(text) {
6878
+ this.setState({
6879
+ msgValue: text
6880
+ });
6881
+ this.resizeInput();
6882
+ }
6751
6883
  focus() {
6752
6884
  if (this.props.disabled) return;
6753
6885
  this.refMessageInput.current && this.refMessageInput.current.focus();
@@ -6826,15 +6958,17 @@ class MessageInput extends common/* Com */.Mw {
6826
6958
  msg = msg || util/* default */.A.trim(this.state.msgValue) || '';
6827
6959
  if (!msg) return;
6828
6960
  if (this.props.disabled) return;
6961
+ if (this.props.onSend) {
6962
+ await this.props.onSend({
6963
+ text: msg,
6964
+ format: 'plaintext'
6965
+ });
6966
+ }
6829
6967
  this.setState({
6830
6968
  openEmoji: false,
6831
6969
  msgValue: ''
6832
6970
  });
6833
6971
  this.resizeInput();
6834
- this.props.onSend && this.props.onSend({
6835
- text: msg,
6836
- format: 'plaintext'
6837
- });
6838
6972
  }
6839
6973
  sendTyping() {
6840
6974
  if (!this.props.cid) return;
@@ -6890,7 +7024,7 @@ class ImageAttachment extends common/* Com */.Mw {
6890
7024
  const MAX_HEIGHT = 240;
6891
7025
  const DEFAULT_MAX_WIDTH = 267;
6892
7026
  let $container = this.containerRef.current;
6893
- this.frameWidth = $container ? $container.offsetWidth : DEFAULT_MAX_WIDTH;
7027
+ this.frameWidth = $container ? $container.parentNode.parentNode.offsetWidth : DEFAULT_MAX_WIDTH;
6894
7028
  this.frameHeight = MAX_HEIGHT;
6895
7029
  this.setState({
6896
7030
  ready: true
@@ -7604,17 +7738,17 @@ class FormSubmitAttachments extends common/* Com */.Mw {
7604
7738
  render() {
7605
7739
  return null;
7606
7740
  let submits = [];
7607
- let attachments = util/* default */.A.get(this.props.ev, 'data.message.attachments') || [];
7608
- util/* default */.A.each(attachments, att => {
7741
+ let attachments = sb.get(this.props.ev, 'data.message.attachments') || [];
7742
+ sb.each(attachments, att => {
7609
7743
  if (!att) return;
7610
7744
  if (att.type !== 'form_submit') return;
7611
7745
  if (!att.form_submit) return;
7612
7746
  submits.push(att.form_submit);
7613
7747
  });
7614
- let $submits = util/* default */.A.map(submits, (submit, index) => (0,preact_module.h)("div", {
7748
+ let $submits = sb.map(submits, (submit, index) => h("div", {
7615
7749
  class: "info-message"
7616
- }, (0,preact_module.h)("span", null, this.props.tt('prechat_form_thanks'))));
7617
- return (0,preact_module.h)("div", null, $submits);
7750
+ }, h("span", null, this.props.tt('prechat_form_thanks'))));
7751
+ return h("div", null, $submits);
7618
7752
  }
7619
7753
  }
7620
7754
  ;// ./src/chatbox/touchscroll.js
@@ -7876,13 +8010,24 @@ class VideoAttachments extends common/* Com */.Mw {
7876
8010
  }, $videos);
7877
8011
  }
7878
8012
  }
8013
+ // EXTERNAL MODULE: ./src/chatbox/time.js
8014
+ var chatbox_time = __webpack_require__(1620);
7879
8015
  ;// ./src/chatbox/TextMessage.js
7880
8016
 
7881
8017
 
7882
8018
 
7883
8019
 
7884
8020
 
8021
+
7885
8022
  class TextMessage extends common/* Com */.Mw {
8023
+ renderTime() {
8024
+ if (!this.props.showTime && !this.props.isLast && !this.props.isFirst) return null;
8025
+ return (0,preact_module.h)("div", null, (0,preact_module.h)(chatbox_time/* default */.A, {
8026
+ class: "inline-time",
8027
+ time: util/* default */.A.get(this.props.ev, 'created', util/* default */.A.Date.now()),
8028
+ t: this.props.t
8029
+ }));
8030
+ }
7886
8031
  render() {
7887
8032
  var format = util/* default */.A.get(this.props.ev, 'data.message.format', 'plaintext');
7888
8033
  let block = util/* default */.A.get(this.props.ev, 'data.message.block');
@@ -7893,6 +8038,7 @@ class TextMessage extends common/* Com */.Mw {
7893
8038
  var text = util/* default */.A.get(this.props.ev, 'data.message.text');
7894
8039
  text = util/* default */.A.trim(text);
7895
8040
  if (util/* default */.A.size(text) === 0) return null;
8041
+ let t = new util/* default */.A.Date(util/* default */.A.get(this.props.ev, 'created')).toLocaleString();
7896
8042
  let byType = util/* default */.A.get(this.props.ev, 'by.type');
7897
8043
  if (byType !== 'user') byType = 'agent';
7898
8044
  var tags = util/* default */.A.extractText(text).map(tag => {
@@ -7921,26 +8067,31 @@ class TextMessage extends common/* Com */.Mw {
7921
8067
  });
7922
8068
  if (util/* default */.A.size(tags) === 0) return null;
7923
8069
  if (byType === 'agent') return (0,preact_module.h)("div", {
7924
- class: "message-agent message-text--agent"
7925
- }, tags);
8070
+ class: "message-agent message-text--agent",
8071
+ title: t
8072
+ }, tags, this.renderTime());
7926
8073
  return (0,preact_module.h)("div", {
7927
- class: "message-user message-text--user"
8074
+ class: "message-user message-text--user",
8075
+ title: t
7928
8076
  }, tags);
7929
8077
  }
7930
8078
  renderBlock(block) {
7931
8079
  if (isEmptyBlock(block)) return null;
8080
+ let t = new util/* default */.A.Date(util/* default */.A.get(this.props.ev, 'created')).toLocaleString();
7932
8081
  let byType = util/* default */.A.get(this.props.ev, 'by.type');
7933
8082
  if (byType !== 'user') byType = 'agent';
7934
8083
  if (byType === 'agent') {
7935
8084
  return (0,preact_module.h)("div", {
7936
- class: "message-agent message-text--agent"
8085
+ class: "message-agent message-text--agent",
8086
+ title: t
7937
8087
  }, (0,preact_module.h)(chatbox_block/* default */.A, {
7938
8088
  block: block,
7939
8089
  onLink: this.props.onLink
7940
- }));
8090
+ }), this.renderTime());
7941
8091
  }
7942
8092
  return (0,preact_module.h)("div", {
7943
- class: "message-user message-text--user"
8093
+ class: "message-user message-text--user",
8094
+ title: t
7944
8095
  }, (0,preact_module.h)(chatbox_block/* default */.A, {
7945
8096
  block: block,
7946
8097
  onLink: this.props.onLink
@@ -7952,8 +8103,6 @@ function isEmptyBlock(block) {
7952
8103
  let hasContent = util/* default */.A.size(util/* default */.A.filter(util/* default */.A.map(block.content, block => isEmptyBlock(block)), isEmpty => !isEmpty)) > 0;
7953
8104
  return !util/* default */.A.trim(block.text) && !hasContent;
7954
8105
  }
7955
- // EXTERNAL MODULE: ./src/chatbox/time.js
7956
- var chatbox_time = __webpack_require__(1620);
7957
8106
  ;// ./src/chatbox/InfoMessage.js
7958
8107
 
7959
8108
  function getRateLang(rating) {
@@ -7964,19 +8113,9 @@ function getRateLang(rating) {
7964
8113
  }
7965
8114
 
7966
8115
 
7967
-
7968
8116
  class InfoMessage extends common/* Com */.Mw {
7969
8117
  render() {
7970
8118
  let ev = this.props.ev.ev;
7971
- var $time = null;
7972
- if (this.props.ev.show_time) {
7973
- $time = (0,preact_module.h)("div", {
7974
- class: "convo-event-time"
7975
- }, (0,preact_module.h)(chatbox_time/* default */.A, {
7976
- time: ev.created,
7977
- t: this.props.t
7978
- }));
7979
- }
7980
8119
  if (ev.type === 'conversation_rated') {
7981
8120
  var rating = util/* default */.A.get(ev, 'data.conversation.ratings.0', {
7982
8121
  no_rating: true,
@@ -7985,14 +8124,14 @@ class InfoMessage extends common/* Com */.Mw {
7985
8124
  if (rating.no_rating) return null;
7986
8125
  return (0,preact_module.h)("div", {
7987
8126
  class: "convo-event"
7988
- }, $time, (0,preact_module.h)("div", {
8127
+ }, (0,preact_module.h)("div", {
7989
8128
  class: "info-message"
7990
8129
  }, this.props.t('rated_as') + ' ' + this.props.t(getRateLang(rating.rating)).toLowerCase()));
7991
8130
  }
7992
8131
  if (ev.type === 'conversation_state_updated' && util/* default */.A.get(ev, 'data.conversation.state') === 'ended') {
7993
8132
  return (0,preact_module.h)("div", {
7994
8133
  class: "convo-event"
7995
- }, $time, (0,preact_module.h)("div", {
8134
+ }, (0,preact_module.h)("div", {
7996
8135
  class: "info-message"
7997
8136
  }, this.props.t('conversation_ended')));
7998
8137
  }
@@ -8021,14 +8160,21 @@ const LoadOrderAttachments = () => __webpack_require__.e(/* import() */ 127).the
8021
8160
  class Event extends common/* Com */.Mw {
8022
8161
  constructor(props) {
8023
8162
  super(props);
8163
+ this.props.store.onConvoEvent(this, ev => this.onEvent(ev));
8024
8164
  this.refForm = (0,preact_module/* createRef */._3)();
8165
+ this.state = {
8166
+ pongs: util/* default */.A.get(this.props.event, 'ev.data.message.pongs') || []
8167
+ };
8025
8168
  }
8026
8169
  render() {
8027
8170
  var ev = util/* default */.A.get(this.props.event, 'ev', {});
8028
8171
  switch (ev.type) {
8172
+ case 'conversation_typing':
8173
+ return this.renderTyping();
8029
8174
  case 'conversation_joined':
8030
8175
  break;
8031
8176
  case 'message_sent':
8177
+ if (this.props.event.is_typing) return this.renderTyping();
8032
8178
  return this.renderMessageSent();
8033
8179
  case 'conversation_state_updated':
8034
8180
  case 'conversation_rating_requested':
@@ -8045,6 +8191,24 @@ class Event extends common/* Com */.Mw {
8045
8191
  focus() {
8046
8192
  this.refForm.current && this.refForm.current.focus();
8047
8193
  }
8194
+ onEvent(ev) {
8195
+ if (ev.id !== util/* default */.A.get(this.props.event, 'ev.id')) return;
8196
+ this.setState({
8197
+ pongs: util/* default */.A.get(ev, 'data.message.pongs') || []
8198
+ });
8199
+ }
8200
+ hasLike() {
8201
+ let {
8202
+ pongs
8203
+ } = this.state;
8204
+ return !!util/* default */.A.find(pongs, pong => pong.type === 'like');
8205
+ }
8206
+ hasDislike() {
8207
+ let {
8208
+ pongs
8209
+ } = this.state;
8210
+ return !!util/* default */.A.find(pongs, pong => pong.type === 'dislike');
8211
+ }
8048
8212
  chooseQuickReply(reply) {
8049
8213
  let ev = util/* default */.A.get(this.props.event, 'ev', {});
8050
8214
  let message = {
@@ -8122,26 +8286,87 @@ class Event extends common/* Com */.Mw {
8122
8286
  OrderAttachments = (await LoadOrderAttachments()).default;
8123
8287
  });
8124
8288
  }
8289
+ renderTyping() {
8290
+ let innercls = 'agent-convo-event-inner';
8291
+ var html = `
8292
+ <html>
8293
+ <head>
8294
+ <style>
8295
+ .typing-container {
8296
+ width: 100vw;
8297
+ height: 100vh;
8298
+ display: flex;
8299
+ align-items: center;
8300
+ gap: 4px;
8301
+ justify-content: center;
8302
+ }
8303
+ .typing-dot {
8304
+ display: inline-block;
8305
+ vertical-align: middle;
8306
+ width: 8px;
8307
+ height: 8px;
8308
+ background: black;
8309
+ border-radius: 50%;
8310
+ animation: typing 0.5s infinite alternate;
8311
+ }
8312
+ .typing-dot:nth-of-type(2) {
8313
+ animation-delay: 0.2s;
8314
+ }
8315
+ .typing-dot:nth-of-type(3) {
8316
+ animation-delay: 0.6s;
8317
+ }
8318
+ @keyframes typing {
8319
+ 0% {
8320
+ opacity: 0.9;
8321
+ }
8322
+ 100% {
8323
+ opacity: 0.4;
8324
+ }
8325
+ }
8326
+ </style>
8327
+ </head>
8328
+ <body style="padding: 0; margin: 0">
8329
+ <div class="typing-container">
8330
+ <span class="typing-dot"></span>
8331
+ <span class="typing-dot"></span>
8332
+ <span class="typing-dot"></span>
8333
+ </div>
8334
+ </body>
8335
+ </html>
8336
+ `;
8337
+ let src = 'data:text/html,' + encodeURIComponent(html);
8338
+ return (0,preact_module.h)("div", {
8339
+ class: "convo-event agent-message"
8340
+ }, (0,preact_module.h)("div", {
8341
+ class: "agent-convo-event-wrapper"
8342
+ }, (0,preact_module.h)("div", {
8343
+ class: innercls
8344
+ }, (0,preact_module.h)("div", {
8345
+ class: "message-agent message-text--agent",
8346
+ style: "opacity: 0.6 !important"
8347
+ }, (0,preact_module.h)("iframe", {
8348
+ src: src,
8349
+ style: "width: 35px !important; height: 20px !important; display: block !important; overflow: hidden !important; padding: 0 !important "
8350
+ })))));
8351
+ }
8125
8352
  renderMessageSent() {
8126
8353
  let ev = this.props.event.ev;
8127
8354
  this.tryLoadOrder(ev);
8128
- var $time = null;
8129
- if (this.props.event.show_time) {
8130
- $time = (0,preact_module.h)("div", {
8131
- class: "convo-event-time"
8132
- }, (0,preact_module.h)(chatbox_time/* default */.A, {
8133
- time: ev.created,
8134
- t: this.props.t
8135
- }));
8136
- }
8137
8355
  let t = new util/* default */.A.Date(ev.created).toLocaleString();
8138
8356
  if (util/* default */.A.get(ev, 'by.type') !== 'user') {
8139
8357
  let $sender = null;
8140
8358
  if (this.props.event.mode === 'lead') $sender = this.renderAgentAvatar(ev);
8359
+ let innercls = 'agent-convo-event-inner';
8360
+ if (this.props.isLast) innercls += ' last';
8141
8361
  return (0,preact_module.h)("div", {
8142
- class: "convo-event agent-message",
8143
- title: t
8144
- }, $time, $sender, (0,preact_module.h)(TextMessage, {
8362
+ class: "convo-event agent-message"
8363
+ }, $sender, (0,preact_module.h)("div", {
8364
+ class: "agent-convo-event-wrapper"
8365
+ }, (0,preact_module.h)("div", {
8366
+ class: innercls
8367
+ }, (0,preact_module.h)(TextMessage, {
8368
+ showTime: this.props.event.show_time,
8369
+ isLast: this.props.isLast,
8145
8370
  store: this.props.store,
8146
8371
  ev: ev,
8147
8372
  onLink: this.props.onLink
@@ -8189,7 +8414,7 @@ class Event extends common/* Com */.Mw {
8189
8414
  store: this.props.store,
8190
8415
  ev: ev,
8191
8416
  onSelect: e => this.chooseQuickReply(e)
8192
- }));
8417
+ }), this.renderReactions(), this.renderAIDevNote())));
8193
8418
  }
8194
8419
  if (util/* default */.A.get(ev, 'data.message.idempotency_key') === ev.id && this.props.store.now() - ev.created < 900) {
8195
8420
  util/* default */.A.setTimeout(() => this.setState({
@@ -8205,9 +8430,6 @@ class Event extends common/* Com */.Mw {
8205
8430
  });
8206
8431
  }
8207
8432
  let $sender = null;
8208
- if (this.props.event.mode === 'lead') $sender = (0,preact_module.h)("div", {
8209
- class: "pt-3"
8210
- });
8211
8433
  let $error = null;
8212
8434
  if (ev._error && ev.type === 'message_sent') {
8213
8435
  let msg = this.props.t('error_send_message');
@@ -8223,9 +8445,8 @@ class Event extends common/* Com */.Mw {
8223
8445
  }));
8224
8446
  }
8225
8447
  return (0,preact_module.h)("div", {
8226
- class: "convo-event user-message",
8227
- title: t
8228
- }, $time, $sender, (0,preact_module.h)("div", {
8448
+ class: "convo-event user-message"
8449
+ }, $sender, (0,preact_module.h)("div", {
8229
8450
  class: "message-user__container"
8230
8451
  }, $dot, (0,preact_module.h)(TextMessage, {
8231
8452
  store: this.props.store,
@@ -8262,6 +8483,106 @@ class Event extends common/* Com */.Mw {
8262
8483
  ev: ev
8263
8484
  })), $error);
8264
8485
  }
8486
+ async onSendReaction(action) {
8487
+ if (this._reacting) return;
8488
+ let ev = this.props.event.ev;
8489
+ let cid = util/* default */.A.get(ev, 'data.message.conversation_id');
8490
+ ev = {
8491
+ type: 'message_pong',
8492
+ data: {
8493
+ message: {
8494
+ id: ev.id,
8495
+ pongs: [{
8496
+ type: action
8497
+ }],
8498
+ conversion_id: cid
8499
+ }
8500
+ }
8501
+ };
8502
+ if (action == 'dislike' && this.props.store.isAIDevMode()) {
8503
+ this.props.store.emitConvoEvent({
8504
+ type: 'bad_feedbacked',
8505
+ data: {
8506
+ event: ev,
8507
+ id: ev.id,
8508
+ conversion_id: cid
8509
+ }
8510
+ });
8511
+ }
8512
+ let {
8513
+ pongs
8514
+ } = this.state;
8515
+ if (action === 'like') {
8516
+ pongs = pongs.filter(pong => pong.type !== 'dislike');
8517
+ pongs.push({
8518
+ type: 'like'
8519
+ });
8520
+ } else if (action === 'dislike') {
8521
+ pongs = pongs.filter(pong => pong.type !== 'like');
8522
+ pongs.push({
8523
+ type: 'dislike'
8524
+ });
8525
+ } else if (action === 'remove_like') {
8526
+ pongs = pongs.filter(pong => pong.type !== 'like');
8527
+ } else if (action === 'remove_dislike') {
8528
+ pongs = pongs.filter(pong => pong.type !== 'dislike');
8529
+ }
8530
+ this.setState({
8531
+ pongs
8532
+ });
8533
+ this._reacting = true;
8534
+ let res = await this.props.store.sendReaction(cid, ev);
8535
+ this._reacting = false;
8536
+ }
8537
+ renderReactions() {
8538
+ if (this.props.store.isAIDevMode()) return null;
8539
+ let ev = util/* default */.A.get(this.props.event, 'ev') || {};
8540
+ let pongs = util/* default */.A.get(ev, 'data.message.pongs') || [];
8541
+ let hasLike = this.hasLike();
8542
+ let hasDislike = this.hasDislike();
8543
+ let likecls = 'message-event-action-btn';
8544
+ if (hasLike) likecls += ' active';
8545
+ let dislikecls = 'message-event-action-btn';
8546
+ if (hasDislike) dislikecls += ' active';
8547
+ return (0,preact_module.h)("div", {
8548
+ class: "message-event-actions"
8549
+ }, (0,preact_module.h)("div", {
8550
+ class: likecls,
8551
+ onClick: () => this.onSendReaction(hasLike ? 'remove_like' : 'like')
8552
+ }, (0,preact_module.h)("div", {
8553
+ class: "message-event-action-btn-svg like"
8554
+ })), (0,preact_module.h)("div", {
8555
+ class: dislikecls,
8556
+ onClick: () => this.onSendReaction(hasDislike ? 'remove_dislike' : 'dislike')
8557
+ }, (0,preact_module.h)("div", {
8558
+ class: "message-event-action-btn-svg dislike"
8559
+ })));
8560
+ }
8561
+ renderAIDevNote() {
8562
+ if (!this.props.isLast) return null;
8563
+ if (!this.props.store.isAIDevMode()) return null;
8564
+ let ev = util/* default */.A.get(this.props.event, 'ev') || {};
8565
+ let pongs = util/* default */.A.get(ev, 'data.message.pongs') || [];
8566
+ let hasLike = this.hasLike();
8567
+ let hasDislike = this.hasDislike();
8568
+ let likecls = 'message-event-action-btn message-event-action-btn__dev message-event-action-btn_like';
8569
+ if (hasLike) likecls += ' active';
8570
+ let dislikecls = 'message-event-action-btn message-event-action-btn__dev message-event-action-btn_dislike';
8571
+ if (hasDislike) dislikecls += ' active';
8572
+ return (0,preact_module.h)("div", {
8573
+ class: "message-event-actions"
8574
+ }, (0,preact_module.h)("div", {
8575
+ class: likecls,
8576
+ onClick: () => this.onSendReaction(hasLike ? 'remove_like' : 'like')
8577
+ }, (0,preact_module.h)("div", {
8578
+ class: "message-event-action-btn-svg like"
8579
+ }), " Good"), (0,preact_module.h)("div", {
8580
+ class: dislikecls,
8581
+ onClick: () => this.onSendReaction(hasDislike ? 'remove_dislike' : 'dislike')
8582
+ }, (0,preact_module.h)("div", {
8583
+ class: "message-event-action-btn-svg dislike"
8584
+ }), " Bad"));
8585
+ }
8265
8586
  renderUpdateConvo(ev) {
8266
8587
  var state = util/* default */.A.get(ev, 'data.conversation.state');
8267
8588
  if (state === 'active') return null;
@@ -8294,8 +8615,6 @@ class Event extends common/* Com */.Mw {
8294
8615
  return acc.name;
8295
8616
  }
8296
8617
  }
8297
- // EXTERNAL MODULE: ./src/chatbox/spinner.js
8298
- var spinner = __webpack_require__(4188);
8299
8618
  ;// ./src/chatbox/Events.js
8300
8619
 
8301
8620
 
@@ -8318,9 +8637,64 @@ class Events extends common/* Com */.Mw {
8318
8637
  }, 500);
8319
8638
  this.checkAndSeen();
8320
8639
  }
8640
+ componentDidMount() {
8641
+ this.setState({
8642
+ isShowTyping: false,
8643
+ typing_event: {}
8644
+ });
8645
+ this.props.store.onConvoEvent(this, ev => {
8646
+ if (util/* default */.A.convoOfEv(ev) !== this.props.cid) return;
8647
+ if (util/* default */.A.get(ev, 'by.type') === 'user') return;
8648
+ let oldby = util/* default */.A.get(this.state.typing_event, 'by.id');
8649
+ if (oldby && util/* default */.A.get(ev, 'by.id') !== oldby) return;
8650
+ if (util/* default */.A.get(ev, 'type') === 'message_sent') {
8651
+ if (this.timer) util/* default */.A.clearTimeout(this.timer);
8652
+ this.timer = null;
8653
+ this.setState({
8654
+ isShowTyping: false
8655
+ });
8656
+ return;
8657
+ }
8658
+ if (util/* default */.A.get(ev, 'type') !== 'conversation_typing') return;
8659
+ let ag = this.props.store.matchAgent(util/* default */.A.get(ev, 'by.id')) || {};
8660
+ if (ag.type == 'agent' && !util/* default */.A.get(this.props.plugin, 'chatbox.show_agent_typing')) return;
8661
+ this.setState({
8662
+ typing_event: ev,
8663
+ isShowTyping: true
8664
+ });
8665
+ if (this.timer) util/* default */.A.clearTimeout(this.timer);
8666
+ this.timer = util/* default */.A.setTimeout(() => {
8667
+ if (util/* default */.A.convoOfEv(ev) !== this.props.cid) return;
8668
+ this.timer = null;
8669
+ this.setState({
8670
+ isShowTyping: false
8671
+ });
8672
+ }, 5000);
8673
+ });
8674
+ }
8321
8675
  componentDidUpdate(prevProps) {
8322
8676
  if (prevProps.cid !== this.props.cid) this.loadConvo();
8323
8677
  }
8678
+ ShowTyping() {
8679
+ this.setState({
8680
+ isShowTyping: true,
8681
+ typing_event: {
8682
+ id: 'evzz' + util/* default */.A.Date.now(),
8683
+ created: util/* default */.A.Date.now(),
8684
+ by: {
8685
+ type: 'agent'
8686
+ },
8687
+ type: 'conversation_typing'
8688
+ }
8689
+ });
8690
+ if (this.timer) util/* default */.A.clearTimeout(this.timer);
8691
+ this.timer = util/* default */.A.setTimeout(() => {
8692
+ this.timer = null;
8693
+ this.setState({
8694
+ isShowTyping: false
8695
+ });
8696
+ }, 5000);
8697
+ }
8324
8698
  render() {
8325
8699
  if (this.state.error) return this.renderError();
8326
8700
  let events = util/* default */.A.map(this.props.store.listEvents(this.props.cid));
@@ -8343,21 +8717,52 @@ class Events extends common/* Com */.Mw {
8343
8717
  events = util/* default */.A.map(events, ev => ({
8344
8718
  ev: ev
8345
8719
  }));
8720
+ if (this.state.isShowTyping) {
8721
+ let ev = this.state.typing_event || {
8722
+ id: 'evzz' + util/* default */.A.Date.now(),
8723
+ created: util/* default */.A.Date.now(),
8724
+ by: {
8725
+ type: 'agent'
8726
+ }
8727
+ };
8728
+ let fakeev = {
8729
+ is_typing: true,
8730
+ id: ev.id,
8731
+ ev: {
8732
+ id: ev.id,
8733
+ created: ev.created,
8734
+ by: ev.by,
8735
+ type: 'message_sent',
8736
+ data: {
8737
+ message: {
8738
+ text: '...',
8739
+ conversation_id: this.props.cid
8740
+ }
8741
+ }
8742
+ }
8743
+ };
8744
+ console.log('FA', fakeev);
8745
+ events.push(fakeev);
8746
+ }
8346
8747
  processEvents(convo, events);
8347
- let $events = util/* default */.A.map(events, ev => (0,preact_module.h)(Event, {
8348
- chatbox: this.props.chatbox,
8349
- onLink: this.props.onLink,
8350
- store: this.props.store,
8351
- onFormSubmit: this.props.onFormSubmit,
8352
- onSend: this.props.onSend,
8353
- onPostback: this.props.onPostback,
8354
- event: ev,
8355
- t: this.props.t,
8356
- key: ev.ev.id
8357
- }));
8748
+ let $events = util/* default */.A.map(events, ev => {
8749
+ let isLast = ev.ev.id === util/* default */.A.get(convo, 'last_message_sent.id');
8750
+ return (0,preact_module.h)(Event, {
8751
+ isLast: isLast,
8752
+ chatbox: this.props.chatbox,
8753
+ onLink: this.props.onLink,
8754
+ store: this.props.store,
8755
+ onFormSubmit: this.props.onFormSubmit,
8756
+ onSend: this.props.onSend,
8757
+ onPostback: this.props.onPostback,
8758
+ event: ev,
8759
+ t: this.props.t,
8760
+ key: ev.ev.id
8761
+ });
8762
+ });
8358
8763
  let $loading = null;
8359
8764
  let style = 'opacity: 1 !important';
8360
- if (this.state.loading || this.props.creating) {
8765
+ if (this.props.creating) {
8361
8766
  $loading = (0,preact_module.h)(spinner/* default */.A, {
8362
8767
  static: true,
8363
8768
  mode: util/* default */.A.get(this.props.chatbox, 'primary_color', 'dark'),
@@ -8366,6 +8771,17 @@ class Events extends common/* Com */.Mw {
8366
8771
  });
8367
8772
  style = 'opacity: 0 !important';
8368
8773
  }
8774
+ if (this.state.loading) {
8775
+ if (util/* default */.A.Date.now() - this.state.loading > 500) {
8776
+ $loading = (0,preact_module.h)(spinner/* default */.A, {
8777
+ static: true,
8778
+ mode: util/* default */.A.get(this.props.chatbox, 'primary_color', 'dark'),
8779
+ size: "120",
8780
+ center: true
8781
+ });
8782
+ style = 'opacity: 0 !important';
8783
+ }
8784
+ }
8369
8785
  return (0,preact_module.h)(preact_module/* Fragment */.FK, null, $loading, (0,preact_module.h)("div", {
8370
8786
  style: style,
8371
8787
  ref: ref => this.refBody = ref,
@@ -8433,10 +8849,16 @@ class Events extends common/* Com */.Mw {
8433
8849
  if (!this.props.cid) return;
8434
8850
  this.lastContentOffsetY = 0;
8435
8851
  this.setState({
8436
- loading: true
8852
+ loading: false
8437
8853
  });
8438
8854
  let events = this.props.store.listEvents(this.props.cid);
8439
8855
  if (util/* default */.A.size(events) === 0) {
8856
+ this.setState({
8857
+ loading: util/* default */.A.Date.now()
8858
+ });
8859
+ util/* default */.A.setTimeout(() => {
8860
+ this.forceUpdate();
8861
+ }, 800);
8440
8862
  let cid = this.props.cid;
8441
8863
  let {
8442
8864
  error
@@ -8452,17 +8874,11 @@ class Events extends common/* Com */.Mw {
8452
8874
  return;
8453
8875
  }
8454
8876
  }
8455
- this.setState({
8456
- loading: true
8457
- });
8458
8877
  this.props.store.fetchMoreEvents(this.props.cid);
8459
8878
  this.setState({
8460
8879
  error: false
8461
8880
  });
8462
8881
  this.scrollToBottom();
8463
- util/* default */.A.setTimeout(() => this.setState({
8464
- loading: false
8465
- }), 50);
8466
8882
  }
8467
8883
  isBottom() {
8468
8884
  let $container = this.refBody;
@@ -8477,7 +8893,7 @@ class Events extends common/* Com */.Mw {
8477
8893
  util/* default */.A.setTimeout(() => {
8478
8894
  const $div = this.refBody;
8479
8895
  if ($div) $div.scrollTop = $div.scrollHeight;
8480
- }, 200);
8896
+ }, 100);
8481
8897
  if (this.props.isShow) {
8482
8898
  if (this.props.store.browserVisibility === 'visible' && document.hasFocus()) {
8483
8899
  this.props.store.seenConvo(this.props.cid);
@@ -8488,14 +8904,19 @@ class Events extends common/* Com */.Mw {
8488
8904
  function processEvents(convo, events) {
8489
8905
  events = events.filter(event => visibleEvent(event.ev));
8490
8906
  if (events.length < 1) return;
8907
+ var lastAgentEvent;
8491
8908
  for (var i = 1; i < events.length; i++) {
8492
8909
  let curEvent = events[i];
8493
8910
  let lastEvent = events[i - 1];
8911
+ if (util/* default */.A.get(curEvent, 'ev.by.type') != 'user' && !curEvent.is_typing) {
8912
+ lastAgentEvent = curEvent;
8913
+ }
8494
8914
  if (visibleEvent(curEvent.ev)) {
8495
8915
  let elapsedSec = util/* default */.A.unixSec(curEvent.ev.created) - util/* default */.A.unixSec(lastEvent.ev.created);
8496
8916
  if (elapsedSec > 120) curEvent.show_time = true;
8497
8917
  }
8498
8918
  }
8919
+ if (lastAgentEvent) lastAgentEvent.show_time = true;
8499
8920
  for (var i = 0; i < events.length; i++) {
8500
8921
  let curEvent = events[i];
8501
8922
  if (util/* default */.A.get(curEvent, 'ev.type') === 'message_sent') {
@@ -8523,76 +8944,6 @@ function Events_isSummited(form) {
8523
8944
  let fields = util/* default */.A.get(form, 'fields') || [];
8524
8945
  return util/* default */.A.find(fields, field => !!field.answered);
8525
8946
  }
8526
- ;// ./src/chatbox/Typing.js
8527
-
8528
-
8529
-
8530
- class Typing extends common/* Com */.Mw {
8531
- constructor(props) {
8532
- super(props);
8533
- }
8534
- componentDidMount() {
8535
- this.setState({
8536
- isShow: false,
8537
- ev: {}
8538
- });
8539
- this.props.store.onConvoEvent(this, ev => {
8540
- if (util/* default */.A.convoOfEv(ev) !== this.props.cid) return;
8541
- let user = this.props.store.matchUser();
8542
- if (util/* default */.A.get(ev, 'by.id') === user.id) return;
8543
- if (util/* default */.A.get(ev, 'by.type') === 'user') return;
8544
- let oldby = util/* default */.A.get(this.state.ev, 'by.id');
8545
- if (oldby && util/* default */.A.get(ev, 'by.id') !== oldby) return;
8546
- if (util/* default */.A.get(ev, 'type') === 'message_sent') {
8547
- if (this.timer) util/* default */.A.clearTimeout(this.timer);
8548
- this.timer = null;
8549
- this.setState({
8550
- isShow: false
8551
- });
8552
- return;
8553
- }
8554
- if (util/* default */.A.get(ev, 'type') !== 'conversation_typing') return;
8555
- let ag = this.props.store.matchAgent(util/* default */.A.get(ev, 'by.id')) || {};
8556
- if (ag.type == 'agent' && !util/* default */.A.get(this.props.plugin, 'chatbox.show_agent_typing')) return;
8557
- this.setState({
8558
- ev: ev,
8559
- isShow: true
8560
- });
8561
- if (this.timer) util/* default */.A.clearTimeout(this.timer);
8562
- this.timer = util/* default */.A.setTimeout(() => {
8563
- if (util/* default */.A.convoOfEv(ev) !== this.props.cid) return;
8564
- this.timer = null;
8565
- this.setState({
8566
- isShow: false
8567
- });
8568
- }, 5000);
8569
- });
8570
- }
8571
- ShowTyping() {
8572
- this.setState({
8573
- isShow: true
8574
- });
8575
- if (this.timer) util/* default */.A.clearTimeout(this.timer);
8576
- this.timer = util/* default */.A.setTimeout(() => {
8577
- this.timer = null;
8578
- this.setState({
8579
- isShow: false
8580
- });
8581
- }, 5000);
8582
- }
8583
- render() {
8584
- let account = this.props.store.matchAccount();
8585
- var cls = this.state.isShow ? '' : 'typing--hidden';
8586
- let byid = util/* default */.A.get(this.state.ev, 'by.display_id', util/* default */.A.get(this.state.ev, 'by.id'));
8587
- let agentName = util/* default */.A.getAgentDisplayName(account, this.props.store.matchAgent(byid));
8588
- if (util/* default */.A.get(this.props.plugin, 'chatbox.hide_agent_profile')) {
8589
- agentName = util/* default */.A.get(account, 'name');
8590
- }
8591
- return (0,preact_module.h)("div", {
8592
- class: `typing ${cls}`
8593
- }, agentName, " ", this.props.t('typing'));
8594
- }
8595
- }
8596
8947
  // EXTERNAL MODULE: ./src/chatbox/releaseAnimation.js
8597
8948
  var releaseAnimation = __webpack_require__(2988);
8598
8949
  ;// ./src/chatbox/Rating.js
@@ -8891,7 +9242,6 @@ var empty = __webpack_require__(9419);
8891
9242
 
8892
9243
 
8893
9244
 
8894
-
8895
9245
  let Order = false;
8896
9246
  const LoadOrder = () => __webpack_require__.e(/* import() */ 185).then(__webpack_require__.bind(__webpack_require__, 4185));
8897
9247
 
@@ -8899,7 +9249,6 @@ const Widget_defaultAvatar = 'https://vcdn.subiz-cdn.com/file/fiqoahedjbgwclpouo
8899
9249
 
8900
9250
 
8901
9251
 
8902
-
8903
9252
  class Widget extends common/* Com */.Mw {
8904
9253
  constructor(props) {
8905
9254
  super(props);
@@ -8943,26 +9292,33 @@ class Widget extends common/* Com */.Mw {
8943
9292
  initial_by: this.props.store.matchUser().id
8944
9293
  });
8945
9294
  if (_creating != this._creating) return;
8946
- if (error) {}
9295
+ if (error) {
9296
+ this.setState({
9297
+ creating: false
9298
+ });
9299
+ return;
9300
+ }
8947
9301
  await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
8948
9302
  message
8949
9303
  });
8950
9304
  if (_creating != this._creating) return;
8951
- this.setState({
8952
- creating: false
8953
- });
8954
9305
  this.props.onGo({
8955
9306
  view: 'chat',
8956
9307
  cid: convo.id
8957
9308
  });
9309
+ this.setState({
9310
+ creating: false
9311
+ });
8958
9312
  return;
8959
9313
  }
8960
- await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
8961
- message
8962
- });
8963
- this.setState({
8964
- creating: false
8965
- });
9314
+ util/* default */.A.setTimeout(async () => {
9315
+ await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
9316
+ message
9317
+ });
9318
+ this.setState({
9319
+ creating: false
9320
+ });
9321
+ }, 1);
8966
9322
  });
8967
9323
  Widget_defineProperty(this, "onLink", (e, url) => {
8968
9324
  if (!url) return e.preventDefault();
@@ -9005,6 +9361,9 @@ class Widget extends common/* Com */.Mw {
9005
9361
  if (!this.props.store.isMobile()) this.focusInput();
9006
9362
  this.updateFormDataFields();
9007
9363
  }
9364
+ applyMessage(text) {
9365
+ this.focusInput(text);
9366
+ }
9008
9367
  componentDidUpdate(prevProp) {
9009
9368
  if (prevProp.isShow !== this.props.isShow) {
9010
9369
  if (this.props.isShow && !this.props.store.isMobile()) this.focusInput();
@@ -9018,14 +9377,14 @@ class Widget extends common/* Com */.Mw {
9018
9377
  quickReplyMessage: {}
9019
9378
  });
9020
9379
  util/* default */.A.setTimeout(() => {
9021
- this.events && this.events.focus();
9380
+ this.$events && this.$events.focus();
9022
9381
  if (!this.props.store.isMobile()) this.focusInput();
9023
9382
  }, 100);
9024
9383
  this.updateFormDataFields();
9025
9384
  }
9026
9385
  }
9027
9386
  ShowTyping() {
9028
- this.refTyping.current && this.refTyping.current.ShowTyping();
9387
+ this.$events && this.$events.ShowTyping();
9029
9388
  }
9030
9389
  shouldShowForm() {
9031
9390
  let form;
@@ -9071,19 +9430,24 @@ class Widget extends common/* Com */.Mw {
9071
9430
  let cls = 'widget-container widget-container--' + position;
9072
9431
  if (!this.props.store.isMobile() && util/* default */.A.get(accountSetting, 'window_mode') === 'full') cls += ' widget-container--full';
9073
9432
  if (!this.props.isShow) cls += ' widget-container--hide';
9433
+ let hideheader = util/* default */.A.get(accountSetting, 'header.hidden', false);
9434
+ var $header;
9435
+ if (!hideheader) {
9436
+ $header = (0,preact_module.h)(Header, {
9437
+ t: this.props.t,
9438
+ plugin: this.props.plugin,
9439
+ store: this.props.store,
9440
+ cid: this.props.cid,
9441
+ view: this.props.view,
9442
+ onClose: this.props.onClose,
9443
+ onGotoList: () => this.props.onGo({
9444
+ view: 'list'
9445
+ })
9446
+ });
9447
+ }
9074
9448
  return (0,preact_module.h)("div", {
9075
9449
  class: cls
9076
- }, (0,preact_module.h)(Header, {
9077
- t: this.props.t,
9078
- plugin: this.props.plugin,
9079
- store: this.props.store,
9080
- cid: this.props.cid,
9081
- view: this.props.view,
9082
- onClose: this.props.onClose,
9083
- onGotoList: () => this.props.onGo({
9084
- view: 'list'
9085
- })
9086
- }), $body);
9450
+ }, $header, $body);
9087
9451
  }
9088
9452
  async submitPrechatForm(form, formName) {
9089
9453
  if (this.state.submiting) return;
@@ -9592,7 +9956,7 @@ class Widget extends common/* Com */.Mw {
9592
9956
  util/* default */.A.setTimeout(() => $input && $input.blur());
9593
9957
  util/* default */.A.setTimeout(() => $input && $input.blur(), 300);
9594
9958
  }
9595
- focusInput() {
9959
+ focusInput(text) {
9596
9960
  if (this.props.store.isPreview) return;
9597
9961
  if (this.shouldShowForm()) {
9598
9962
  let firstemptykey = '';
@@ -9610,6 +9974,9 @@ class Widget extends common/* Com */.Mw {
9610
9974
  }
9611
9975
  var $input = this.msgInput.current;
9612
9976
  if (!$input) return;
9977
+ if (text != undefined && typeof text === 'string') {
9978
+ $input.applyMessage(text);
9979
+ }
9613
9980
  util/* default */.A.setTimeout(() => $input.focus());
9614
9981
  util/* default */.A.setTimeout(() => $input.focus(), 300);
9615
9982
  }
@@ -9642,6 +10009,7 @@ class Widget extends common/* Com */.Mw {
9642
10009
  ref: this.msgInput,
9643
10010
  cid: this.props.cid,
9644
10011
  onChange: this.onChangeMessageInput,
10012
+ is_loading: this.state.creating,
9645
10013
  onSend: this.sendMessage,
9646
10014
  t: this.props.t
9647
10015
  });
@@ -9665,18 +10033,13 @@ class Widget extends common/* Com */.Mw {
9665
10033
  store: this.props.store,
9666
10034
  chatbox: this.props.plugin.chatbox || {},
9667
10035
  onFormSubmit: e => this.onEventFormSubmit(e),
9668
- ref: ref => this.events = ref,
10036
+ ref: ref => this.$events = ref,
9669
10037
  cid: this.props.cid,
9670
10038
  creating: this.creating,
9671
10039
  onSend: e => this.sendMessage(e),
9672
10040
  onPostback: e => this.createPostback(e),
9673
- t: this.props.t
9674
- }), (0,preact_module.h)(Typing, {
9675
- store: this.props.store,
9676
- cid: this.props.cid,
9677
10041
  t: this.props.t,
9678
- plugin: this.props.plugin,
9679
- ref: this.refTyping
10042
+ plugin: this.props.plugin
9680
10043
  })), (0,preact_module.h)(Rating, {
9681
10044
  forceView: this.props.view,
9682
10045
  plugin: this.props.plugin,
@@ -10094,6 +10457,9 @@ class Main extends common/* Com */.Mw {
10094
10457
  cid: p.cid
10095
10458
  });
10096
10459
  }
10460
+ applyMessage(text) {
10461
+ this.refWidget.current && this.refWidget.current.applyMessage(text);
10462
+ }
10097
10463
  showGreeting() {
10098
10464
  this.refButton.current && this.refButton.current.ShowGreeting();
10099
10465
  }
@@ -10392,6 +10758,10 @@ class PluginMgr {
10392
10758
  let chatbox = this.findChatbox();
10393
10759
  if (chatbox) return chatbox.call('showGreeting');
10394
10760
  }
10761
+ applyTextToCurrentChatbox(text) {
10762
+ let chatbox = this.findChatbox();
10763
+ if (chatbox) return chatbox.call('applyMessage', text);
10764
+ }
10395
10765
  hideCurrentGreeting() {
10396
10766
  let chatbox = this.findChatbox();
10397
10767
  if (chatbox) return chatbox.call('hideGreeting');
@@ -10466,6 +10836,9 @@ class lib_Widget {
10466
10836
  await this.store.readyGate.entry();
10467
10837
  cb();
10468
10838
  }
10839
+ setAIDevMode(mode) {
10840
+ this.store.setAIDevMode(mode);
10841
+ }
10469
10842
  setTrackPageView(val) {
10470
10843
  this.store.setTrackPageview(val);
10471
10844
  }
@@ -10677,6 +11050,10 @@ class lib_Widget {
10677
11050
  if (this.pluginMgr) this.pluginMgr.destroy();
10678
11051
  this.store.destroy();
10679
11052
  }
11053
+ async applyMessage(msg) {
11054
+ await this.domGate.entry();
11055
+ this.pluginMgr.applyTextToCurrentChatbox(msg);
11056
+ }
10680
11057
  _overridePlugin(plugins) {
10681
11058
  this.store.overridePlugin(plugins);
10682
11059
  }