@textback/notification-widget 2.0.0-9450 → 2.0.1-102913

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 (113) hide show
  1. package/.eslintrc.js +291 -291
  2. package/build/index.js +6 -3
  3. package/build/sdk.js +3 -3
  4. package/package.json +11 -8
  5. package/promote_tag.sh +1 -1
  6. package/{README.md → readme.md} +569 -490
  7. package/server.js +134 -134
  8. package/src/libraries/ai.1.0.11.js +4088 -4088
  9. package/src/libraries/localization/getLocale.js +17 -0
  10. package/src/libraries/localization/locales/.tern-port +1 -0
  11. package/src/libraries/localization/locales/cs.js +23 -0
  12. package/src/libraries/localization/locales/en.js +23 -0
  13. package/src/libraries/localization/locales/index.js +9 -0
  14. package/src/libraries/localization/locales/pl.js +23 -0
  15. package/src/libraries/localization/locales/ro.js +23 -0
  16. package/src/libraries/localization/locales/ru.js +22 -0
  17. package/src/libraries/localization/locales/uk.js +23 -0
  18. package/src/libraries/localization/text.js +9 -0
  19. package/src/libraries/t.js +82 -82
  20. package/src/sdk/channels/channel.js +30 -30
  21. package/src/sdk/channels/facebook.js +13 -13
  22. package/src/sdk/channels/factory.js +3 -3
  23. package/src/sdk/channels/skype.js +12 -12
  24. package/src/sdk/channels/telegram.js +18 -13
  25. package/src/sdk/channels/viber.js +12 -12
  26. package/src/sdk/channels/vk-modal/vk-modal.html +17 -17
  27. package/src/sdk/channels/vk-modal/vk-modal.js +25 -25
  28. package/src/sdk/channels/vk-modal/vk-modal.scss +116 -116
  29. package/src/sdk/channels/vk.js +195 -173
  30. package/src/sdk/channels/whatsapp.js +20 -11
  31. package/src/sdk/channels/whatsappb.js +27 -0
  32. package/src/sdk/events/observer.js +46 -46
  33. package/src/sdk/index.js +5 -5
  34. package/src/sdk/sdk.js +67 -30
  35. package/src/sdk/utils/apiErrorHandler.js +11 -11
  36. package/src/sdk/utils/appInsights.js +88 -88
  37. package/src/sdk/utils/browserInfo.js +8 -8
  38. package/src/sdk/utils/constants.js +17 -17
  39. package/src/sdk/utils/cookies.js +67 -50
  40. package/src/sdk/utils/find.js +7 -7
  41. package/src/sdk/utils/loadConfig.js +20 -20
  42. package/src/sdk/utils/loadDeepLink.js +48 -21
  43. package/src/sdk/utils/loadScript.js +25 -25
  44. package/src/sdk/utils/loadSubscriptions.js +6 -6
  45. package/src/sdk/utils/parseQueryString.js +33 -33
  46. package/src/sdk/utils/windowHelper.js +25 -0
  47. package/src/sdk/widget/widget.js +192 -140
  48. package/src/widget/components/index.js +6 -2
  49. package/src/widget/components/tb-notification-button/facebook.js +9 -2
  50. package/src/widget/components/tb-notification-button/index.js +34 -34
  51. package/src/widget/components/tb-notification-button/styles.scss +657 -433
  52. package/src/widget/components/tb-notification-button/telegram.js +9 -2
  53. package/src/widget/components/tb-notification-button/viber.js +9 -2
  54. package/src/widget/components/tb-notification-button/vk.js +60 -47
  55. package/src/widget/components/tb-notification-button/whatsapp.js +15 -8
  56. package/src/widget/components/tb-notification-button/whatsappb.js +58 -0
  57. package/src/widget/components/tb-notification-widget/index.js +597 -353
  58. package/src/widget/components/tb-notification-widget/normalize.scss +395 -394
  59. package/src/widget/components/tb-notification-widget/styles.scss +514 -136
  60. package/src/widget/components/tb-nw-wahunter/index.js +259 -0
  61. package/src/widget/components/tb-nw-wahunter/styles.scss +471 -0
  62. package/src/widget/config.js +5 -5
  63. package/src/widget/icons/icon_chat_window.svg +1 -0
  64. package/src/widget/icons/icon_close.svg +1 -0
  65. package/src/widget/icons/icon_facebook.svg +7 -7
  66. package/src/widget/icons/icon_facebook_circle.svg +7 -9
  67. package/src/widget/icons/icon_instagram_circle.svg +95 -95
  68. package/src/widget/icons/icon_skype.svg +44 -44
  69. package/src/widget/icons/icon_skype_circle.svg +46 -46
  70. package/src/widget/icons/icon_skype_new.svg +113 -113
  71. package/src/widget/icons/icon_tg.svg +25 -25
  72. package/src/widget/icons/icon_tg_circle.svg +17 -27
  73. package/src/widget/icons/icon_viber.svg +75 -75
  74. package/src/widget/icons/icon_viber_circle.svg +67 -77
  75. package/src/widget/icons/icon_viber_new.svg +102 -102
  76. package/src/widget/icons/icon_vk.svg +14 -14
  77. package/src/widget/icons/icon_vk_circle.svg +16 -16
  78. package/src/widget/icons/icon_whatsapp.svg +147 -147
  79. package/src/widget/icons/icon_whatsapp_circle.svg +4 -123
  80. package/src/widget/icons/icon_whatsapp_hollow.svg +128 -0
  81. package/src/widget/icons/icon_whatsapp_new.svg +127 -127
  82. package/src/widget/icons/icon_whatsappb.svg +147 -0
  83. package/src/widget/icons/icon_whatsappb_circle.svg +4 -0
  84. package/src/widget/icons/icon_whatsappb_new.svg +127 -0
  85. package/src/widget/icons/paper-plane-arrow.svg +3 -0
  86. package/src/widget/icons/tb-logo.svg +21 -0
  87. package/src/widget/index.js +28 -28
  88. package/src/widget/locales/cs.js +42 -0
  89. package/src/widget/locales/en.js +42 -20
  90. package/src/widget/locales/index.js +2 -2
  91. package/src/widget/locales/pl.js +41 -19
  92. package/src/widget/locales/ro.js +41 -20
  93. package/src/widget/locales/ru.js +40 -19
  94. package/src/widget/locales/uk.js +40 -19
  95. package/src/widget/utils/cookiesEx.js +41 -41
  96. package/src/widget/utils/getLocale.js +4 -2
  97. package/src/widget/utils/stringifyAttributes.js +19 -19
  98. package/src/widget/utils/text.js +2 -1
  99. package/src/widget/utils/widgetsStorage.js +28 -28
  100. package/src/widget/widget.entry.js +3 -4
  101. package/tests/gf.html +35 -35
  102. package/tests/gf.js +21 -21
  103. package/tests/index.js +61 -61
  104. package/views/examples.ejs +7 -3
  105. package/views/sdk.html +274 -256
  106. package/webpack.common.js +72 -72
  107. package/webpack.dev.js +15 -15
  108. package/webpack.prod.js +10 -17
  109. package/build/index.js.map +0 -1
  110. package/build/sdk.js.map +0 -1
  111. package/src/widget/components/tb-notification-button/skype.js +0 -47
  112. package/src/widget/icons/text-back-badge.png +0 -0
  113. package/src/widget/locales/cz.js +0 -20
@@ -1,21 +1,48 @@
1
- import apiErrorHandler from './apiErrorHandler.js';
2
-
3
- const cache = {};
4
-
5
- export default function loadDeepLink(apiPath, options = {}) {
6
- const body = JSON.stringify(options);
7
-
8
- if (cache[body]) {
9
- return cache[body];
10
- }
11
-
12
- cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, {
13
- method: 'POST',
14
- headers: {
15
- 'Content-Type': 'application/json'
16
- },
17
- body
18
- }).then(apiErrorHandler);
19
-
20
- return cache[body];
21
- };
1
+ 'use strict';
2
+
3
+ import apiErrorHandler from './apiErrorHandler.js';
4
+
5
+ const cache = {};
6
+
7
+ export const deeplinkUpdater = (apiPath, deeplink) => {
8
+ let _promises = [];
9
+
10
+ return data => {
11
+ Promise.all(_promises).then(() => {
12
+ let _data = JSON.stringify({
13
+ id: deeplink,
14
+ insecureContext: { data: data }
15
+ });
16
+
17
+ let _promise = fetch(
18
+ `${apiPath}/endUserNotifications/deepLinks`,
19
+ {
20
+ method: 'PATCH',
21
+ body: _data
22
+ }
23
+ );
24
+
25
+ _promises.push(_promise);
26
+
27
+ return _promises;
28
+ });
29
+ };
30
+ };
31
+
32
+ export default function loadDeepLink(apiPath, options = {}) {
33
+ const body = JSON.stringify(options);
34
+
35
+ if (cache[body]) {
36
+ return cache[body];
37
+ }
38
+
39
+ cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, {
40
+ method: 'POST',
41
+ headers: {
42
+ 'Content-Type': 'application/json'
43
+ },
44
+ body
45
+ }).then(apiErrorHandler);
46
+
47
+ return cache[body];
48
+ };
@@ -1,26 +1,26 @@
1
- const cache = {};
2
-
3
- export default function loadScript(url) {
4
- if (cache[url]){
5
- return cache[url];
6
- }
7
-
8
- cache[url] = new Promise((resolve, reject) => {
9
- let ready = false;
10
- const scriptElement = document.createElement("script");
11
-
12
- scriptElement.type = "text/javascript";
13
- scriptElement.src = url;
14
- scriptElement.async = true;
15
- scriptElement.onload = scriptElement.onreadystatechange = function() {
16
- if (!ready && (!this.readyState || this.readyState == "complete")) {
17
- ready = true;
18
- resolve();
19
- }
20
- };
21
- scriptElement.onerror = scriptElement.onabort = reject;
22
- document.head.appendChild(scriptElement);
23
- });
24
-
25
- return cache[url];
1
+ const cache = {};
2
+
3
+ export default function loadScript(url) {
4
+ if (cache[url]){
5
+ return cache[url];
6
+ }
7
+
8
+ cache[url] = new Promise((resolve, reject) => {
9
+ let ready = false;
10
+ const scriptElement = document.createElement("script");
11
+
12
+ scriptElement.type = "text/javascript";
13
+ scriptElement.src = url;
14
+ scriptElement.async = true;
15
+ scriptElement.onload = scriptElement.onreadystatechange = function() {
16
+ if (!ready && (!this.readyState || this.readyState == "complete")) {
17
+ ready = true;
18
+ resolve();
19
+ }
20
+ };
21
+ scriptElement.onerror = scriptElement.onabort = reject;
22
+ document.head.appendChild(scriptElement);
23
+ });
24
+
25
+ return cache[url];
26
26
  }
@@ -1,6 +1,6 @@
1
- import apiErrorHandler from './apiErrorHandler.js';
2
-
3
- export default function loadSubscriptions(uuid, widgetId, apiPath){
4
- const subscribedUsers = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}/subscribedUsers/${uuid}`).then(apiErrorHandler);
5
- return subscribedUsers;
6
- }
1
+ import apiErrorHandler from './apiErrorHandler.js';
2
+
3
+ export default function loadSubscriptions(uuid, widgetId, apiPath){
4
+ const subscribedUsers = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}/subscribedUsers/${uuid}`).then(apiErrorHandler);
5
+ return subscribedUsers;
6
+ }
@@ -1,34 +1,34 @@
1
- function parseQueryString(query) {
2
- const vars = query.split('&'),
3
- queryString = {};
4
-
5
- if (query.length > 0) {
6
- for (var i = 0; i < vars.length; i++) {
7
- const pair = vars[i].split('='),
8
- key = decodeURIComponent(pair[0]),
9
- value = decodeURIComponent(pair[1]);
10
-
11
- if (!key)
12
- continue;
13
-
14
- switch ( typeof queryString[key] ) {
15
- // If first entry with this name
16
- case 'undefined':
17
- queryString[key] = value;
18
- break;
19
- // If second entry with this name
20
- case 'string': {
21
- const arr = [ queryString[key], value ];
22
- queryString[ key ] = arr;
23
- break;
24
- }
25
- // If third or later entry with this name
26
- default:
27
- queryString[key].push(value);
28
- }
29
- }
30
- }
31
- return queryString;
32
- }
33
-
1
+ function parseQueryString(query) {
2
+ const vars = query.split('&'),
3
+ queryString = {};
4
+
5
+ if (query.length > 0) {
6
+ for (var i = 0; i < vars.length; i++) {
7
+ const pair = vars[i].split('='),
8
+ key = decodeURIComponent(pair[0]),
9
+ value = decodeURIComponent(pair[1]);
10
+
11
+ if (!key)
12
+ continue;
13
+
14
+ switch ( typeof queryString[key] ) {
15
+ // If first entry with this name
16
+ case 'undefined':
17
+ queryString[key] = value;
18
+ break;
19
+ // If second entry with this name
20
+ case 'string': {
21
+ const arr = [ queryString[key], value ];
22
+ queryString[ key ] = arr;
23
+ break;
24
+ }
25
+ // If third or later entry with this name
26
+ default:
27
+ queryString[key].push(value);
28
+ }
29
+ }
30
+ }
31
+ return queryString;
32
+ }
33
+
34
34
  export default parseQueryString;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ export default class WindowHelper {
4
+ constructior() {}
5
+
6
+ static get center() {
7
+ return {
8
+ x: Math.floor(window.innerWidth * 0.5),
9
+ y: Math.floor(window.innerHeight * 0.5)
10
+ };
11
+ }
12
+
13
+ static getRatio(percent) {
14
+ let r = percent / 100;
15
+ return {
16
+ width: Math.floor(window.innerWidth * r),
17
+ height: Math.floor(window.innerHeight * r)
18
+ };
19
+ }
20
+
21
+ static getRatioPropString(percent) {
22
+ let ratioObj = this.getRatio(percent);
23
+ return `width=${ratioObj.width},height=${ratioObj.height}`;
24
+ }
25
+ }
@@ -1,140 +1,192 @@
1
- import UUID from 'uuid-js';
2
- import assign from 'lodash/assign';
3
-
4
- import apiErrorHandler from '../utils/apiErrorHandler.js';
5
- import loadConfig from '../utils/loadConfig.js';
6
- import loadDeepLink from '../utils/loadDeepLink.js';
7
- import loadSubscriptions from '../utils/loadSubscriptions.js';
8
- import cookies from '../utils/cookies.js';
9
- import constants from '../utils/constants.js';
10
- import parseQueryString from '../utils/parseQueryString.js';
11
- import find from '../utils/find.js';
12
- import appInsights from '../utils/appInsights.js';
13
-
14
- import channelsFactory from '../channels/factory.js';
15
-
16
- const INITIAL_CONFIG_DEFAULTS = {
17
- apiPath: 'https://api.textback.io/api',
18
- };
19
-
20
- export default class Widget {
21
- constructor(config, sdk) {
22
- this.initialConfig = assign({}, INITIAL_CONFIG_DEFAULTS, config);
23
- this.sdk = sdk;
24
-
25
- this.config = {};
26
- this.channels = [];
27
- this.initialized = false;
28
- this.initPromise = null;
29
-
30
- this.id = this.initialConfig.widgetId;
31
- this.widgetUserId = Widget.getWidgetUserId();
32
- this.insecureContext = Widget.createInsecureContext(this.initialConfig.insecureContext);
33
- this.secureContextToken = this.initialConfig.secureContextToken;
34
- }
35
-
36
- getConfig() {
37
- return this.config;
38
- }
39
-
40
- initialize() {
41
- this.initPromise = Promise.all([
42
- this.initializeConfig(),
43
- loadSubscriptions(this.widgetUserId, this.initialConfig.widgetId, this.initialConfig.apiPath),
44
- ]).then(([config, subscriptions]) => {
45
- this.config = config.$value;
46
- this.subscriptions = subscriptions.$items;
47
-
48
- this.useVKApi = this.config.type === constants.WIDGET_TYPE_API_CALL;
49
- this.aiKey = Widget.getAiKey(config);
50
-
51
- return Promise.all([
52
- loadDeepLink(
53
- this.initialConfig.apiPath,
54
- {
55
- accountId: this.config.accountId,
56
- insecureContext: this.insecureContext,
57
- widgetId: this.config.id,
58
- secureContextToken: this.secureContextToken,
59
- user: {
60
- id: this.widgetUserId
61
- }
62
- }
63
- ),
64
- appInsights.init(this.aiKey, this.widgetUserId, this.config.accountId)
65
- ]);
66
- }).then(([deeplink, ai]) => {
67
- this.deeplink = `subscribe_${deeplink.$value.id}`;
68
- this.channels = this.config.channels.map(channel => channelsFactory.create(channel, this.deeplink, this))
69
- .filter(channel => !!channel);
70
- const channelInitPromises = this.channels.filter(channel => !!channel.initPromise)
71
- .map(channel => channel.initPromise);
72
-
73
- return Promise.all(channelInitPromises);
74
- }).then(channelPromises => {
75
- return this;
76
- }, err => {
77
- appInsights.trackWidgetEvent(this.config.id, 'Widget.initialize.error', err);
78
- return Promise.reject(err);
79
- })
80
-
81
- return this.initPromise;
82
- }
83
-
84
- initializeConfig() {
85
- let promise;
86
- if (!this.initialConfig.overrideConfig) {
87
- promise = loadConfig(this.initialConfig.widgetId, this.initialConfig.apiPath);
88
- } else {
89
- promise = Promise.resolve({ $value: this.initialConfig.overrideConfig });
90
- }
91
-
92
- return promise;
93
- }
94
-
95
- subscribe(channelCode) {
96
- const channel = find(this.getEnabledChannels(), chan => chan.channel === channelCode);
97
- if (channel) {
98
- channel.subscribe();
99
- }
100
- }
101
-
102
- getChannels() {
103
- return this.channels;
104
- }
105
-
106
- getEnabledChannels() {
107
- return this.channels.filter(channel => channel.enabled && !channel.hasError);
108
- }
109
-
110
- static getWidgetUserId() {
111
- let widgetUserId = cookies.getCookie(constants.COOKIE_WIDGET_USER_ID);
112
- if (widgetUserId === null) {
113
- let uuid = UUID.create(4);
114
- widgetUserId = uuid.hex;
115
- cookies.setCookie(constants.COOKIE_WIDGET_USER_ID, widgetUserId, constants.WIDGET_USER_ID_COOKIE_TTL);
116
- }
117
- return widgetUserId;
118
- }
119
-
120
- static createInsecureContext(insecureContext = {}) {
121
- const ctx = assign({}, insecureContext);//Object.assign({}, insecureContext);
122
- ctx.pageTitle = window.document.title;
123
- ctx.pageUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
124
- ctx.params = parseQueryString(window.location.search.substring(1));
125
- ctx.timezoneOffset = new Date().getTimezoneOffset();
126
-
127
- return ctx;
128
- }
129
-
130
- static getAiKey(config) {
131
- let aiKey = undefined;
132
- try {
133
- aiKey = config.headers.get('X-TB-AIKEY');
134
- } catch (e) { }
135
-
136
- return aiKey;
137
- }
138
-
139
-
140
- }
1
+ import UUID from 'uuid-js';
2
+ import assign from 'lodash/assign';
3
+
4
+ import apiErrorHandler from '../utils/apiErrorHandler.js';
5
+ import loadConfig from '../utils/loadConfig.js';
6
+ import loadDeepLink from '../utils/loadDeepLink.js';
7
+ import loadSubscriptions from '../utils/loadSubscriptions.js';
8
+ import cookies from '../utils/cookies.js';
9
+ import constants from '../utils/constants.js';
10
+ import parseQueryString from '../utils/parseQueryString.js';
11
+ import find from '../utils/find.js';
12
+ import appInsights from '../utils/appInsights.js';
13
+
14
+ import channelsFactory from '../channels/factory.js';
15
+
16
+ const INITIAL_CONFIG_DEFAULTS = {
17
+ apiPath: 'https://api.textback.io/api',
18
+ };
19
+
20
+ export default class Widget {
21
+ constructor(config, sdk) {
22
+ this.initialConfig = assign({}, INITIAL_CONFIG_DEFAULTS, config);
23
+ this.sdk = sdk;
24
+
25
+ this.config = {};
26
+ this.channels = [];
27
+ this.initialized = false;
28
+ this.initPromise = null;
29
+
30
+ this.id = this.initialConfig.widgetId;
31
+ this.widgetUserId = Widget.getWidgetUserId();
32
+ this.insecureContext = Widget.createInsecureContext(this.initialConfig.insecureContext);
33
+ this.secureContextToken = this.initialConfig.secureContextToken;
34
+ }
35
+
36
+ getConfig() {
37
+ return this.config;
38
+ }
39
+
40
+ initialize() {
41
+ this.initPromise = Promise.all([
42
+ this.initializeConfig(),
43
+ loadSubscriptions(this.widgetUserId, this.initialConfig.widgetId, this.initialConfig.apiPath),
44
+ ]).then(([config, subscriptions]) => {
45
+ this.config = config.$value;
46
+ this.subscriptions = subscriptions.$items;
47
+
48
+ this.useVKApi = this.config.type === constants.WIDGET_TYPE_API_CALL;
49
+ this.aiKey = Widget.getAiKey(config);
50
+
51
+ let customDeeplinkData = this.config.channels.filter(
52
+ c => c.hasOwnProperty('additionalProperties') && c.additionalProperties.hasOwnProperty('customDeeplinkValue')
53
+ ).filter(
54
+ c => c.channel === 'whatsapp' || c.channel === 'whatsappb'
55
+ ).filter(
56
+ c => c.enabled
57
+ ).map(
58
+ ({additionalProperties, channel, channelId}) => {
59
+ return {
60
+ channel: channel,
61
+ channelId: channelId,
62
+ customDeeplinkValue: additionalProperties.customDeeplinkValue
63
+ };
64
+ }
65
+ );
66
+
67
+ let deeplinkData = {
68
+ accountId: this.config.accountId,
69
+ insecureContext: this.insecureContext,
70
+ widgetId: this.config.id,
71
+ secureContextToken: this.secureContextToken,
72
+ user: {
73
+ id: this.widgetUserId
74
+ }
75
+ };
76
+
77
+ if(customDeeplinkData.length > 0) {
78
+ deeplinkData.customDeeplinkValue = customDeeplinkData;
79
+ }
80
+
81
+ return Promise.all([
82
+ loadDeepLink(
83
+ this.initialConfig.apiPath,
84
+ deeplinkData
85
+ ),
86
+ appInsights.init(this.aiKey, this.widgetUserId, this.config.accountId)
87
+ ]);
88
+ }).then(([deeplink, ai]) => {
89
+ this.deeplink = `subscribe_${deeplink.$value.id}`;
90
+ this.channels = this.config.channels.map(channel => channelsFactory.create(channel, this.deeplink, this))
91
+ .filter(channel => !!channel);
92
+
93
+ const channelInitPromises = this.channels.filter(
94
+ channel => !!channel.initPromise
95
+ ).map(
96
+ channel => channel.initPromise
97
+ );
98
+
99
+ return Promise.all(channelInitPromises);
100
+ }).then(channelPromises => {
101
+ return this;
102
+ }, err => {
103
+ appInsights.trackWidgetEvent(this.config.id, 'Widget.initialize.error', err);
104
+ return Promise.reject(err);
105
+ });
106
+
107
+ return this.initPromise;
108
+ }
109
+
110
+ initializeConfig() {
111
+ let promise;
112
+ if (!this.initialConfig.overrideConfig) {
113
+ promise = loadConfig(this.initialConfig.widgetId, this.initialConfig.apiPath);
114
+ } else {
115
+ promise = Promise.resolve({ $value: this.initialConfig.overrideConfig });
116
+ }
117
+
118
+ return promise;
119
+ }
120
+
121
+ subscribe(channelCode) {
122
+ const channel = find(this.getEnabledChannels(), chan => chan.channel === channelCode);
123
+ if (channel) {
124
+ channel.subscribe();
125
+ }
126
+ }
127
+
128
+ getChannels() {
129
+ return this.channels;
130
+ }
131
+
132
+ getEnabledChannels() {
133
+ return this.channels.filter(channel => channel.enabled && !channel.hasError);
134
+ }
135
+
136
+ runWahunter(phoneNumber) {
137
+ return fetch(`${this.initialConfig.apiPath}/wahunter`, {
138
+ method: 'POST',
139
+ headers: {
140
+ 'Content-Type': 'application/json;charset=utf-8'
141
+ },
142
+ body: JSON.stringify({
143
+ notificationWidgetId: this.initialConfig.widgetId,
144
+ phone: phoneNumber,
145
+ insecureContext: this.insecureContext,
146
+ deeplinkId: this.deeplink,
147
+ }),
148
+ }).then((resp) => {
149
+ if (resp.ok) {
150
+ cookies.setCookie(`${constants.COOKIE_NAME_PREFIX + this.id}_wahunter_was_run`, true, this.config.showWidgetSetting.showSessionLength * 60);
151
+ } else {
152
+ return Promise.reject(resp);
153
+ }
154
+ })
155
+ }
156
+
157
+ static getWidgetUserId() {
158
+ let widgetUserId = cookies.getCookie(constants.COOKIE_WIDGET_USER_ID);
159
+ if (widgetUserId === null) {
160
+ let uuid = UUID.create(4);
161
+ widgetUserId = uuid.hex;
162
+ cookies.setCookie(constants.COOKIE_WIDGET_USER_ID, widgetUserId, constants.WIDGET_USER_ID_COOKIE_TTL);
163
+ }
164
+ return widgetUserId;
165
+ }
166
+
167
+ static createInsecureContext(insecureContext = {}) {
168
+ const ctx = assign({}, insecureContext);//Object.assign({}, insecureContext);
169
+ ctx.pageTitle = window.document.title;
170
+ ctx.pageUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
171
+ ctx.params = parseQueryString(window.location.search.substring(1));
172
+ ctx.timezoneOffset = new Date().getTimezoneOffset();
173
+ ctx.cookies = cookies.getCookieObject();
174
+
175
+ const roistatVisitCookie = cookies.getCookie("roistat_visit");
176
+
177
+ if (roistatVisitCookie) {
178
+ ctx.roistatVisit = roistatVisitCookie;
179
+ }
180
+
181
+ return ctx;
182
+ }
183
+
184
+ static getAiKey(config) {
185
+ let aiKey = undefined;
186
+ try {
187
+ aiKey = config.headers.get('X-TB-AIKEY');
188
+ } catch (e) { }
189
+
190
+ return aiKey;
191
+ }
192
+ }
@@ -5,7 +5,9 @@ import getLocale from '../utils/getLocale.js';
5
5
 
6
6
  export default class Component {
7
7
  constructor(props = {}) {
8
- this.element = props.element || document.createElement(this.constructor.tagName);
8
+
9
+ if (Object.prototype.hasOwnProperty.call(props, 'parentElement')) this.element = props.parentElement;
10
+ if (!Object.prototype.hasOwnProperty.call(props, 'parentElement')) this.element = props.element || document.createElement(this.constructor.tagName);
9
11
 
10
12
  const dataset = JSON.parse(JSON.stringify(this.element.dataset || {}));
11
13
  const data = merge(JSON.parse(this.element.getAttribute('data')), dataset);
@@ -30,6 +32,8 @@ export default class Component {
30
32
  }
31
33
 
32
34
  set lang(value) {
35
+ if (!value) return;
36
+
33
37
  this.element.setAttribute('lang', value);
34
38
  }
35
39
 
@@ -45,4 +49,4 @@ export default class Component {
45
49
  static get tagName() {
46
50
  return 'div';
47
51
  }
48
- };
52
+ };
@@ -22,9 +22,16 @@ class FacebookButton extends Button {
22
22
  <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
23
23
  </a>
24
24
  <p class="tb-notification-button__tip">
25
- ${this.text('facebook_tip')}
25
+ ${this.text('facebookTip')}
26
26
  </p>
27
27
  `;
28
+ } else if(this.config.markUp.style === 'gradient') {
29
+ return `
30
+ <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
31
+ <tb-notification-button__icon>${icon}</tb-notification-button__icon>
32
+ <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
33
+ </a>
34
+ `;
28
35
  } else if (this.config.markUp.style !== 'square') {
29
36
  return `
30
37
  <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
@@ -37,7 +44,7 @@ class FacebookButton extends Button {
37
44
  <div class="tb-notification-button__inner">
38
45
  <tb-notification-button__icon>${icon}</tb-notification-button__icon>
39
46
  <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
40
- <tb-notification-button__text>${this.text('sign-facebook')}</tb-notification-button__text>
47
+ <tb-notification-button__text>${this.text('facebookExtended')}</tb-notification-button__text>
41
48
  </a>
42
49
  </div>
43
50
  `;