@subiz/widget-v4 4.1.172 → 4.1.174

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 (40) hide show
  1. package/chat.js +18 -1
  2. package/compiled_src/chatbox/Widget.js +1 -0
  3. package/compiled_src/lib.js +3 -0
  4. package/compiled_src/store/api.js +4 -1
  5. package/compiled_src/store/store.js +8 -1
  6. package/compiled_src/util/common.js +1 -1
  7. package/dist/198c50be7a7.app.js +1 -0
  8. package/dist/{198b082f7d0.chat.html → 198c50be7a7.chat.html} +1 -1
  9. package/dist/198c50be7a7.chat.js +1 -0
  10. package/dist/{198b082f7d0.form.html → 198c50be7a7.form.html} +1 -1
  11. package/dist/198c50be7a7.form.js +1 -0
  12. package/dist/{198b082f7d0.index.html → 198c50be7a7.index.html} +1 -1
  13. package/dist/{198b082f7d0.library.html → 198c50be7a7.library.html} +1 -1
  14. package/dist/198c50be7a7.library.js +1 -0
  15. package/dist/{198b082f7d0.preview.html → 198c50be7a7.preview.html} +1 -1
  16. package/dist/198c50be7a7.preview.js +1 -0
  17. package/dist/{198b082f7d0.chat.js → 198c50be7a7.webview.js} +1 -1
  18. package/dist/HASH +1 -1
  19. package/dist/screenshoot.js +41 -16
  20. package/package.json +5 -5
  21. package/src/chatbox/Widget.js +1 -0
  22. package/src/lib.js +4 -0
  23. package/src/store/api.js +4 -1
  24. package/src/store/store.js +8 -1
  25. package/src/util/common.js +1 -1
  26. package/dist/198b082f7d0.app.js +0 -1
  27. package/dist/198b082f7d0.form.js +0 -1
  28. package/dist/198b082f7d0.library.js +0 -1
  29. package/dist/198b082f7d0.preview.js +0 -1
  30. package/dist/198b082f7d0.webview.js +0 -1
  31. /package/dist/{198b082f7d0.127.js → 198c50be7a7.127.js} +0 -0
  32. /package/dist/{198b082f7d0.132.js → 198c50be7a7.132.js} +0 -0
  33. /package/dist/{198b082f7d0.185.js → 198c50be7a7.185.js} +0 -0
  34. /package/dist/{198b082f7d0.27.js → 198c50be7a7.27.js} +0 -0
  35. /package/dist/{198b082f7d0.278.js → 198c50be7a7.278.js} +0 -0
  36. /package/dist/{198b082f7d0.339.js → 198c50be7a7.339.js} +0 -0
  37. /package/dist/{198b082f7d0.459.js → 198c50be7a7.459.js} +0 -0
  38. /package/dist/{198b082f7d0.490.js → 198c50be7a7.490.js} +0 -0
  39. /package/dist/{198b082f7d0.74.js → 198c50be7a7.74.js} +0 -0
  40. /package/dist/{198b082f7d0.997.js → 198c50be7a7.997.js} +0 -0
package/chat.js CHANGED
@@ -27,9 +27,13 @@ function runChatbox(subiz) {
27
27
 
28
28
  async function run() {
29
29
  let accid = getUrlParameter('id') || getUrlParameter('acc_id') || getUrlParameter('account_id')
30
+ let botid = getUrlParameter('bot-id')
30
31
 
31
32
  let subiz = new ApiV4(config.ApiURL, config.FileURL, config.RealtimeURL, true, false)
32
33
  window.subiz = subiz
34
+ if (botid) {
35
+ await subiz.overrideBotId(botid)
36
+ }
33
37
  subiz._overrideDeviceType('mobile')
34
38
  if (window.innerWidth > 760) {
35
39
  // table or wider screen
@@ -42,8 +46,21 @@ async function run() {
42
46
  document.querySelector('#result_text').textContent = `ERROR: ${res.error} with account id "${accid}"`
43
47
  return
44
48
  }
45
- setTimeout(() => {
49
+ setTimeout(async () => {
46
50
  subiz.showWidget()
51
+ if (botid) {
52
+ let botM = subiz.store.matchBot() || {}
53
+ let bot = botM[botid] || {}
54
+ console.log('matchbottt', botM)
55
+ subiz.startConvo({
56
+ state: 'active',
57
+ locale: 'vi-VN',
58
+ is_testing: true,
59
+ bot_version: bot.version,
60
+ bot_id: botid,
61
+ welcome_message: bot.welcome_message,
62
+ })
63
+ }
47
64
  }, 1)
48
65
  }
49
66
 
@@ -69,6 +69,7 @@ class Widget extends _common.Com {
69
69
  convo,
70
70
  error
71
71
  } = await this.props.store.startConvo({
72
+ state: 'active',
72
73
  locale: this.props.t.locale(),
73
74
  message: text,
74
75
  members: [{
@@ -69,6 +69,9 @@ class Widget {
69
69
  logout(userref) {
70
70
  return this.store.logout(userref);
71
71
  }
72
+ overrideBotId(botid) {
73
+ this.store.overrideBotId(botid);
74
+ }
72
75
  async init(param, $container) {
73
76
  param = param || {};
74
77
  let accid = param.account_id;
@@ -145,8 +145,11 @@ class _default {
145
145
  _defineProperty(this, "time", _ => ajax.setBaseUrl(this.ApiURL).withCredentials(true).setParser('json').get('/time'));
146
146
  _defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
147
147
  _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
148
- _defineProperty(this, "getAccountSetting", () => {
148
+ _defineProperty(this, "getAccountSetting", p => {
149
149
  let href = _index.default.get(document, 'location.href');
150
+ if (p && p.bot_id) {
151
+ return this.apireq.addQuery('url', href).addQuery('bot_id', p.bot_id).get(`/accounts/${this.accid}/settings`);
152
+ }
150
153
  return this.apireq.addQuery('url', href).get(`/accounts/${this.accid}/settings`);
151
154
  });
152
155
  _defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
@@ -355,6 +355,10 @@ class Store {
355
355
  await this.readyGate.entry();
356
356
  this.reconnect();
357
357
  }
358
+ async overrideBotId(botid) {
359
+ this.forceBotId = botid;
360
+ await this.readyGate.entry();
361
+ }
358
362
  async overrideChatbox(chatbox) {
359
363
  this.forceChatbox = chatbox;
360
364
  await this.readyGate.entry();
@@ -599,7 +603,9 @@ class Store {
599
603
  let fetchuser = p && p.user ? Promise.resolve({
600
604
  body: p.user
601
605
  }) : this.api.getUser();
602
- let outs = await Promise.all([fetchuser, this.api.getAccountSetting()]);
606
+ let outs = await Promise.all([fetchuser, this.api.getAccountSetting({
607
+ bot_id: this.forceBotId
608
+ })]);
603
609
  let error = _index.default.find(outs, out => out.error);
604
610
  if (error) return console.error(error);
605
611
  let set = outs[1].body;
@@ -1172,6 +1178,7 @@ class Store {
1172
1178
  src = src.replace('http://file.subiz.com/', this.FileURL);
1173
1179
  src = src.replace('https://file.mysubiz.com/', this.FileURL);
1174
1180
  src = src.replace('http://file.mysubiz.com/', this.FileURL);
1181
+ return src;
1175
1182
  return src.replace('vcdn.subiz-cdn.com', 'cdn.subiz.net');
1176
1183
  }
1177
1184
  clearBrowserData() {
@@ -285,7 +285,7 @@ XMLHttpRequest.prototype.send = function (body) {
285
285
  response: this.responseText
286
286
  });
287
287
  }
288
- old(a, b, c);
288
+ if (typeof old == 'function') old(a, b, c);
289
289
  };
290
290
  return _originalSend.apply(this, arguments);
291
291
  };