@subiz/widget-v4 4.1.92 → 4.1.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  function _default(store) {
13
+ if (!store.matchAutoStartBot()) return;
13
14
  let botM = store.matchBot();
14
15
  if (Object.keys(botM).length === 0) return;
15
16
  _index.default.each(botM, bot => {
@@ -285,6 +285,9 @@ class Widget {
285
285
  this.pluginMgr.showCurrentGreeting();
286
286
  }
287
287
  }
288
+ stopAutobot() {
289
+ this.store.doNotStartBot();
290
+ }
288
291
  }
289
292
  window.__sbz_WIDGET = Widget;
290
293
  var _default = exports.default = Widget;
@@ -33,14 +33,14 @@ class _default {
33
33
  });
34
34
  return this.apireq.post(`/accounts/${this.accid}/conversations`, data);
35
35
  });
36
- _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
36
+ _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.addQuery('x-referer', _index.default.get(location, 'origin', '')).post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
37
37
  _defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
38
38
  _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/receive`));
39
39
  _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/seen`));
40
40
  _defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
41
41
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
42
- _defineProperty(this, "sendEvent", data => this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
43
- _defineProperty(this, "submitForm", (form_id, page_url, device, data, user) => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, {
42
+ _defineProperty(this, "sendEvent", data => this.apireq.addQuery('shorten', true).addQuery('x-referer', _index.default.get(location, 'origin', '')).post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
43
+ _defineProperty(this, "submitForm", (form_id, page_url, device, data, user) => this.apireq.addQuery('x-referer', _index.default.get(location, 'origin', '')).post(`/accounts/${this.accid}/users/${this.uid}/events`, {
44
44
  by: {
45
45
  id: this.uid,
46
46
  device: device
@@ -217,6 +217,13 @@ class Store {
217
217
  this.sendPresence();
218
218
  });
219
219
  window.addEventListener('beforeunload', () => this.api.sendLostFocus());
220
+ this.doNotStartBot = () => {
221
+ this._donotstartbot = true;
222
+ };
223
+ this.autoStartBot = () => {
224
+ this._donotstartbot = false;
225
+ };
226
+ this.matchAutoStartBot = () => !this._donotstartbot;
220
227
  this._presenceInterval1 = _index.default.setInterval(() => {
221
228
  if (this._die) return _index.default.clearInterval(this._presenceInterval1);
222
229
  if (this.browserVisibility === 'visible' && document.hasFocus()) this.sendPresence();
package/index.html CHANGED
@@ -1,4 +1,4 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta name="description" content="Subiz preview" />
@@ -46,6 +46,30 @@
46
46
  button.id = 'test2'
47
47
  document.body.appendChild(button)
48
48
  }, 2000)
49
+
50
+ setTimeout(function () {
51
+ // only run when url contain ?bot=greeting
52
+ var urlParams = new URLSearchParams(window.location.search)
53
+ const greeting = urlParams.get('bot')
54
+ if (greeting !== 'greeting') return
55
+
56
+ let botid = '<botid>' ////////////////////// replace your bot id here. eg: bbrtilgagvnoehvpzg
57
+
58
+ // dont allow other bots to run
59
+ subiz('shrinkWidget')
60
+ subiz('stopAutobot')
61
+
62
+ subiz('waitReady', function () {
63
+ let kk = subiz('startConvo', {
64
+ initial_by: botid,
65
+ state: 'active',
66
+ members: [{id: botid, type: 'bot'}],
67
+ }).then(function (out) {
68
+ if (!out || !out.convo || !out.convo.id) return
69
+ subiz('showWidget', 'chat', out.convo.id)
70
+ })
71
+ })
72
+ })
49
73
  </script>
50
74
  </body>
51
75
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.92",
3
+ "version": "4.1.93",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
package/src/bot.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import sb from './util/index.js'
2
2
  import * as common from './common.js'
3
3
 
4
- export default function(store) {
4
+ export default function (store) {
5
+ if (!store.matchAutoStartBot()) return
5
6
  let botM = store.matchBot()
6
7
  if (Object.keys(botM).length === 0) return
7
8
  sb.each(botM, (bot) => {
package/src/lib.js CHANGED
@@ -306,6 +306,10 @@ class Widget {
306
306
  this.pluginMgr.showCurrentGreeting()
307
307
  }
308
308
  }
309
+
310
+ stopAutobot() {
311
+ this.store.doNotStartBot()
312
+ }
309
313
  }
310
314
 
311
315
  // for debugging purpose
package/src/store/api.js CHANGED
@@ -209,7 +209,10 @@ export default class {
209
209
  return this.apireq.post(`/accounts/${this.accid}/conversations`, data)
210
210
  }
211
211
 
212
- sendConvoEvent = (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev)
212
+ sendConvoEvent = (cid, ev) =>
213
+ this.apireq
214
+ .addQuery('x-referer', sb.get(location, 'origin', ''))
215
+ .post(`/accounts/${this.accid}/conversations/${cid}/events`, ev)
213
216
  createPostback = (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p)
214
217
  markAsReceived = (cid, messageId) =>
215
218
  this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/receive`)
@@ -219,23 +222,28 @@ export default class {
219
222
  getConversation = (cid) => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`)
220
223
  getLocaleContent = (locale) => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`)
221
224
  sendEvent = (data) =>
222
- this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data)
225
+ this.apireq
226
+ .addQuery('shorten', true)
227
+ .addQuery('x-referer', sb.get(location, 'origin', ''))
228
+ .post(`/accounts/${this.accid}/users/${this.uid}/events`, data)
223
229
 
224
230
  submitForm = (form_id, page_url, device, data, user) =>
225
- this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, {
226
- by: {id: this.uid, device: device},
227
- type: 'form_submitted',
228
- data: {
229
- user: user,
230
- form_submission: {
231
- user_id: this.uid,
232
- form_id: form_id,
233
- page_url: page_url,
234
- submitted_at: sb.Date.now(),
235
- values: data,
231
+ this.apireq
232
+ .addQuery('x-referer', sb.get(location, 'origin', ''))
233
+ .post(`/accounts/${this.accid}/users/${this.uid}/events`, {
234
+ by: {id: this.uid, device: device},
235
+ type: 'form_submitted',
236
+ data: {
237
+ user: user,
238
+ form_submission: {
239
+ user_id: this.uid,
240
+ form_id: form_id,
241
+ page_url: page_url,
242
+ submitted_at: sb.Date.now(),
243
+ values: data,
244
+ },
236
245
  },
237
- },
238
- })
246
+ })
239
247
 
240
248
  sendTyping = (cid) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`)
241
249
 
@@ -69,6 +69,16 @@ export default class Store {
69
69
  })
70
70
  window.addEventListener('beforeunload', () => this.api.sendLostFocus())
71
71
 
72
+ this.doNotStartBot = () => {
73
+ this._donotstartbot = true
74
+ }
75
+
76
+ this.autoStartBot = () => {
77
+ this._donotstartbot = false
78
+ }
79
+
80
+ this.matchAutoStartBot = () => !this._donotstartbot
81
+
72
82
  // faster send rate when has focus
73
83
  this._presenceInterval1 = sb.setInterval(() => {
74
84
  if (this._die) return sb.clearInterval(this._presenceInterval1)