@subiz/widget-v4 4.0.86 → 4.0.87

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 (50) hide show
  1. package/.prettierrc.js +1 -1
  2. package/compiled_src/chatbox/AgentsAvatar.js +20 -3
  3. package/compiled_src/chatbox/ChatButton.js +7 -0
  4. package/compiled_src/chatbox/Event.js +12 -0
  5. package/compiled_src/chatbox/Events.js +1 -0
  6. package/compiled_src/chatbox/MessageInput.js +6 -0
  7. package/compiled_src/chatbox/Widget.js +41 -37
  8. package/compiled_src/chatbox/main.js +10 -0
  9. package/compiled_src/popup/popup.js +14 -2
  10. package/compiled_src/store/store.js +20 -34
  11. package/compiled_src/util/common.js +10 -10
  12. package/dist/{18224b3b0f8.132.js → 182ed9b853b.132.js} +0 -0
  13. package/dist/{18224b3b0f8.178.js → 182ed9b853b.178.js} +0 -0
  14. package/dist/{18224b3b0f8.213.js → 182ed9b853b.213.js} +1 -1
  15. package/dist/{18224b3b0f8.335.js → 182ed9b853b.335.js} +0 -0
  16. package/dist/{18224b3b0f8.362.js → 182ed9b853b.362.js} +1 -1
  17. package/dist/{18224b3b0f8.441.js → 182ed9b853b.441.js} +1 -1
  18. package/dist/{18224b3b0f8.605.js → 182ed9b853b.605.js} +0 -0
  19. package/dist/{18224b3b0f8.678.js → 182ed9b853b.678.js} +0 -0
  20. package/dist/{18224b3b0f8.782.js → 182ed9b853b.782.js} +1 -1
  21. package/dist/182ed9b853b.app.js +1 -0
  22. package/dist/{18224b3b0f8.index.html → 182ed9b853b.index.html} +1 -1
  23. package/dist/{18224b3b0f8.library.html → 182ed9b853b.library.html} +1 -1
  24. package/dist/182ed9b853b.library.js +1 -0
  25. package/dist/{18224b3b0f8.preview.html → 182ed9b853b.preview.html} +1 -1
  26. package/dist/182ed9b853b.preview.js +1 -0
  27. package/dist/182ed9b853b.screenshoot.js +1 -0
  28. package/dist/213.js +12 -1
  29. package/dist/362.js +1 -1
  30. package/dist/441.js +2 -1
  31. package/dist/782.js +1 -1
  32. package/dist/HASH +1 -1
  33. package/dist/screenshoot.html +1 -1
  34. package/dist/screenshoot.js +26 -44
  35. package/index.html +1 -1
  36. package/package.json +11 -11
  37. package/src/chatbox/AgentsAvatar.js +32 -10
  38. package/src/chatbox/ChatButton.js +7 -0
  39. package/src/chatbox/Event.js +23 -4
  40. package/src/chatbox/Events.js +3 -1
  41. package/src/chatbox/MessageInput.js +14 -5
  42. package/src/chatbox/Widget.js +10 -9
  43. package/src/chatbox/main.js +8 -1
  44. package/src/popup/popup.js +14 -1
  45. package/src/store/store.js +21 -32
  46. package/src/util/common.js +16 -19
  47. package/dist/18224b3b0f8.app.js +0 -1
  48. package/dist/18224b3b0f8.library.js +0 -1
  49. package/dist/18224b3b0f8.preview.js +0 -1
  50. package/dist/18224b3b0f8.screenshoot.js +0 -1
package/.prettierrc.js CHANGED
@@ -4,7 +4,7 @@ module.exports = {
4
4
  embeddedLanguageFormatting: 'auto',
5
5
  htmlWhitespaceSensitivity: 'css',
6
6
  insertPragma: false,
7
- jsxBracketSameLine: true,
7
+ //jsxBracketSameLine: true,
8
8
  jsxSingleQuote: true,
9
9
  printWidth: 120,
10
10
  proseWrap: 'preserve',
@@ -20,6 +20,26 @@ class AgentsAvatar extends _common.Com {
20
20
 
21
21
  render() {
22
22
  let accountSetting = this.props.plugin.chatbox;
23
+ let acc = this.props.store.matchAccount();
24
+ var tooltippos = this.props.tooltipPos || 'bottom';
25
+ var mode = this.props.mode || 'primary';
26
+
27
+ if (accountSetting && accountSetting.hide_agent_profile) {
28
+ return (0, _preact.h)("div", {
29
+ class: `group-avatar group-avatar--${mode}`
30
+ }, (0, _preact.h)("div", {
31
+ class: "d-inline-block pos-relative",
32
+ "data-tooltip": acc.name,
33
+ "data-tooltip-position": tooltippos
34
+ }, (0, _preact.h)("img", {
35
+ width: 35,
36
+ height: 35,
37
+ alt: "agent avatar left",
38
+ class: "avatar group-avatar--agent-left",
39
+ src: this.props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
40
+ })));
41
+ }
42
+
23
43
  let agentM = this.props.store.matchAgent('*');
24
44
 
25
45
  var agents = _index.default.map(this.props.agent_ids, id => agentM[id]);
@@ -37,9 +57,6 @@ class AgentsAvatar extends _common.Com {
37
57
  }
38
58
 
39
59
  agents = _index.default.filter(agents, ag => !!ag);
40
- let acc = this.props.store.matchAccount();
41
- var tooltippos = this.props.tooltipPos || 'bottom';
42
- var mode = this.props.mode || 'primary';
43
60
 
44
61
  if (agents.length === 0) {
45
62
  return (0, _preact.h)("div", {
@@ -214,6 +214,13 @@ class ChatButton extends _common.Com {
214
214
  position = _index.default.get(accountSetting, 'mobile_button.position') || position;
215
215
  }
216
216
 
217
+ if (accountSetting && accountSetting.hide_agent_profile) {
218
+ agent = Object.assign({}, account, {
219
+ avatar_url: account.logo_url || require('../../assets/img/image_default.png'),
220
+ fullname: account.name || this.props.t('agent')
221
+ });
222
+ }
223
+
217
224
  let cls = 'widget-preview widget-preview--' + position;
218
225
  if (!this.state.displayPreview) cls += ' widget-preview--hidden';
219
226
  var tags = this.renderMessagePreview(this.state.previewEvent, this.props.t('sent_you_a_message'));
@@ -128,6 +128,18 @@ class Event extends _common.Com {
128
128
 
129
129
  var uri = acc.logo_url || require('../../assets/img/image_default.png');
130
130
 
131
+ if (true || _index.default.get(this.props, 'chatbox.hide_agent_profile')) {
132
+ return (0, _preact.h)("div", {
133
+ class: "message-sender"
134
+ }, (0, _preact.h)("img", {
135
+ alt: "sender",
136
+ class: "message-sender-avatar",
137
+ src: this.props.store.replaceFileUrl(uri)
138
+ }), (0, _preact.h)("p", {
139
+ class: "message-sender-name"
140
+ }, acc.name));
141
+ }
142
+
131
143
  let agentM = this.props.store.matchAgent('*');
132
144
 
133
145
  if (byid !== 'system' || bytype !== 'dummy') {
@@ -68,6 +68,7 @@ class Events extends _common.Com {
68
68
  processEvents(convo, events);
69
69
 
70
70
  let $events = _index.default.map(events, ev => (0, _preact.h)(_Event.default, {
71
+ chatbox: this.props.chatbox,
71
72
  onLink: this.props.onLink,
72
73
  store: this.props.store,
73
74
  onFormSubmit: this.props.onFormSubmit,
@@ -46,6 +46,12 @@ class MessageInput extends _common.Com {
46
46
  }, 5);
47
47
  }
48
48
 
49
+ blur() {
50
+ const $input = this.refMessageInput.current;
51
+ if (!$input) return;
52
+ $input.blur();
53
+ }
54
+
49
55
  render() {
50
56
  var buttons = (0, _preact.h)("div", {
51
57
  class: "d-flex flex-row align-self-end"
@@ -51,6 +51,40 @@ class Widget extends _common.Com {
51
51
  constructor(props) {
52
52
  super(props);
53
53
 
54
+ _defineProperty(this, "msgInput", (0, _preact.createRef)());
55
+
56
+ _defineProperty(this, "sendMessage", async message => {
57
+ let text = message.text;
58
+
59
+ if (!this.props.cid) {
60
+ this.creating = true;
61
+ const {
62
+ convo,
63
+ error
64
+ } = await this.props.store.startConvo({
65
+ locale: this.props.t.locale(),
66
+ message: text,
67
+ initial_by: this.props.store.matchUser().id
68
+ });
69
+
70
+ if (error) {}
71
+
72
+ this.creating = false;
73
+ this.props.store.sendConvoEvent(convo.id, 'message_sent', {
74
+ message
75
+ });
76
+ this.props.onGo({
77
+ view: 'chat',
78
+ cid: convo.id
79
+ });
80
+ return;
81
+ }
82
+
83
+ this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
84
+ message
85
+ });
86
+ });
87
+
54
88
  _defineProperty(this, "onLink", (e, url) => {
55
89
  if (!url) return e.preventDefault();
56
90
  let noschemeurl = url.replace(/(^\w+:|^)\/\//, '');
@@ -572,7 +606,7 @@ class Widget extends _common.Com {
572
606
 
573
607
  blur() {
574
608
  if (this.props.store.isPreview) return;
575
- var $input = this.msgInput;
609
+ var $input = this.msgInput.current;
576
610
  if (!$input) return;
577
611
  setTimeout(() => $input && $input.blur());
578
612
  setTimeout(() => $input && $input.blur(), 300);
@@ -598,7 +632,7 @@ class Widget extends _common.Com {
598
632
  return;
599
633
  }
600
634
 
601
- var $input = this.msgInput;
635
+ var $input = this.msgInput.current;
602
636
  if (!$input) return;
603
637
  setTimeout(() => $input.focus());
604
638
  setTimeout(() => $input.focus(), 300);
@@ -614,38 +648,6 @@ class Widget extends _common.Com {
614
648
  this.focusInput();
615
649
  }
616
650
 
617
- async sendMessage(message) {
618
- let text = message.text;
619
-
620
- if (!this.props.cid) {
621
- this.creating = true;
622
- const {
623
- convo,
624
- error
625
- } = await this.props.store.startConvo({
626
- locale: this.props.t.locale(),
627
- message: text,
628
- initial_by: this.props.store.matchUser().id
629
- });
630
-
631
- if (error) {}
632
-
633
- this.creating = false;
634
- this.props.store.sendConvoEvent(convo.id, 'message_sent', {
635
- message
636
- });
637
- this.props.onGo({
638
- view: 'chat',
639
- cid: convo.id
640
- });
641
- return;
642
- }
643
-
644
- this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
645
- message
646
- });
647
- }
648
-
649
651
  createPostback(postback) {
650
652
  this.props.store.createPostback(this.props.cid, postback);
651
653
  }
@@ -653,9 +655,9 @@ class Widget extends _common.Com {
653
655
  renderChat() {
654
656
  let $input = (0, _preact.h)(_MessageInput.default, {
655
657
  store: this.props.store,
656
- ref: ref => this.msgInput = ref,
658
+ ref: this.msgInput,
657
659
  cid: this.props.cid,
658
- onSend: e => this.sendMessage(e),
660
+ onSend: this.sendMessage,
659
661
  t: this.props.t
660
662
  });
661
663
  let convo = this.props.store.matchConvo(this.props.cid) || {};
@@ -678,6 +680,7 @@ class Widget extends _common.Com {
678
680
  isShow: this.props.isShow,
679
681
  onLink: this.onLink,
680
682
  store: this.props.store,
683
+ chatbox: this.props.plugin.chatbox || {},
681
684
  onFormSubmit: e => this.onEventFormSubmit(e),
682
685
  ref: ref => this.events = ref,
683
686
  cid: this.props.cid,
@@ -748,6 +751,7 @@ class Widget extends _common.Com {
748
751
  }
749
752
 
750
753
  renderConvoSummary(convo) {
754
+ let accountSetting = this.props.plugin.chatbox || {};
751
755
  let agentM = this.props.store.matchAgent('*');
752
756
 
753
757
  let ags = _index.default.filter(convo.members, m => {
@@ -765,7 +769,7 @@ class Widget extends _common.Com {
765
769
 
766
770
  var name = _index.default.each(agents, ag => ag.fullname).join(', ');
767
771
 
768
- if (!name) name = this.props.store.matchAccount().name;
772
+ if (accountSetting.hide_agent_profile || !name) name = this.props.store.matchAccount().name;
769
773
  if (!name) name = this.props.t('agent');
770
774
  var $you = null;
771
775
 
@@ -142,6 +142,16 @@ class Main extends _common.Com {
142
142
  }
143
143
 
144
144
  p = p || {};
145
+
146
+ if (!p.view && !p.cid) {
147
+ let convoM = this.props.store.matchConvo('*');
148
+
149
+ let redconvo = _index.default.find(convoM, convo => !_index.default.isConvoSeen(convo, this.props.store.matchUser().id));
150
+
151
+ p.cid = _index.default.get(redconvo, 'id', _index.default.get(convoM, '0.id'));
152
+ p.view = 'chat';
153
+ }
154
+
145
155
  if (this.props.store.isMobile()) modifyViewport();
146
156
  this.setState({
147
157
  widgetConvoId: p.cid,
@@ -281,16 +281,28 @@ class Popup extends _common.Com {
281
281
  let user = _index.default.cloneDeep(this.props.store.matchUser());
282
282
 
283
283
  let is_lead = false;
284
+ let modifiedPairs = {};
284
285
 
285
286
  for (var pair of formData.entries()) {
287
+ if (modifiedPairs[pair[0]]) {
288
+ let currentValue = _index.default.get(modifiedPairs, `${pair[0]}.1`, '');
289
+
290
+ currentValue += `,${pair[1]}`;
291
+
292
+ _index.default.set(modifiedPairs, `${pair[0]}.1`, currentValue);
293
+ } else {
294
+ modifiedPairs[pair[0]] = [pair[0], pair[1]];
295
+ }
296
+ }
297
+
298
+ for (const [_, pair] of Object.entries(modifiedPairs)) {
286
299
  let page = _index.default.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`);
287
300
 
288
301
  let form = _index.default.find(page.components, com => com.type === 'form');
289
302
 
290
303
  let fields = _index.default.get(form, 'form.fields', []);
291
304
 
292
- let field = _index.default.find(fields, field => field.key === pair[0]);
293
-
305
+ let field = _index.default.find(fields, field => field.key === pair[0]) || {};
294
306
  if (!field.type) return;
295
307
  summitFields.push({
296
308
  key: pair[0],
@@ -50,8 +50,6 @@ class Store {
50
50
 
51
51
  _defineProperty(this, "suggest_addresses", keyword => this.api.suggest_address(keyword));
52
52
 
53
- _defineProperty(this, "matchSession", () => this.kv.match('session') || {});
54
-
55
53
  _defineProperty(this, "matchAccount", () => this.cache.match('account'));
56
54
 
57
55
  _defineProperty(this, "matchPaymentMethods", () => this.cache.match('payment_methods'));
@@ -145,6 +143,8 @@ class Store {
145
143
  };
146
144
  });
147
145
 
146
+ _defineProperty(this, "matchLocation", () => this.cache.match('location') || {});
147
+
148
148
  _defineProperty(this, "matchBot", () => this.cache.match('bot') || {});
149
149
 
150
150
  _defineProperty(this, "readyGate", new _index.default.Gate());
@@ -172,6 +172,8 @@ class Store {
172
172
 
173
173
  _defineProperty(this, "seenQueue", []);
174
174
 
175
+ _defineProperty(this, "matchTrafficSource", () => this.kv.match('traffic_source'));
176
+
175
177
  _defineProperty(this, "_typing", _index.default.throttle(convoid => this.api.sendTyping(convoid), 3000, {
176
178
  trailing: false
177
179
  }));
@@ -279,7 +281,7 @@ class Store {
279
281
  }
280
282
 
281
283
  isInsync(key) {
282
- return _index.default.Date.now() - (this.g_sync[key] || 0) < 300000;
284
+ return _index.default.Date.now() - (this.g_sync[key] || 0) < 600000;
283
285
  }
284
286
 
285
287
  async fetchShippingAddresses() {
@@ -562,24 +564,6 @@ class Store {
562
564
 
563
565
  if (setting.user) {
564
566
  setting.user.account_id = setting.account.id;
565
- let oldsession = this.matchSession();
566
- let session = setting.user.session;
567
-
568
- if (session) {
569
- if (session.id === oldsession.id) {
570
- session._urls = oldsession._urls;
571
- } else {}
572
- } else {
573
- session = oldsession;
574
- }
575
-
576
- session._urls = session._urls || [];
577
-
578
- session._urls.push(location.href);
579
-
580
- while (session._urls.length > 1000) session._urls.shift();
581
-
582
- this.kv.put('session', session);
583
567
  delete setting.user.session;
584
568
 
585
569
  this._setUser(setting.user);
@@ -592,6 +576,10 @@ class Store {
592
576
  delete setting.account;
593
577
  }
594
578
 
579
+ let location = _index.default.get(setting, 'location', []);
580
+
581
+ this.cache.put('location', location);
582
+
595
583
  let bots = _index.default.get(setting, 'bots', []);
596
584
 
597
585
  let botM = {};
@@ -637,7 +625,11 @@ class Store {
637
625
 
638
626
  async track() {
639
627
  let user = this.kv.match('user') || {};
640
- await this.api.sendContentView(this.device, location.href, document.title, this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
628
+ let out = await this.api.sendContentView(this.device, location.href, document.title, this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
629
+
630
+ let traffic_source = _index.default.get(out, 'body.by.device.source', '');
631
+
632
+ if (traffic_source) this.kv.put('traffic_source', traffic_source);
641
633
  this.sendPresence();
642
634
  }
643
635
 
@@ -983,12 +975,10 @@ class Store {
983
975
  }
984
976
 
985
977
  logBotRun(botid) {
986
- let session = this.matchSession();
987
978
  let log = this.kv.match('bot_run_logs') || {};
988
979
  log[botid] = {
989
980
  bot_id: botid,
990
- created: this.now(),
991
- session_id: session.id
981
+ created: this.now()
992
982
  };
993
983
  this.kv.put('bot_run_logs', log);
994
984
  }
@@ -996,11 +986,9 @@ class Store {
996
986
  sendImpression(id) {
997
987
  let user = this.kv.match('user') || {};
998
988
  let log = this.kv.match('plugin_run_logs') || {};
999
- let session = this.matchSession();
1000
989
  log[id] = {
1001
990
  web_plugin_id: id,
1002
- created: this.now(),
1003
- session_id: session.id
991
+ created: this.now()
1004
992
  };
1005
993
  this.kv.put('plugin_run_logs', log);
1006
994
  return this.api.sendImpression({
@@ -1009,8 +997,7 @@ class Store {
1009
997
  web_plugin_id: id,
1010
998
  user_id: user.id,
1011
999
  url: window.location.href,
1012
- device: this.device,
1013
- session_id: session.id
1000
+ device: this.device
1014
1001
  });
1015
1002
  }
1016
1003
 
@@ -1032,8 +1019,7 @@ class Store {
1032
1019
  url: window.location.href,
1033
1020
  device: this.device,
1034
1021
  submission,
1035
- impression_token: impressionToken,
1036
- session_id: this.matchSession().id
1022
+ impression_token: impressionToken
1037
1023
  });
1038
1024
  }
1039
1025
 
@@ -1079,7 +1065,7 @@ class Store {
1079
1065
  async loopTime() {
1080
1066
  let startms = _index.default.Date.now();
1081
1067
 
1082
- if (!_index.default.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 120000);
1068
+ if (!_index.default.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 240000);
1083
1069
  let {
1084
1070
  body: t,
1085
1071
  error
@@ -1091,7 +1077,7 @@ class Store {
1091
1077
  var localMs = _index.default.Date.now();
1092
1078
 
1093
1079
  this.timeDiff = Math.floor(serverMs - localMs);
1094
- setTimeout(() => this.loopTime(), 120000);
1080
+ setTimeout(() => this.loopTime(), 240000);
1095
1081
  }
1096
1082
 
1097
1083
  replaceFileUrl(src) {
@@ -750,10 +750,9 @@ function osName() {
750
750
  function check_frequently(freq, lastrun, store) {
751
751
  if (!lastrun) return true;
752
752
  if (op.get(freq, 'once_per_user')) return false;
753
- var session = store.matchSession() || {};
754
753
 
755
754
  if (op.get(freq, 'once_per_session')) {
756
- if (lastrun.session_id === session.id) return false;
755
+ if (sameDay(lastrun.created, Date.now())) return false;
757
756
  }
758
757
 
759
758
  if (op.get(freq, 'interval_sec')) {
@@ -766,7 +765,7 @@ function check_frequently(freq, lastrun, store) {
766
765
 
767
766
  function checkRunConditions(freq, conds, lastrun, store) {
768
767
  var acc = store.matchAccount() || {};
769
- var session = store.matchSession() || {};
768
+ var location = store.matchLocation() || {};
770
769
  if (!check_frequently(freq, lastrun, store)) return false;
771
770
 
772
771
  for (var i = 0; i < size(conds); i++) {
@@ -806,15 +805,15 @@ function checkRunConditions(freq, conds, lastrun, store) {
806
805
  if (size(cond.exclude_locations) > 0) {
807
806
  let found = find(cond.exclude_locations, loc => {
808
807
  if (loc.city_name && loc.country_code) {
809
- if (loc.city_name === session.city_name && loc.country_code === session.country_code) return true;
808
+ if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
810
809
  }
811
810
 
812
811
  if (loc.city_name && !loc.country_code) {
813
- if (loc.city_name === session.city_name) return true;
812
+ if (loc.city_name === location.city_name) return true;
814
813
  }
815
814
 
816
815
  if (!loc.city_name && loc.country_code) {
817
- if (loc.country_code === session.country_code) return true;
816
+ if (loc.country_code === location.country_code) return true;
818
817
  }
819
818
  });
820
819
  if (found) return false;
@@ -823,15 +822,15 @@ function checkRunConditions(freq, conds, lastrun, store) {
823
822
  if (size(cond.locations) > 0) {
824
823
  let found = find(cond.locations, loc => {
825
824
  if (loc.city_name && loc.country_code) {
826
- if (loc.city_name === session.city_name && loc.country_code === session.country_code) return true;
825
+ if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
827
826
  }
828
827
 
829
828
  if (loc.city_name && !loc.country_code) {
830
- if (loc.city_name === session.city_name) return true;
829
+ if (loc.city_name === location.city_name) return true;
831
830
  }
832
831
 
833
832
  if (!loc.city_name && loc.country_code) {
834
- if (loc.country_code === session.country_code) return true;
833
+ if (loc.country_code === location.country_code) return true;
835
834
  }
836
835
  });
837
836
  if (!found) return false;
@@ -895,7 +894,8 @@ function checkRunConditions(freq, conds, lastrun, store) {
895
894
 
896
895
  case 'source':
897
896
  if (size(cond.sources) > 0) {
898
- if (!find(cond.sources, src => norm(src) === norm(session.source))) return false;
897
+ let source = store.matchTrafficSource();
898
+ if (!find(cond.sources, src => norm(src) === norm(source))) return false;
899
899
  }
900
900
 
901
901
  break;
File without changes
File without changes