@subiz/widget-v4 4.0.88 → 4.0.89

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 (36) hide show
  1. package/assets/less/chatbox.less +2 -0
  2. package/compiled_src/chatbox/Event.js +1 -1
  3. package/compiled_src/chatbox/Widget.js +55 -6
  4. package/compiled_src/util/common.js +1 -1
  5. package/dist/132.js +52 -7
  6. package/dist/178.js +1 -1
  7. package/dist/1833a09e682.132.js +1 -0
  8. package/dist/1833a09e682.178.js +1 -0
  9. package/dist/{182ee177a49.213.js → 1833a09e682.213.js} +0 -0
  10. package/dist/{182ee177a49.335.js → 1833a09e682.335.js} +0 -0
  11. package/dist/{182ee177a49.362.js → 1833a09e682.362.js} +0 -0
  12. package/dist/1833a09e682.441.js +1 -0
  13. package/dist/{182ee177a49.605.js → 1833a09e682.605.js} +0 -0
  14. package/dist/{182ee177a49.678.js → 1833a09e682.678.js} +0 -0
  15. package/dist/{182ee177a49.782.js → 1833a09e682.782.js} +0 -0
  16. package/dist/1833a09e682.app.js +1 -0
  17. package/dist/{182ee177a49.index.html → 1833a09e682.index.html} +1 -1
  18. package/dist/{182ee177a49.library.html → 1833a09e682.library.html} +1 -1
  19. package/dist/1833a09e682.library.js +1 -0
  20. package/dist/{182ee177a49.preview.html → 1833a09e682.preview.html} +1 -1
  21. package/dist/1833a09e682.preview.js +1 -0
  22. package/dist/1833a09e682.screenshoot.js +1 -0
  23. package/dist/441.js +52 -45
  24. package/dist/HASH +1 -1
  25. package/dist/screenshoot.html +1 -1
  26. package/dist/screenshoot.js +1 -1
  27. package/package.json +8 -8
  28. package/src/chatbox/Widget.js +52 -3
  29. package/src/util/common.js +1 -1
  30. package/dist/182ee177a49.132.js +0 -1
  31. package/dist/182ee177a49.178.js +0 -1
  32. package/dist/182ee177a49.441.js +0 -1
  33. package/dist/182ee177a49.app.js +0 -1
  34. package/dist/182ee177a49.library.js +0 -1
  35. package/dist/182ee177a49.preview.js +0 -1
  36. package/dist/182ee177a49.screenshoot.js +0 -1
@@ -97,6 +97,8 @@ body div#sbz92 {
97
97
  }
98
98
 
99
99
  img {
100
+ overflow: hidden;
101
+ flex-shrink: 0;
100
102
  background-repeat: no-repeat;
101
103
  background-position: center;
102
104
  background-size: 100% 100%;
@@ -128,7 +128,7 @@ 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')) {
131
+ if (_index.default.get(this.props, 'chatbox.hide_agent_profile')) {
132
132
  return (0, _preact.h)("div", {
133
133
  class: "message-sender"
134
134
  }, (0, _preact.h)("img", {
@@ -54,6 +54,14 @@ class Widget extends _common.Com {
54
54
  _defineProperty(this, "msgInput", (0, _preact.createRef)());
55
55
 
56
56
  _defineProperty(this, "sendMessage", async message => {
57
+ let hasPostback = _index.default.find(message.attachments, att => att.type === 'postback');
58
+
59
+ if (this.isFormRequired() && hasPostback) {
60
+ this.onStartConvoClick();
61
+ this.fillQuickReplyToQuestion(message);
62
+ return;
63
+ }
64
+
57
65
  let text = message.text;
58
66
 
59
67
  if (!this.props.cid) {
@@ -115,7 +123,8 @@ class Widget extends _common.Com {
115
123
  clickedJoin: false,
116
124
  formData: {},
117
125
  showOrder: false,
118
- order_id: ''
126
+ order_id: '',
127
+ quickReplyMessage: ''
119
128
  });
120
129
  this.props.store.onUpdate(this, _ => this.forceUpdate());
121
130
  }
@@ -133,7 +142,8 @@ class Widget extends _common.Com {
133
142
  if (prevProp.cid !== this.props.cid) {
134
143
  this.closeOrder();
135
144
  this.setState({
136
- clickedJoin: false
145
+ clickedJoin: false,
146
+ quickReplyMessage: ''
137
147
  });
138
148
  setTimeout(() => {
139
149
  this.events && this.events.focus();
@@ -145,6 +155,15 @@ class Widget extends _common.Com {
145
155
  }
146
156
 
147
157
  shouldShowForm() {
158
+ let form;
159
+ let accountSetting = this.props.plugin.chatbox || {};
160
+ let acc = this.props.store.matchAccount() || {};
161
+ if (_index.default.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form;
162
+
163
+ let offlineEnabled = _index.default.get(accountSetting, 'offline_form.enabled');
164
+
165
+ if (this.isOffline(acc, accountSetting) && offlineEnabled) form = accountSetting.offline_form;
166
+ if (!this.hasSentMessage(this.props.cid) && form && (_index.default.size(form.groups) || form.group_required)) return true;
148
167
  let formRequired = this.isFormRequired();
149
168
  return formRequired && !this.props.cid || formRequired && this.props.cid && this.state.clickedJoin;
150
169
  }
@@ -263,6 +282,9 @@ class Widget extends _common.Com {
263
282
  }]
264
283
  }
265
284
  });
285
+ this.setState({
286
+ quickReplyMessage: ''
287
+ });
266
288
  if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid);
267
289
  return;
268
290
  }
@@ -308,7 +330,8 @@ class Widget extends _common.Com {
308
330
  });
309
331
  this.setState({
310
332
  creating: false,
311
- clickedJoin: false
333
+ clickedJoin: false,
334
+ quickReplyMessage: ''
312
335
  });
313
336
  if (!this.props.store.isMobile()) this.focusInput();
314
337
  }
@@ -319,7 +342,8 @@ class Widget extends _common.Com {
319
342
  key: 'question',
320
343
  is_required: true,
321
344
  label: this.props.t.i18n(_index.default.get(form, `i18n_question_label`, {})) || form.question_label,
322
- type: 'text'
345
+ type: 'text',
346
+ value: this.state.quickReplyMessage
323
347
  };
324
348
  this.setState({
325
349
  formData
@@ -381,6 +405,7 @@ class Widget extends _common.Com {
381
405
  if (_index.default.size(this.state.formData) === 0) return null;
382
406
 
383
407
  let $fields = _index.default.map(this.state.formData, (field, key) => {
408
+ if (this.state.quickReplyMessage && key === 'question') return null;
384
409
  let $field = null;
385
410
  var errclass = field.error ? 'input--error' : '';
386
411
 
@@ -648,6 +673,19 @@ class Widget extends _common.Com {
648
673
  this.focusInput();
649
674
  }
650
675
 
676
+ fillQuickReplyToQuestion(message) {
677
+ let formData = this.state.formData;
678
+
679
+ if (formData) {
680
+ _index.default.set(formData, 'question.value', message.text);
681
+ }
682
+
683
+ this.setState({
684
+ formData,
685
+ quickReplyMessage: message.text
686
+ });
687
+ }
688
+
651
689
  createPostback(postback) {
652
690
  this.props.store.createPostback(this.props.cid, postback);
653
691
  }
@@ -718,7 +756,8 @@ class Widget extends _common.Com {
718
756
  cid: ''
719
757
  });
720
758
  this.setState({
721
- clickedJoin: true
759
+ clickedJoin: true,
760
+ quickReplyMessage: ''
722
761
  });
723
762
  }
724
763
 
@@ -745,7 +784,6 @@ class Widget extends _common.Com {
745
784
  let formData = this.fillForm(form);
746
785
  let convo = this.props.store.matchConvo(this.props.cid) || {};
747
786
  if (convo.state === 'ended') return true;
748
- if (this.userHasSent(this.props.cid)) return false;
749
787
  if (convo.state && convo.state !== 'pending') delete formData.group;
750
788
  return !!_index.default.find(formData, field => field.value == null || field.value === '');
751
789
  }
@@ -868,6 +906,17 @@ class Widget extends _common.Com {
868
906
  return joined;
869
907
  }
870
908
 
909
+ hasSentMessage(cid) {
910
+ let convo = this.props.store.matchConvo(cid) || {};
911
+
912
+ let joined = _index.default.find(convo.members, mem => {
913
+ if (mem.type === 'bot') return true;
914
+ return mem.last_sent;
915
+ });
916
+
917
+ return joined;
918
+ }
919
+
871
920
  isOffline(acc, accSetting) {
872
921
  let enableWhen = _index.default.get(accSetting, 'offline_form.enable_when');
873
922
 
@@ -894,7 +894,7 @@ function checkRunConditions(freq, conds, lastrun, store) {
894
894
 
895
895
  case 'source':
896
896
  if (size(cond.sources) > 0) {
897
- let source = store.matchTrafficSource();
897
+ let source = store.matchTrafficSource() || 'direct';
898
898
  if (!find(cond.sources, src => norm(src) === norm(source))) return false;
899
899
  }
900
900
 
package/dist/132.js CHANGED
@@ -2756,7 +2756,7 @@ class Event extends common/* Com */.up {
2756
2756
 
2757
2757
  var uri = acc.logo_url || __webpack_require__(9895);
2758
2758
 
2759
- if (true) {
2759
+ if (util/* default.get */.Z.get(this.props, 'chatbox.hide_agent_profile')) {
2760
2760
  return (0,preact_module.h)("div", {
2761
2761
  class: "message-sender"
2762
2762
  }, (0,preact_module.h)("img", {
@@ -5668,6 +5668,14 @@ class Widget extends common/* Com */.up {
5668
5668
  Widget_defineProperty(this, "msgInput", (0,preact_module/* createRef */.Vf)());
5669
5669
 
5670
5670
  Widget_defineProperty(this, "sendMessage", async message => {
5671
+ let hasPostback = util/* default.find */.Z.find(message.attachments, att => att.type === 'postback');
5672
+
5673
+ if (this.isFormRequired() && hasPostback) {
5674
+ this.onStartConvoClick();
5675
+ this.fillQuickReplyToQuestion(message);
5676
+ return;
5677
+ }
5678
+
5671
5679
  let text = message.text;
5672
5680
 
5673
5681
  if (!this.props.cid) {
@@ -5729,7 +5737,8 @@ class Widget extends common/* Com */.up {
5729
5737
  clickedJoin: false,
5730
5738
  formData: {},
5731
5739
  showOrder: false,
5732
- order_id: ''
5740
+ order_id: '',
5741
+ quickReplyMessage: ''
5733
5742
  });
5734
5743
  this.props.store.onUpdate(this, _ => this.forceUpdate());
5735
5744
  }
@@ -5747,7 +5756,8 @@ class Widget extends common/* Com */.up {
5747
5756
  if (prevProp.cid !== this.props.cid) {
5748
5757
  this.closeOrder();
5749
5758
  this.setState({
5750
- clickedJoin: false
5759
+ clickedJoin: false,
5760
+ quickReplyMessage: ''
5751
5761
  });
5752
5762
  setTimeout(() => {
5753
5763
  this.events && this.events.focus();
@@ -5759,6 +5769,13 @@ class Widget extends common/* Com */.up {
5759
5769
  }
5760
5770
 
5761
5771
  shouldShowForm() {
5772
+ let form;
5773
+ let accountSetting = this.props.plugin.chatbox || {};
5774
+ let acc = this.props.store.matchAccount() || {};
5775
+ if (util/* default.get */.Z.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form;
5776
+ let offlineEnabled = util/* default.get */.Z.get(accountSetting, 'offline_form.enabled');
5777
+ if (this.isOffline(acc, accountSetting) && offlineEnabled) form = accountSetting.offline_form;
5778
+ if (!this.hasSentMessage(this.props.cid) && form && (util/* default.size */.Z.size(form.groups) || form.group_required)) return true;
5762
5779
  let formRequired = this.isFormRequired();
5763
5780
  return formRequired && !this.props.cid || formRequired && this.props.cid && this.state.clickedJoin;
5764
5781
  }
@@ -5866,6 +5883,9 @@ class Widget extends common/* Com */.up {
5866
5883
  }]
5867
5884
  }
5868
5885
  });
5886
+ this.setState({
5887
+ quickReplyMessage: ''
5888
+ });
5869
5889
  if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid);
5870
5890
  return;
5871
5891
  }
@@ -5911,7 +5931,8 @@ class Widget extends common/* Com */.up {
5911
5931
  });
5912
5932
  this.setState({
5913
5933
  creating: false,
5914
- clickedJoin: false
5934
+ clickedJoin: false,
5935
+ quickReplyMessage: ''
5915
5936
  });
5916
5937
  if (!this.props.store.isMobile()) this.focusInput();
5917
5938
  }
@@ -5922,7 +5943,8 @@ class Widget extends common/* Com */.up {
5922
5943
  key: 'question',
5923
5944
  is_required: true,
5924
5945
  label: this.props.t.i18n(util/* default.get */.Z.get(form, `i18n_question_label`, {})) || form.question_label,
5925
- type: 'text'
5946
+ type: 'text',
5947
+ value: this.state.quickReplyMessage
5926
5948
  };
5927
5949
  this.setState({
5928
5950
  formData
@@ -5975,6 +5997,7 @@ class Widget extends common/* Com */.up {
5975
5997
  renderFields() {
5976
5998
  if (util/* default.size */.Z.size(this.state.formData) === 0) return null;
5977
5999
  let $fields = util/* default.map */.Z.map(this.state.formData, (field, key) => {
6000
+ if (this.state.quickReplyMessage && key === 'question') return null;
5978
6001
  let $field = null;
5979
6002
  var errclass = field.error ? 'input--error' : '';
5980
6003
 
@@ -6231,6 +6254,19 @@ class Widget extends common/* Com */.up {
6231
6254
  this.focusInput();
6232
6255
  }
6233
6256
 
6257
+ fillQuickReplyToQuestion(message) {
6258
+ let formData = this.state.formData;
6259
+
6260
+ if (formData) {
6261
+ util/* default.set */.Z.set(formData, 'question.value', message.text);
6262
+ }
6263
+
6264
+ this.setState({
6265
+ formData,
6266
+ quickReplyMessage: message.text
6267
+ });
6268
+ }
6269
+
6234
6270
  createPostback(postback) {
6235
6271
  this.props.store.createPostback(this.props.cid, postback);
6236
6272
  }
@@ -6301,7 +6337,8 @@ class Widget extends common/* Com */.up {
6301
6337
  cid: ''
6302
6338
  });
6303
6339
  this.setState({
6304
- clickedJoin: true
6340
+ clickedJoin: true,
6341
+ quickReplyMessage: ''
6305
6342
  });
6306
6343
  }
6307
6344
 
@@ -6326,7 +6363,6 @@ class Widget extends common/* Com */.up {
6326
6363
  let formData = this.fillForm(form);
6327
6364
  let convo = this.props.store.matchConvo(this.props.cid) || {};
6328
6365
  if (convo.state === 'ended') return true;
6329
- if (this.userHasSent(this.props.cid)) return false;
6330
6366
  if (convo.state && convo.state !== 'pending') delete formData.group;
6331
6367
  return !!util/* default.find */.Z.find(formData, field => field.value == null || field.value === '');
6332
6368
  }
@@ -6431,6 +6467,15 @@ class Widget extends common/* Com */.up {
6431
6467
  return joined;
6432
6468
  }
6433
6469
 
6470
+ hasSentMessage(cid) {
6471
+ let convo = this.props.store.matchConvo(cid) || {};
6472
+ let joined = util/* default.find */.Z.find(convo.members, mem => {
6473
+ if (mem.type === 'bot') return true;
6474
+ return mem.last_sent;
6475
+ });
6476
+ return joined;
6477
+ }
6478
+
6434
6479
  isOffline(acc, accSetting) {
6435
6480
  let enableWhen = util/* default.get */.Z.get(accSetting, 'offline_form.enable_when');
6436
6481
  let isonline = true;