@subiz/widget-v4 4.0.63 → 4.0.67

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 (100) hide show
  1. package/assets/less/chatbox.less +6 -1
  2. package/babel.config.js +2 -4
  3. package/compiled_src/bot.js +7 -1
  4. package/compiled_src/call/call.js +15 -12
  5. package/compiled_src/chatbox/ChatButton.js +3 -1
  6. package/compiled_src/chatbox/DropdownSelect.js +75 -66
  7. package/compiled_src/chatbox/Event.js +1 -0
  8. package/compiled_src/chatbox/MessageInput.js +7 -4
  9. package/compiled_src/chatbox/Order.js +94 -90
  10. package/compiled_src/chatbox/ProductAttachments.js +40 -4
  11. package/compiled_src/chatbox/Rating.js +10 -7
  12. package/compiled_src/chatbox/Typing.js +3 -1
  13. package/compiled_src/chatbox/Widget.js +27 -23
  14. package/compiled_src/chatbox/main.js +2 -0
  15. package/compiled_src/contact/contact.js +9 -6
  16. package/compiled_src/lib.js +14 -9
  17. package/compiled_src/notif/notif.js +15 -12
  18. package/compiled_src/order/address_picker.js +71 -63
  19. package/compiled_src/order/order.js +330 -316
  20. package/compiled_src/popup/countdown.js +7 -4
  21. package/compiled_src/popup/popup.js +12 -9
  22. package/compiled_src/store/api.js +110 -80
  23. package/compiled_src/store/api_fake.js +82 -55
  24. package/compiled_src/store/store.js +194 -135
  25. package/compiled_src/util/common.js +1 -1
  26. package/dist/132.js +678 -591
  27. package/dist/178.js +174 -341
  28. package/dist/17ff367201e.132.js +1 -0
  29. package/dist/17ff367201e.178.js +1 -0
  30. package/dist/17ff367201e.213.js +1 -0
  31. package/dist/17ff367201e.335.js +1 -0
  32. package/dist/17ff367201e.362.js +1 -0
  33. package/dist/17ff367201e.441.js +1 -0
  34. package/dist/17ff367201e.605.js +1 -0
  35. package/dist/17ff367201e.678.js +1 -0
  36. package/dist/17ff367201e.782.js +1 -0
  37. package/dist/17ff367201e.app.js +1 -0
  38. package/dist/{17e757ccadd.index.html → 17ff367201e.index.html} +1 -1
  39. package/dist/{17e757ccadd.library.html → 17ff367201e.library.html} +1 -1
  40. package/dist/17ff367201e.library.js +1 -0
  41. package/dist/{17e757ccadd.preview.html → 17ff367201e.preview.html} +1 -1
  42. package/dist/17ff367201e.preview.js +1 -0
  43. package/dist/17ff367201e.screenshoot.js +1 -0
  44. package/dist/213.js +19 -13
  45. package/dist/335.js +11 -8
  46. package/dist/362.js +21 -71
  47. package/dist/441.js +2 -2
  48. package/dist/605.js +15 -12
  49. package/dist/678.js +20 -70
  50. package/dist/782.js +21 -118
  51. package/dist/HASH +1 -1
  52. package/dist/screenshoot.html +1 -1
  53. package/dist/screenshoot.js +453 -332
  54. package/package.json +14 -14
  55. package/src/bot.js +2 -1
  56. package/src/chatbox/Buttons.js +8 -8
  57. package/src/chatbox/ChatButton.js +2 -2
  58. package/src/chatbox/Event.js +1 -1
  59. package/src/chatbox/ProductAttachments.js +41 -5
  60. package/src/chatbox/Typing.js +5 -1
  61. package/src/chatbox/main.js +4 -1
  62. package/src/store/store.js +24 -11
  63. package/src/util/common.js +1 -1
  64. package/up +1 -1
  65. package/dist/0b82fa7e5c3b07b40a44.png +0 -1
  66. package/dist/0f4af006e38ee8b93633.png +0 -1
  67. package/dist/17e757ccadd.132.js +0 -1
  68. package/dist/17e757ccadd.178.js +0 -1
  69. package/dist/17e757ccadd.213.js +0 -1
  70. package/dist/17e757ccadd.335.js +0 -1
  71. package/dist/17e757ccadd.362.js +0 -1
  72. package/dist/17e757ccadd.441.js +0 -1
  73. package/dist/17e757ccadd.605.js +0 -1
  74. package/dist/17e757ccadd.678.js +0 -1
  75. package/dist/17e757ccadd.782.js +0 -1
  76. package/dist/17e757ccadd.app.js +0 -1
  77. package/dist/17e757ccadd.library.js +0 -1
  78. package/dist/17e757ccadd.preview.js +0 -1
  79. package/dist/17e757ccadd.screenshoot.js +0 -1
  80. package/dist/1ea1c6cd21d25176810c.png +0 -1
  81. package/dist/292d42404e1b03398f61.png +0 -1
  82. package/dist/312d376370831b7bea83.png +0 -1
  83. package/dist/313d1bfc1cf776d1aefe.png +0 -1
  84. package/dist/4aa58bb7a66bb44975aa.png +0 -1
  85. package/dist/56ce063bc6c81adb7322.png +0 -1
  86. package/dist/6a411166ef5cc79e0714.png +0 -1
  87. package/dist/6faf403782fefacc1649.png +0 -1
  88. package/dist/79dca33c68fab79c067f.png +0 -1
  89. package/dist/82da1578fa84f9debaeb.png +0 -1
  90. package/dist/8b8e0f0824743974b282.png +0 -1
  91. package/dist/8d551390d81e39130a3c.png +0 -1
  92. package/dist/9fc61b9479877ebdb6c7.png +0 -1
  93. package/dist/a165d31dcb3dc90f1057.png +0 -1
  94. package/dist/a98d4a5698812c4426b3.png +0 -1
  95. package/dist/c41606bf9d1b604e46d5.png +0 -1
  96. package/dist/ce1f7450ce6c1aacd330.png +0 -1
  97. package/dist/cf8c01e88f4770a6e3e5.png +0 -1
  98. package/dist/dfbcfeab1d5622a737e2.png +0 -1
  99. package/dist/e4893ed8c2f7b8329919.png +0 -1
  100. package/dist/ec2ab4eb4ef73d186186.png +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.0.63",
3
+ "version": "4.0.67",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -14,27 +14,27 @@
14
14
  "@subiz/storage": "0.0.8",
15
15
  "@subiz/wsclient": "^3.1.7",
16
16
  "cookie_js": "1.4.2",
17
- "core-js": "^3.20.3",
18
- "css-loader": "^6.5.1",
17
+ "core-js": "^3.21.1",
18
+ "css-loader": "5.2.7",
19
19
  "file-loader": "^6.2.0",
20
20
  "less": "^4.1.2",
21
21
  "less-loader": "^10.2.0",
22
- "marked": "^4.0.10",
23
- "preact": "^10.6.4"
22
+ "marked": "^4.0.12",
23
+ "preact": "^10.7.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@babel/cli": "^7.16.8",
27
- "@babel/core": "^7.16.7",
26
+ "@babel/core": "^7.17.8",
28
27
  "@babel/plugin-proposal-class-properties": "^7.16.7",
29
- "@babel/plugin-transform-react-jsx": "^7.16.7",
30
- "@babel/preset-env": "^7.16.8",
31
- "babel-loader": "^8.2.3",
28
+ "@babel/plugin-transform-react-jsx": "^7.17.3",
29
+ "@babel/preset-env": "^7.16.11",
30
+ "@babel/cli": "^7.17.5",
31
+ "babel-loader": "^8.2.4",
32
32
  "babel-plugin-syntax-jsx": "^6.18.0",
33
33
  "html-webpack-plugin": "^5.5.0",
34
- "puppeteer": "^13.0.1",
35
- "webpack": "^5.66.0",
34
+ "puppeteer": "^13.5.2",
35
+ "webpack": "^5.70.0",
36
36
  "webpack-bundle-analyzer": "^4.5.0",
37
- "webpack-cli": "^4.9.1",
38
- "webpack-dev-server": "^4.7.3"
37
+ "webpack-cli": "^4.9.2",
38
+ "webpack-dev-server": "^4.7.4"
39
39
  }
40
40
  }
package/src/bot.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import sb from './util/index.js'
2
+ import * as common from './common.js'
2
3
 
3
4
  export default function(store) {
4
5
  let botM = store.matchBot()
@@ -12,7 +13,7 @@ export default function(store) {
12
13
 
13
14
  let {error} = await store.startConvo({
14
15
  initial_by: bot.id,
15
- locale: sb.detectLang(),
16
+ locale: common.getLocale(bot, sb.detectLang()),
16
17
  state: 'active',
17
18
  members: [{type: 'bot', id: bot.id}],
18
19
  })
@@ -1,18 +1,18 @@
1
1
  import sb from '../util/index.js'
2
- import { Com } from '../common.js'
3
- import { h } from 'preact'
2
+ import {Com} from '../common.js'
3
+ import {h} from 'preact'
4
4
 
5
5
  export default class Buttons extends Com {
6
- constructor (props) {
6
+ constructor(props) {
7
7
  super(props)
8
8
  }
9
9
 
10
- render () {
10
+ render() {
11
11
  if (sb.size(this.props.buttons) === 0) return null
12
12
  var $buttons = sb.map(this.props.buttons, (button, index) => {
13
13
  if (button.type === 'call_button') {
14
14
  return (
15
- <a class="url-button-attachment" href={'tel:' + button.phone_number} key={index} title={button.title}>
15
+ <a class='url-button-attachment' href={'tel:' + button.phone_number} key={index} title={button.title}>
16
16
  {button.title}
17
17
  </a>
18
18
  )
@@ -20,7 +20,7 @@ export default class Buttons extends Com {
20
20
 
21
21
  if (button.type === 'url_button') {
22
22
  return (
23
- <a class="url-button-attachment" href={button.url} target="_blank" key={index} title={button.title}>
23
+ <a class='url-button-attachment' href={button.url} target='_blank' key={index} title={button.title}>
24
24
  {button.title || button.url}
25
25
  </a>
26
26
  )
@@ -28,7 +28,7 @@ export default class Buttons extends Com {
28
28
 
29
29
  if (button.type === 'postback_button') {
30
30
  return (
31
- <a class="url-button-attachment" href="javascript:;" onClick={_ => this.props.onSelect(button)}>
31
+ <a class='url-button-attachment' href='javascript:;' onClick={(_) => this.props.onSelect(button)}>
32
32
  {button.title}
33
33
  </a>
34
34
  )
@@ -39,6 +39,6 @@ export default class Buttons extends Com {
39
39
  return null
40
40
  })
41
41
 
42
- return <div class="button-attachments">{$buttons}</div>
42
+ return <div class='button-attachments'>{$buttons}</div>
43
43
  }
44
44
  }
@@ -122,11 +122,11 @@ export default class ChatButton extends Com {
122
122
  if (new sb.Date().getTime() - this.props.store.matchClosePreviewAt() < Ms30Mins) return
123
123
 
124
124
  let greeting = sb.get(accountSetting, 'greeting', {})
125
- if (!greeting.message || !greeting.enabled) {
125
+ let text = this.props.t.i18n(sb.get(greeting, 'greeting', {})) || greeting.message
126
+ if (!text || !greeting.enabled) {
126
127
  this.setState({previewEvent: {}})
127
128
  return
128
129
  }
129
-
130
130
  this.ShowGreeting()
131
131
  }
132
132
 
@@ -140,7 +140,7 @@ export default class Event extends Com {
140
140
  />
141
141
  <FormSubmitAttachments store={this.props.store} ev={ev} t={this.props.t} />
142
142
  <GenericTemplateAttachments store={this.props.store} ev={ev} onSelect={(e) => this.choosePostbackBtn(e)} />
143
- <ProductAttachments t={this.props.t} store={this.props.store} ev={ev} />
143
+ <ProductAttachments t={this.props.t} onPostback={(e) => this.choosePostbackBtn(e)} store={this.props.store} ev={ev} />
144
144
  <OrderAttachments t={this.props.t} store={this.props.store} ev={ev} />
145
145
  <QuickReplies store={this.props.store} ev={ev} onSelect={(e) => this.chooseQuickReply(e)} />
146
146
  </div>
@@ -22,17 +22,53 @@ export default class ProductAttachments extends Com {
22
22
  let $products = sb.map(products, (att, index) => {
23
23
  let product = att.product
24
24
 
25
- let $detailbtn = null
25
+ let $detailbtns = []
26
26
  let url = product.url || product.mobile_url
27
27
  if (this.props.store.isMobile()) url = product.mobile_url || product.url
28
- if (url)
29
- $detailbtn = (
28
+ if (url && sb.size(product.buttons) == 0)
29
+ $detailbtns.push(
30
30
  <a class='product_attachment__btn' href={url} target='_blank'>
31
31
  {this.props.t('detail')}
32
32
  <img src={require('../../assets/img/external-link.svg')} class='product_attachment__btn_external_link' />
33
- </a>
33
+ </a>,
34
34
  )
35
35
 
36
+ console.log("P", product)
37
+
38
+ if (sb.size(product.buttons) > 0) {
39
+ $detailbtns = $detailbtns.concat(
40
+ sb.map(product.buttons, (button, index) => {
41
+ if (button.type === 'call_button') {
42
+ return (
43
+ <a class='product_attachment__btn' href={'tel:' + button.phone_number} key={index} title={button.title}>
44
+ {button.title}
45
+ </a>
46
+ )
47
+ }
48
+
49
+ if (button.type === 'url_button') {
50
+ return (
51
+ <a class='product_attachment__btn' href={button.url} target='_blank' key={index} title={button.title}>
52
+ {button.title || this.props.t('detail')}{' '}
53
+ <img
54
+ src={require('../../assets/img/external-link.svg')}
55
+ class='product_attachment__btn_external_link'
56
+ />
57
+ </a>
58
+ )
59
+ }
60
+
61
+ if (button.type === 'postback_button') {
62
+ return (
63
+ <a class='product_attachment__btn' href='javascript:;' onClick={(_) => this.props.onPostback(button)}>
64
+ {button.title}
65
+ </a>
66
+ )
67
+ }
68
+ }),
69
+ )
70
+ }
71
+
36
72
  let $title = (
37
73
  <a href={url} class='product_attachment__title' target='_blank'>
38
74
  {product.name}
@@ -60,7 +96,7 @@ export default class ProductAttachments extends Com {
60
96
  {$title}
61
97
  {$subtitle}
62
98
  {$price}
63
- <div class='product_attachment__btns'>{$detailbtn}</div>
99
+ <div class='product_attachment__btns'>{$detailbtns}</div>
64
100
  </div>
65
101
  )
66
102
  })
@@ -30,6 +30,10 @@ export default class Typing extends Com {
30
30
  return
31
31
  }
32
32
 
33
+ // dont show typing of agent, some agent dont like this
34
+ let ag = this.props.store.matchAgent(ev.by.id)
35
+ if (ag.type == 'agent') return
36
+
33
37
  if (sb.get(ev, 'type') !== 'conversation_typing') return
34
38
  this.setState({ ev: ev, isShow: true })
35
39
  if (this.timer) clearTimeout(this.timer)
@@ -38,7 +42,7 @@ export default class Typing extends Com {
38
42
 
39
43
  this.timer = null
40
44
  this.setState({ isShow: false })
41
- }, 10000)
45
+ }, 5000)
42
46
  })
43
47
  }
44
48
 
@@ -160,12 +160,15 @@ export default class Main extends Com {
160
160
  }
161
161
 
162
162
  function restoreViewport() {
163
- // remove our viewport
163
+ // restore scroll attribute for background document
164
+ if (document.body && document.body.classList) document.body.classList.remove('sbz_no_scroll')
164
165
  let metatag = document.getElementById('subiz-meta-viewport')
165
166
  if (metatag) metatag.remove()
166
167
  }
167
168
 
168
169
  function modifyViewport() {
170
+ // dont allow to scroll background document
171
+ if (document.body && document.body.classList) document.body.classList.add('sbz_no_scroll')
169
172
  let metatag = document.createElement('meta')
170
173
  metatag.httpEquiv = 'X-UA-Compatible'
171
174
  metatag.name = 'viewport'
@@ -166,7 +166,7 @@ export default class Store {
166
166
  overridePlugin(plugins) {
167
167
  if (!Array.isArray(plugins)) throw 'plugins must be be an array'
168
168
  let pluginM = {}
169
- sb.map(plugins, function(plugin) {
169
+ sb.map(plugins, function (plugin) {
170
170
  pluginM[plugin.id] = plugin
171
171
  })
172
172
  this.forcePlugins = pluginM
@@ -816,6 +816,14 @@ export default class Store {
816
816
  }
817
817
  this.onWs(ret)
818
818
  sendEventToThirdParty('SUBIZ Chat', 'Sent', 'User')
819
+ // send special event if user sent the first msg
820
+ let lastMsgSent = this.kv.match('last_msg_sent')
821
+ if (!lastMsgSent) {
822
+ let dataLayer = window.dataLayer || []
823
+ dataLayer.push({event: 'SUBIZ Chat', event_action: 'Sent', event_label: 'User', first_interaction: 1})
824
+ }
825
+
826
+ this.kv.put('last_msg_sent', sb.Date.now())
819
827
  }
820
828
 
821
829
  onConvoEvent = (o, cb) => this.pubsub.on2(o, 'events', cb)
@@ -863,7 +871,9 @@ export default class Store {
863
871
  setIsOpen = (isopen) => {
864
872
  let lastisopen = this.kv.match('isopen')
865
873
  this.kv.put('isopen', isopen)
866
- if (!lastisopen && isopen) sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows')
874
+ if (!lastisopen && isopen) {
875
+ sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows')
876
+ }
867
877
  }
868
878
  closePreview = () => this.kv.put('close_preview_at', new sb.Date().getTime())
869
879
  setLastview = (view, opts) => this.kv.put('lastview', {view, opts})
@@ -961,7 +971,7 @@ export default class Store {
961
971
  let startms = sb.Date.now()
962
972
 
963
973
  // store not init
964
- if (!sb.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 30000)
974
+ if (!sb.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 120000)
965
975
 
966
976
  let {body: t, error} = await this.api.time()
967
977
  if (error) return setTimeout(() => this.loopTime(), 30000)
@@ -969,7 +979,7 @@ export default class Store {
969
979
  var serverMs = new sb.Date(t).getTime() + latences
970
980
  var localMs = sb.Date.now()
971
981
  this.timeDiff = Math.floor(serverMs - localMs)
972
- setTimeout(() => this.loopTime(), 60000)
982
+ setTimeout(() => this.loopTime(), 120000)
973
983
  }
974
984
 
975
985
  replaceFileUrl(src) {
@@ -1084,7 +1094,7 @@ function getGaClientId() {
1084
1094
  if (!hasGA()) return clientId
1085
1095
 
1086
1096
  var allTrackers = window.ga.getAll() || []
1087
- allTrackers.forEach(function(tracker) {
1097
+ allTrackers.forEach(function (tracker) {
1088
1098
  clientId = tracker.get('clientId')
1089
1099
  })
1090
1100
 
@@ -1101,7 +1111,7 @@ function getGaTrackingIds() {
1101
1111
  if (!hasGA()) return trackingIds
1102
1112
 
1103
1113
  const allTrackers = window.ga.getAll() || []
1104
- allTrackers.forEach(function(tracker) {
1114
+ allTrackers.forEach(function (tracker) {
1105
1115
  var trackingId = tracker.get('trackingId')
1106
1116
  if (trackingId) trackingIds.push(trackingId)
1107
1117
  })
@@ -1119,7 +1129,7 @@ function sendToGA(category, action, label) {
1119
1129
  if (!hasGA()) return
1120
1130
 
1121
1131
  const allTrackers = window.ga.getAll() || []
1122
- allTrackers.forEach(function(tracker) {
1132
+ allTrackers.forEach(function (tracker) {
1123
1133
  const name = tracker.get('name')
1124
1134
  window.ga(name + '.send', 'event', category, action, label)
1125
1135
  })
@@ -1129,10 +1139,12 @@ function sendEventToThirdParty(category, action, label) {
1129
1139
  document.dispatchEvent(new CustomEvent('subiz', {detail: {category, action, label}}))
1130
1140
  sendToGA(category, action, label)
1131
1141
  sendToFBPixel(category, action, label)
1142
+ let dataLayer = window.dataLayer || []
1143
+ dataLayer.push({event: category, event_action: action, event_label: label})
1132
1144
  }
1133
1145
 
1134
1146
  // from http://detectmobilebrowsers.com/
1135
- let mobileCheck = (function(a) {
1147
+ let mobileCheck = (function (a) {
1136
1148
  return (
1137
1149
  /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
1138
1150
  a,
@@ -1143,6 +1155,7 @@ let mobileCheck = (function(a) {
1143
1155
  )
1144
1156
  })(navigator.userAgent || navigator.vendor || window.opera)
1145
1157
 
1146
- let tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
1147
- navigator.userAgent,
1148
- )
1158
+ let tabletCheck =
1159
+ /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
1160
+ navigator.userAgent,
1161
+ )
@@ -326,7 +326,7 @@ export function isURL(url) {
326
326
  }
327
327
 
328
328
  export function isNumber(num) {
329
- var reg = /^\d+$/
329
+ var re = /^\d+$/
330
330
  return re.test(String(num))
331
331
  }
332
332
 
package/up CHANGED
@@ -38,6 +38,6 @@ sleep 5
38
38
 
39
39
  echo "Remove cloudfare cache"
40
40
  # PURGE CLOUD FLARE CACHE
41
- curl -X POST "https://api.cloudflare.com/client/v4/zones/cc22eff135a40705ebe59955b450217d/purge_cache" -H "X-Auth-Email: thanhpham@vietnambiz.com" -H "X-Auth-Key: $(cat ~/.cloudflare)" -H "Content-Type: application/javascript"
41
+ curl -X POST "https://api.cloudflare.com/client/v4/zones/e8f5c860cbbc130dd389313324a6c35e/purge_cache" -H "X-Auth-Email: thanhpham@vietnambiz.com" -H "X-Auth-Key: $(cat ~/.cloudflare)"
42
42
 
43
43
  echo "Success. $(cat dist/HASH)"
@@ -1 +0,0 @@
1
- module.exports = __webpack_public_path__ + "assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png";
@@ -1 +0,0 @@
1
- module.exports = __webpack_public_path__ + "assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png";