web-manager 3.1.16 → 3.1.18

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -44,7 +44,7 @@ npm install web-manager
44
44
  * Firebase (Firebase app, Firestore, Auth, & Messaging)
45
45
  * Lazysizes to lazyload images
46
46
  * Sentry to report errors
47
- * Tawk to implement a chatbox
47
+ * [Chatsy.ai](https://chatsy.ai) AI chatbot integration
48
48
  * Cookieconsent to comply with GDPR
49
49
 
50
50
  ## Example Setup
package/index.js CHANGED
@@ -184,7 +184,7 @@ function Manager() {
184
184
  } else if (event.target.matches('.auth-forgot-email-btn')) {
185
185
  This.auth().forgot();
186
186
  } else if (event.target.matches('#prechat-btn')) {
187
- load_tawk(This, This.properties.options);
187
+ load_chatsy(This, This.properties.options);
188
188
  } else if (event.target.matches('.auth-subscribe-notifications-btn')) {
189
189
  This.notifications().subscribe()
190
190
  }
@@ -549,12 +549,17 @@ function Manager() {
549
549
  release: ''
550
550
  }
551
551
  },
552
- tawk: {
552
+ chatsy: {
553
553
  enabled: true,
554
554
  config: {
555
+ accountId: '',
555
556
  chatId: '',
556
- widgetId: 'default',
557
- prechatColor: '#02A84E'
557
+ options: {
558
+ button: {
559
+ background: '#237afc',
560
+ text: '#ffffff',
561
+ }
562
+ },
558
563
  }
559
564
  },
560
565
  cookieconsent: {
@@ -589,21 +594,22 @@ function Manager() {
589
594
  var options_user = {};
590
595
  function eachRecursive(obj, parent) {
591
596
  parent = (!parent) ? '' : parent;
592
- for (var key in obj) {
593
- if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
594
- eachRecursive(obj[key], parent + key + '.');
595
- } else {
596
- utilities.set(options_user, parent + key, utilities.get(options_defaults, parent + key) );
597
- var t_globalItem = utilities.get(configuration, 'global.settings.' + parent + key, undefined);
598
- var t_pageItem = utilities.get(configuration, 'page.settings.' + parent + key, undefined);
599
- if (typeof t_globalItem !== 'undefined') {
600
- utilities.set(options_user, parent + key, t_globalItem);
601
- }
602
- if (typeof t_pageItem !== 'undefined') {
603
- utilities.set(options_user, parent + key, t_pageItem);
604
- }
597
+
598
+ for (var key in obj) {
599
+ if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
600
+ eachRecursive(obj[key], parent + key + '.');
601
+ } else {
602
+ utilities.set(options_user, parent + key, utilities.get(options_defaults, parent + key) );
603
+ var t_globalItem = utilities.get(configuration, 'global.settings.' + parent + key, undefined);
604
+ var t_pageItem = utilities.get(configuration, 'page.settings.' + parent + key, undefined);
605
+ if (typeof t_globalItem !== 'undefined') {
606
+ utilities.set(options_user, parent + key, t_globalItem);
607
+ }
608
+ if (typeof t_pageItem !== 'undefined') {
609
+ utilities.set(options_user, parent + key, t_pageItem);
605
610
  }
606
611
  }
612
+ }
607
613
  }
608
614
 
609
615
  eachRecursive(options_defaults);
@@ -678,9 +684,12 @@ function Manager() {
678
684
  console.error(e);
679
685
  }
680
686
 
681
- var tawkOps = options_user.libraries.tawk;
682
- if (tawkOps.enabled) {
683
- This.dom().select('#prechat-btn').css({background: tawkOps.config.prechatColor}).show();
687
+ var chatsyOps = options_user.libraries.chatsy;
688
+ if (chatsyOps.enabled) {
689
+ This.dom().select('#prechat-btn').css({
690
+ background: chatsyOps.config.options.button.background,
691
+ })
692
+ .show();
684
693
  }
685
694
 
686
695
  // load non-critical libraries
@@ -1406,24 +1415,29 @@ function Manager() {
1406
1415
  });
1407
1416
  }
1408
1417
 
1409
- var load_tawk = function(This, options) {
1418
+ var load_chatsy = function(This, options) {
1410
1419
  var dom = This.dom();
1411
1420
  return new Promise(function(resolve, reject) {
1412
- // if (typeof window.Tawk_API !== 'undefined') {
1413
- // return resolve();
1414
- // }
1415
- if (options.libraries.tawk.enabled === true) {
1416
- window.Tawk_API = window.Tawk_API || {}, window.Tawk_LoadStart = new Date();
1417
- window.Tawk_API.onLoad = function(){
1418
- dom.select('#prechat-btn').hide();
1419
- Tawk_API.maximize();
1420
- };
1421
- var tawkPath = 'libraries.tawk.config';
1422
- dom.loadScript({src: 'https://embed.tawk.to/' + utilities.get(options, tawkPath + '.chatId', '') + '/' + (utilities.get(options, tawkPath + '.widgetId') || 'default'), crossorigin: true}, function(e) {
1421
+ if (options.libraries.chatsy.enabled === true) {
1422
+ var chatsyPath = 'libraries.chatsy.config';
1423
+
1424
+ dom.loadScript({
1425
+ // src: 'https://embed.tawk.to/' + utilities.get(options, tawkPath + '.chatId', '') + '/' + (utilities.get(options, tawkPath + '.widgetId') || 'default'),
1426
+ src: 'https://app.chatsy.ai/resources/script.js',
1427
+ // src: 'http://192.168.86.248:4001/resources/script.js',
1428
+ attributes: [
1429
+ {name: 'data-account-id', value: utilities.get(options, chatsyPath + '.accountId', '')},
1430
+ {name: 'data-chat-id', value: utilities.get(options, chatsyPath + '.chatId', '')},
1431
+ ],
1432
+ crossorigin: true,
1433
+ }, function(e) {
1423
1434
  if (e) {
1424
1435
  return reject(e);
1425
1436
  }
1426
- // This.log('Loaded tawk.');
1437
+ // This.log('Loaded chatsy.');
1438
+ chatsy.open();
1439
+ dom.select('#prechat-btn').hide();
1440
+
1427
1441
  resolve();
1428
1442
  })
1429
1443
 
package/lib/dom.js CHANGED
@@ -255,7 +255,11 @@ Dom.loadScript = function(options, callback) {
255
255
  options.async = typeof options.async === 'undefined' ? false : options.async;
256
256
  options.crossorigin = typeof options.crossorigin === 'undefined' ? false : options.crossorigin;
257
257
  options.cacheBreaker = typeof options.cacheBreaker === 'undefined' ? true : options.cacheBreaker;
258
+ options.attributes = typeof options.attributes === 'undefined' ? [] : options.attributes;
258
259
 
260
+ var s = document.createElement('script');
261
+
262
+ // Set the script cache breaker
259
263
  if (options.cacheBreaker) {
260
264
  var src = options.src.split('?');
261
265
  var query = new URLSearchParams(src[1])
@@ -264,12 +268,21 @@ Dom.loadScript = function(options, callback) {
264
268
  options.src = src[0] + '?' + query.toString();
265
269
  }
266
270
 
267
- var s = document.createElement('script');
268
- s.src = options.src;
269
- s.async = options.async;
271
+ // If crossorigin is set, set the attribute
270
272
  if (options.crossorigin) {
271
- s.setAttribute('crossorigin','*');
273
+ options.attributes.push({name: 'crossorigin', value: '*'});
272
274
  }
275
+
276
+ // Set the script attributes
277
+ options.attributes
278
+ .forEach(attribute => {
279
+ s.setAttribute(attribute.name, attribute.value);
280
+ });
281
+
282
+ // Set the script source
283
+ s.async = options.async;
284
+ s.src = options.src;
285
+
273
286
  s.onload = function() {
274
287
  if (callback) { callback(); }
275
288
  return resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.16",
3
+ "version": "3.1.18",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "index.js",
6
6
  "scripts": {