@textback/notification-widget 2.0.0 → 2.0.1-102913

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. package/.eslintrc.js +291 -291
  2. package/build/index.js +12 -0
  3. package/build/sdk.js +9 -0
  4. package/package.json +70 -68
  5. package/promote_tag.sh +1 -1
  6. package/readme.md +569 -490
  7. package/server.js +8 -4
  8. package/src/libraries/ai.1.0.11.js +4088 -4088
  9. package/src/libraries/localization/locales/cs.js +14 -12
  10. package/src/libraries/localization/locales/en.js +14 -12
  11. package/src/libraries/localization/locales/index.js +8 -8
  12. package/src/libraries/localization/locales/pl.js +14 -12
  13. package/src/libraries/localization/locales/ro.js +14 -12
  14. package/src/libraries/localization/locales/ru.js +13 -12
  15. package/src/libraries/localization/locales/uk.js +14 -12
  16. package/src/libraries/localization/text.js +9 -9
  17. package/src/libraries/t.js +82 -82
  18. package/src/sdk/channels/channel.js +30 -30
  19. package/src/sdk/channels/facebook.js +13 -13
  20. package/src/sdk/channels/factory.js +3 -3
  21. package/src/sdk/channels/skype.js +12 -12
  22. package/src/sdk/channels/telegram.js +18 -18
  23. package/src/sdk/channels/viber.js +12 -12
  24. package/src/sdk/channels/vk-modal/vk-modal.html +17 -17
  25. package/src/sdk/channels/vk-modal/vk-modal.js +25 -25
  26. package/src/sdk/channels/vk-modal/vk-modal.scss +116 -116
  27. package/src/sdk/channels/vk.js +195 -184
  28. package/src/sdk/channels/whatsapp.js +16 -10
  29. package/src/sdk/channels/whatsappb.js +27 -0
  30. package/src/sdk/events/observer.js +46 -46
  31. package/src/sdk/index.js +5 -5
  32. package/src/sdk/sdk.js +67 -30
  33. package/src/sdk/utils/apiErrorHandler.js +11 -11
  34. package/src/sdk/utils/appInsights.js +88 -88
  35. package/src/sdk/utils/browserInfo.js +8 -8
  36. package/src/sdk/utils/constants.js +17 -17
  37. package/src/sdk/utils/cookies.js +67 -50
  38. package/src/sdk/utils/find.js +7 -7
  39. package/src/sdk/utils/loadConfig.js +20 -20
  40. package/src/sdk/utils/loadDeepLink.js +48 -21
  41. package/src/sdk/utils/loadScript.js +25 -25
  42. package/src/sdk/utils/loadSubscriptions.js +6 -6
  43. package/src/sdk/utils/parseQueryString.js +33 -33
  44. package/src/sdk/utils/windowHelper.js +25 -25
  45. package/src/sdk/widget/widget.js +192 -140
  46. package/src/widget/components/index.js +6 -2
  47. package/src/widget/components/tb-notification-button/facebook.js +9 -2
  48. package/src/widget/components/tb-notification-button/index.js +34 -34
  49. package/src/widget/components/tb-notification-button/styles.scss +657 -433
  50. package/src/widget/components/tb-notification-button/telegram.js +9 -2
  51. package/src/widget/components/tb-notification-button/viber.js +9 -2
  52. package/src/widget/components/tb-notification-button/vk.js +59 -50
  53. package/src/widget/components/tb-notification-button/whatsapp.js +15 -8
  54. package/src/widget/components/tb-notification-button/whatsappb.js +58 -0
  55. package/src/widget/components/tb-notification-widget/index.js +589 -384
  56. package/src/widget/components/tb-notification-widget/normalize.scss +395 -394
  57. package/src/widget/components/tb-notification-widget/styles.scss +502 -139
  58. package/src/widget/components/tb-nw-wahunter/index.js +259 -0
  59. package/src/widget/components/tb-nw-wahunter/styles.scss +471 -0
  60. package/src/widget/config.js +5 -5
  61. package/src/widget/icons/icon_chat_window.svg +1 -0
  62. package/src/widget/icons/icon_close.svg +1 -0
  63. package/src/widget/icons/icon_facebook.svg +7 -7
  64. package/src/widget/icons/icon_facebook_circle.svg +7 -9
  65. package/src/widget/icons/icon_instagram_circle.svg +95 -95
  66. package/src/widget/icons/icon_skype.svg +44 -44
  67. package/src/widget/icons/icon_skype_circle.svg +46 -46
  68. package/src/widget/icons/icon_skype_new.svg +113 -113
  69. package/src/widget/icons/icon_tg.svg +25 -25
  70. package/src/widget/icons/icon_tg_circle.svg +17 -27
  71. package/src/widget/icons/icon_viber.svg +75 -75
  72. package/src/widget/icons/icon_viber_circle.svg +67 -77
  73. package/src/widget/icons/icon_viber_new.svg +102 -102
  74. package/src/widget/icons/icon_vk.svg +14 -14
  75. package/src/widget/icons/icon_vk_circle.svg +16 -16
  76. package/src/widget/icons/icon_whatsapp.svg +147 -147
  77. package/src/widget/icons/icon_whatsapp_circle.svg +3 -3
  78. package/src/widget/icons/icon_whatsapp_hollow.svg +128 -0
  79. package/src/widget/icons/icon_whatsapp_new.svg +127 -127
  80. package/src/widget/icons/icon_whatsappb.svg +147 -0
  81. package/src/widget/icons/icon_whatsappb_circle.svg +4 -0
  82. package/src/widget/icons/icon_whatsappb_new.svg +127 -0
  83. package/src/widget/icons/paper-plane-arrow.svg +3 -0
  84. package/src/widget/icons/tb-logo.svg +21 -0
  85. package/src/widget/index.js +28 -28
  86. package/src/widget/locales/cs.js +42 -0
  87. package/src/widget/locales/en.js +42 -20
  88. package/src/widget/locales/index.js +2 -2
  89. package/src/widget/locales/pl.js +41 -19
  90. package/src/widget/locales/ro.js +41 -20
  91. package/src/widget/locales/ru.js +40 -19
  92. package/src/widget/locales/uk.js +40 -19
  93. package/src/widget/utils/cookiesEx.js +41 -41
  94. package/src/widget/utils/getLocale.js +4 -2
  95. package/src/widget/utils/stringifyAttributes.js +19 -19
  96. package/src/widget/utils/text.js +2 -1
  97. package/src/widget/utils/widgetsStorage.js +28 -28
  98. package/src/widget/widget.entry.js +3 -4
  99. package/tests/gf.html +35 -35
  100. package/tests/gf.js +21 -21
  101. package/tests/index.js +61 -61
  102. package/views/examples.ejs +7 -3
  103. package/views/sdk.html +274 -256
  104. package/webpack.common.js +72 -72
  105. package/webpack.dev.js +15 -15
  106. package/webpack.prod.js +10 -10
  107. package/src/widget/components/tb-notification-button/skype.js +0 -47
  108. package/src/widget/icons/text-back-badge.png +0 -0
  109. package/src/widget/locales/cz.js +0 -20
@@ -1,25 +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
+ '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
  `;
@@ -1,35 +1,35 @@
1
- import Component from '../index.js';
2
- import appInsights from '../../../sdk/utils/appInsights.js';
3
- import find from '../../../sdk/utils/find.js';
4
- import './styles.scss';
5
-
6
- export default class Button extends Component {
7
- constructor() {
8
- super(...arguments);
9
-
10
- this.element.setAttribute('channel', this.channel);
11
-
12
- this.channelAPI = find(this.widgetAPI.getEnabledChannels(), channel => {
13
- return channel.id === this.config.id && channel.channel === this.config.channel && channel.channelId === this.config.channelId;
14
- });
15
- }
16
-
17
- render() {
18
- let self = this;
19
- super.render();
20
- this.element.addEventListener('click', () => {
21
- appInsights.trackButtonClick(this.widgetId, 'notificationWidget.button.click', this.channel)
22
- });
23
- }
24
-
25
- get defaults() {
26
- return {
27
- config: JSON.parse(this.element.getAttribute('config')) || {},
28
- channel: this.element.getAttribute('channel')
29
- }
30
- }
31
-
32
- static get tagName() {
33
- return 'tb-notification-button';
34
- }
1
+ import Component from '../index.js';
2
+ import appInsights from '../../../sdk/utils/appInsights.js';
3
+ import find from '../../../sdk/utils/find.js';
4
+ import './styles.scss';
5
+
6
+ export default class Button extends Component {
7
+ constructor() {
8
+ super(...arguments);
9
+
10
+ this.element.setAttribute('channel', this.channel);
11
+
12
+ this.channelAPI = find(this.widgetAPI.getEnabledChannels(), channel => {
13
+ return channel.id === this.config.id && channel.channel === this.config.channel && channel.channelId === this.config.channelId;
14
+ });
15
+ }
16
+
17
+ render() {
18
+ let self = this;
19
+ super.render();
20
+ this.element.addEventListener('click', () => {
21
+ appInsights.trackButtonClick(this.widgetId, 'notificationWidget.button.click', this.channel)
22
+ });
23
+ }
24
+
25
+ get defaults() {
26
+ return {
27
+ config: JSON.parse(this.element.getAttribute('config')) || {},
28
+ channel: this.element.getAttribute('channel')
29
+ }
30
+ }
31
+
32
+ static get tagName() {
33
+ return 'tb-notification-button';
34
+ }
35
35
  };