@chat21/chat21-web-widget 5.0.52 → 5.0.53-rc.2

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 (137) hide show
  1. package/.github/workflows/docker-community-push-latest.yml +1 -0
  2. package/.github/workflows/docker-image-tag-community-tag-push.yml +1 -0
  3. package/CHANGELOG.md +16 -0
  4. package/Dockerfile +2 -2
  5. package/angular.json +4 -21
  6. package/deploy_amazon_beta.sh +1 -1
  7. package/deploy_amazon_prod.sh +1 -1
  8. package/package.json +17 -18
  9. package/src/app/app.component.scss +38 -10
  10. package/src/app/app.component.ts +2 -0
  11. package/src/app/app.module.ts +5 -3
  12. package/src/app/component/conversation-detail/conversation/conversation.component.html +13 -1
  13. package/src/app/component/conversation-detail/conversation/conversation.component.scss +19 -0
  14. package/src/app/component/conversation-detail/conversation/conversation.component.ts +50 -9
  15. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +0 -2
  16. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +0 -10
  17. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +22 -0
  18. package/src/app/component/form/form-builder/form-builder.component.ts +1 -1
  19. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +1 -1
  20. package/src/app/component/form/inputs/form-label/form-label.component.ts +1 -1
  21. package/src/app/component/form/inputs/form-text/form-text.component.ts +2 -2
  22. package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +2 -2
  23. package/src/app/component/form/prechat-form/prechat-form.component.ts +1 -1
  24. package/src/app/component/home/home.component.html +7 -15
  25. package/src/app/component/message/bubble-message/bubble-message.component.html +1 -4
  26. package/src/app/component/message/bubble-message/bubble-message.component.ts +1 -37
  27. package/src/app/component/message/image/image.component.ts +1 -9
  28. package/src/app/component/message/info-message/info-message.component.html +3 -3
  29. package/src/app/component/message/info-message/info-message.component.ts +0 -10
  30. package/src/app/directives/tooltip.directive.spec.ts +8 -0
  31. package/src/app/directives/tooltip.directive.ts +46 -0
  32. package/src/app/providers/global-settings.service.ts +2 -2
  33. package/src/app/utils/rules.ts +13 -0
  34. package/src/base_script.html +57 -0
  35. package/src/chat21-core/providers/abstract/archivedconversations-handler.service.ts +5 -5
  36. package/src/chat21-core/providers/abstract/conversation-handler.service.ts +6 -6
  37. package/src/chat21-core/providers/abstract/conversations-handler.service.ts +6 -6
  38. package/src/chat21-core/providers/abstract/groups-handler.service.ts +5 -5
  39. package/src/chat21-core/providers/abstract/logger.service.ts +1 -0
  40. package/src/chat21-core/providers/abstract/messagingAuth.service.ts +2 -2
  41. package/src/chat21-core/providers/abstract/presence.service.ts +2 -2
  42. package/src/chat21-core/providers/abstract/typing.service.ts +2 -2
  43. package/src/chat21-core/providers/abstract/upload.service.ts +1 -1
  44. package/src/chat21-core/providers/firebase/firebase-archivedconversations-handler.ts +1 -1
  45. package/src/chat21-core/providers/firebase/firebase-groups-handler.ts +1 -1
  46. package/src/chat21-core/providers/logger/customLogger.ts +4 -0
  47. package/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts +1 -1
  48. package/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts +0 -1
  49. package/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts +1 -1
  50. package/src/chat21-core/utils/constants.ts +3 -2
  51. package/src/chat21-core/utils/utils.ts +2 -0
  52. package/src/launch.js +4 -61
  53. package/src/polyfills.ts +0 -10
  54. package/src/test.ts +3 -1
  55. package/tsconfig.json +5 -3
  56. package/dist/3rdpartylicenses.txt +0 -942
  57. package/dist/assets/i18n/en.json +0 -94
  58. package/dist/assets/i18n/es.json +0 -90
  59. package/dist/assets/i18n/fr.json +0 -90
  60. package/dist/assets/i18n/it.json +0 -90
  61. package/dist/assets/images/avatar_bot_tiledesk.svg +0 -1
  62. package/dist/assets/images/chat_human_avatar.svg +0 -12
  63. package/dist/assets/images/f21ico-done.svg +0 -1
  64. package/dist/assets/images/f21ico-done_all.svg +0 -1
  65. package/dist/assets/images/f21ico-schedule.svg +0 -1
  66. package/dist/assets/images/file-alt-solid.png +0 -0
  67. package/dist/assets/images/light_avatar_placeholder.svg +0 -1
  68. package/dist/assets/images/tommy_bot_tiledesk.svg +0 -48
  69. package/dist/assets/images/website_mockup.jpg +0 -0
  70. package/dist/assets/js/chat21client.js +0 -1066
  71. package/dist/assets/js/mqtt/4.1.0/mqtt.min.js +0 -1
  72. package/dist/assets/js/mqtt/4.2.6/mqtt.min.js +0 -1
  73. package/dist/assets/js/mqtt/4.2.8/mqtt.min.js +0 -1
  74. package/dist/assets/sounds/Carme.mp3 +0 -0
  75. package/dist/assets/sounds/justsaying.mp3 +0 -0
  76. package/dist/assets/sounds/pling.mp3 +0 -0
  77. package/dist/assets/styles/tiledesk_v1.scss +0 -22
  78. package/dist/assets/twp/chatbot-panel.html +0 -424
  79. package/dist/assets/twp/index-dev.html +0 -2430
  80. package/dist/assets/twp/index.html +0 -603
  81. package/dist/assets/twp/tiledesk_widget_files/bootstrap.min.css +0 -5
  82. package/dist/assets/twp/tiledesk_widget_files/bootstrap.min.js +0 -7
  83. package/dist/assets/twp/tiledesk_widget_files/facebook.png +0 -0
  84. package/dist/assets/twp/tiledesk_widget_files/font-awesome.min.css +0 -4
  85. package/dist/assets/twp/tiledesk_widget_files/icon +0 -23
  86. package/dist/assets/twp/tiledesk_widget_files/jquery.min.js +0 -2
  87. package/dist/assets/twp/tiledesk_widget_files/linkedin.png +0 -0
  88. package/dist/assets/twp/tiledesk_widget_files/logo-black.png +0 -0
  89. package/dist/assets/twp/tiledesk_widget_files/logo-mobile.png +0 -0
  90. package/dist/assets/twp/tiledesk_widget_files/logo-short.png +0 -0
  91. package/dist/assets/twp/tiledesk_widget_files/logo.png +0 -0
  92. package/dist/assets/twp/tiledesk_widget_files/logo@2x-black.png +0 -0
  93. package/dist/assets/twp/tiledesk_widget_files/telegram.png +0 -0
  94. package/dist/assets/twp/tiledesk_widget_files/twitter.png +0 -0
  95. package/dist/assets/twp/tiledesk_widget_files/website-poly.min.css +0 -5623
  96. package/dist/assets/twp/tiledesk_widget_files/whatsapp.png +0 -0
  97. package/dist/environments/real_data/widget-config-docker.json +0 -28
  98. package/dist/environments/real_data/widget-config-firebase.json +0 -30
  99. package/dist/environments/real_data/widget-config-mqtt.json +0 -27
  100. package/dist/environments/real_data/widget-config-native-mqtt.json +0 -28
  101. package/dist/environments/real_data/widget-config-native-prod.json +0 -27
  102. package/dist/f21ico-done.svg +0 -1
  103. package/dist/f21ico-done_all.svg +0 -1
  104. package/dist/f21ico-schedule.svg +0 -1
  105. package/dist/favicon.ico +0 -0
  106. package/dist/iframe-style.css +0 -189
  107. package/dist/index.html +0 -16
  108. package/dist/launch.js +0 -428
  109. package/dist/main.js +0 -1
  110. package/dist/polyfills-es5.js +0 -1
  111. package/dist/polyfills.js +0 -1
  112. package/dist/runtime.js +0 -1
  113. package/dist/scripts.js +0 -1
  114. package/dist/styles.css +0 -1
  115. package/dist/styles.js +0 -1
  116. package/dist/test-auth-remote.html +0 -95
  117. package/dist/test-auth.html +0 -49
  118. package/dist/test-buttons.html +0 -147
  119. package/dist/test-custom-auth.html +0 -50
  120. package/dist/test-new.html +0 -231
  121. package/dist/test.html +0 -142
  122. package/dist/tiledesk.js +0 -72
  123. package/dist/vendor.js +0 -1
  124. package/dist/widget-config-template.json +0 -29
  125. package/dist/widget-config.json +0 -29
  126. package/e2e/protractor.conf.js +0 -32
  127. package/src/environments/environment.pre.ts +0 -42
  128. package/src/environments/environment.prod.ts +0 -40
  129. package/src/environments/environment.ts +0 -41
  130. package/src/environments/real_data/widget-config-docker.json +0 -28
  131. package/src/environments/real_data/widget-config-firebase.json +0 -30
  132. package/src/environments/real_data/widget-config-mqtt.json +0 -27
  133. package/src/environments/real_data/widget-config-native-mqtt.json +0 -28
  134. package/src/environments/real_data/widget-config-native-prod.json +0 -27
  135. package/src/test-auth-remote.html +0 -95
  136. package/src/test-auth.html +0 -49
  137. package/src/test-buttons.html +0 -147
package/dist/launch.js DELETED
@@ -1,428 +0,0 @@
1
- /** */
2
- ready(function() {
3
- // console.log('DOM is ready, call initWidget');
4
- if(!window.tileDeskAsyncInit){
5
- initAysncEvents();
6
- }
7
- initWidget();
8
- });
9
-
10
- /** */
11
- function ready(callbackFunction){
12
- if(document.readyState != 'loading')
13
- callbackFunction()
14
- else
15
- document.addEventListener("DOMContentLoaded", callbackFunction)
16
- }
17
-
18
-
19
- /** */
20
- function loadIframe(tiledeskScriptBaseLocation) {
21
- var dev = window.location.hostname.includes('localhost')? true: false;
22
-
23
- var containerDiv = document.createElement('div');
24
- containerDiv.setAttribute('id','tiledesk-container');
25
- containerDiv.classList.add("closed");
26
- document.body.appendChild(containerDiv);
27
-
28
- var iDiv = document.createElement('div');
29
- iDiv.setAttribute('id','tiledeskdiv');
30
- containerDiv.appendChild(iDiv);
31
-
32
- var ifrm = document.createElement("iframe");
33
- ifrm.setAttribute("frameborder", "0");
34
- ifrm.setAttribute("border", "0");
35
-
36
- var srcTileDesk = '<html lang="en">';
37
- srcTileDesk += '<head>';
38
- srcTileDesk += '<meta charset="utf-8">';
39
- srcTileDesk += '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />';
40
- srcTileDesk += '<title>Tilechat Widget</title>';
41
- srcTileDesk += '<base href="./">';
42
- srcTileDesk += '<link rel="icon" type="image/x-icon" href="favicon.ico">';
43
- srcTileDesk += '<link rel="stylesheet" type="text/css" href="' + tiledeskScriptBaseLocation +'/assets/styles/tiledesk_v1.scss" media="all">';
44
- srcTileDesk += '</head>';
45
- srcTileDesk += '<body>';
46
- srcTileDesk += '<chat-root></chat-root>';
47
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/runtime.js"></script>';
48
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/polyfills.js"></script>';
49
- srcTileDesk += '<script type="text/css" src="'+tiledeskScriptBaseLocation+'/styles.css"></script>';
50
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/vendor.js"></script>';
51
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/main.js"></script>';
52
- srcTileDesk += '</body>';
53
- srcTileDesk += '</html>';
54
-
55
- ifrm.setAttribute('id','tiledeskiframe');
56
- ifrm.setAttribute('tiledesk_context','parent');
57
-
58
- /** */
59
- window.tiledesk.on('onInit', function(event_data) {
60
- // console.log("launch onInit isopen", tiledeskScriptBaseLocation, window.tiledesk.angularcomponent.component.g.isOpen);
61
- if (window.tiledesk.angularcomponent.component.g.isOpen) {
62
- containerDiv.classList.add("open");
63
- containerDiv.classList.remove("closed");
64
- iDiv.classList.remove("callout");
65
- } else {
66
- containerDiv.classList.add("closed");
67
- containerDiv.classList.remove("open");
68
- iDiv.classList.remove("messagePreview");
69
- }
70
- });
71
- /** */
72
- window.tiledesk.on('onOpen', function(event_data) {
73
- containerDiv.classList.add("open");
74
- containerDiv.classList.remove("closed");
75
- iDiv.classList.remove("callout");
76
- iDiv.classList.remove("messagePreview");
77
- });
78
- /** */
79
- window.tiledesk.on('onClose', function(event_data) {
80
- containerDiv.classList.add("closed");
81
- containerDiv.classList.remove("open");
82
- });
83
-
84
- /** */
85
- window.tiledesk.on('onOpenEyeCatcher', function(event_data) {
86
- iDiv.classList.add("callout");
87
- });
88
- /** */
89
- window.tiledesk.on('onClosedEyeCatcher', function(event_data) {
90
- iDiv.classList.remove("callout");
91
- });
92
-
93
- /** */
94
- window.tiledesk.on('onConversationUpdated', function(event_data) {
95
- const messagePreview = window.tiledesk.angularcomponent.component.g.isOpenNewMessage
96
- const isOpen = window.tiledesk.angularcomponent.component.g.isOpen
97
- try {
98
- if (!isOpen && messagePreview) {
99
- iDiv.classList.add("messagePreview");
100
- iDiv.classList.remove("callout");
101
- // ----------------------------//
102
- }
103
- } catch(er) {
104
- console.error("onConversationUpdated > error: " + er);
105
- }
106
- });
107
-
108
- window.tiledesk.on('onCloseMessagePreview', function(event_data) {
109
- try {
110
- iDiv.classList.remove("messagePreview");
111
- } catch(er) {
112
- console.error("onCloseMessagePreview > error: " + er);
113
- }
114
- });
115
-
116
-
117
- /**** BEGIN EVENST ****/
118
- /** */
119
- window.tiledesk.on('onNewConversation', function(event_data) {
120
- // console.log("test-custom-auth.html onNewConversation >>>",event_data);
121
- const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
122
- // console.log(">>>> tiledeskToken >>>> ",event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid);
123
- if(tiledeskToken) {
124
- var httpRequest = createCORSRequest('POST', event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid+'/events',true); //set async to false because loadParams must return when the get is complete
125
- httpRequest.setRequestHeader('Content-type', 'application/json');
126
- httpRequest.setRequestHeader('Authorization',tiledeskToken);
127
- httpRequest.send(JSON.stringify({"name":"new_conversation","attributes": {"request_id":event_data.detail.newConvId, "department": event_data.detail.global.departmentSelected.id, "participants": event_data.detail.global.participants, "language": event_data.detail.global.lang, "subtype":"info", "fullname":event_data.detail.global.attributes.userFullname, "email":event_data.detail.global.attributes.userEmail, "attributes":event_data.detail.global.attributes}}));
128
- }
129
- });
130
-
131
- /** @deprecated event */
132
- window.tiledesk.on('onLoggedIn', function(event_data) {
133
- // console.log("test-custom-auth.html onLoggedIn",event_data);
134
- const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
135
- // console.log("------------------->>>> tiledeskToken: ",window.tiledesk.angularcomponent.component.g);
136
- if(tiledeskToken) {
137
- var httpRequest = createCORSRequest('POST', event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid+'/events',true); //set async to false because loadParams must return when the get is complete
138
- httpRequest.setRequestHeader('Content-type','application/json');
139
- httpRequest.setRequestHeader('Authorization',tiledeskToken);
140
- httpRequest.send(JSON.stringify({"name":"logged_in","attributes": {"fullname":event_data.detail.global.attributes.userFullname, "email":event_data.detail.global.attributes.userEmail, "language": event_data.detail.global.lang, "attributes":event_data.detail.global.attributes}}));
141
- }
142
- });
143
-
144
- /** */
145
- window.tiledesk.on('onAuthStateChanged', function(event_data) {
146
- // console.log("test-custom-auth.html onAuthStateChanged",event_data);
147
- const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
148
- // console.log("------------------->>>> tiledeskToken: ",window.tiledesk.angularcomponent.component.g);
149
- if(tiledeskToken) {
150
- var httpRequest = createCORSRequest('POST', event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid+'/events',true); //set async to false because loadParams must return when the get is complete
151
- httpRequest.setRequestHeader('Content-type','application/json');
152
- httpRequest.setRequestHeader('Authorization',tiledeskToken);
153
- httpRequest.send(JSON.stringify({"name":"auth_state_changed","attributes": {"user_id":event_data.detail.global.senderId, "isLogged":event_data.detail.global.isLogged, "event":event_data.detail.event, "subtype":"info", "fullname":event_data.detail.global.attributes.userFullname, "email":event_data.detail.global.attributes.userEmail, "language":event_data.detail.global.lang, "attributes":event_data.detail.global.attributes}}));
154
- httpRequest.onload = function(event) {
155
- if(event.target && event.target.status === 401){
156
- window.tiledesk.hide()
157
- window.tiledesk.dispose()
158
- }
159
- }
160
- }
161
- });
162
- /**** END EVENST ****/
163
-
164
- iDiv.appendChild(ifrm);
165
-
166
- // buildIframeDOM(ifrm)
167
- // ifrm.contentWindow.document.open();
168
- // ifrm.document.srcdoc = srcTileDesk;
169
- // ifrm.srcdoc = srcTileDesk
170
- ifrm.contentWindow.document.open();
171
- ifrm.contentWindow.document.write(srcTileDesk);
172
- ifrm.contentWindow.document.close();
173
-
174
- }
175
-
176
- function buildIframeDOM(iframe){
177
-
178
- var meta = document.createElement('meta');
179
- meta.setAttribute('charset', 'utf-8')
180
- var meta_2 = document.createElement('meta')
181
- meta_2.setAttribute('name', 'viewport')
182
- meta_2.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0')
183
- var title = document.createElement('title')
184
- title.title = 'Tilechat Widget'
185
- var base = document.createElement('base')
186
- base.setAttribute('href', './')
187
- var link_1 = document.createElement('link')
188
- link_1.setAttribute('rel', 'icon')
189
- link_1.setAttribute('type', 'image/x-icon')
190
- link_1.setAttribute('href', 'favicon.ico')
191
- var link_2 = document.createElement('link')
192
- link_2.setAttribute('rel', 'stylesheet')
193
- link_2.setAttribute('type', 'text/css')
194
- link_2.setAttribute('href', tiledeskScriptBaseLocation + '/assets/styles/tiledesk_v1.scss')
195
- link_2.setAttribute('media','all')
196
-
197
-
198
- let head = iframe.contentWindow.document.getElementsByTagName('head')[0]
199
- head.appendChild(meta)
200
- head.appendChild(meta_2)
201
- head.appendChild(title)
202
- head.appendChild(base)
203
- head.appendChild(link_1)
204
- head.appendChild(link_2)
205
-
206
- var script_1 = document.createElement('script')
207
- script_1.setAttribute('type','text/javascript')
208
- script_1.setAttribute('src',tiledeskScriptBaseLocation + '/runtime.js')
209
- var script_2 = document.createElement('script')
210
- script_2.setAttribute('type','text/javascript')
211
- script_2.setAttribute('src',tiledeskScriptBaseLocation + '/polyfills.js')
212
- var script_3 = document.createElement('script')
213
- script_3.setAttribute('type','text/javascript')
214
- script_3.setAttribute('src',tiledeskScriptBaseLocation + '/styles.css')
215
- var script_4 = document.createElement('script')
216
- script_4.setAttribute('type','text/javascript')
217
- script_4.setAttribute('src',tiledeskScriptBaseLocation + '/vendor.js')
218
- var script_5 = document.createElement('script')
219
- script_5.setAttribute('type','text/javascript')
220
- script_5.setAttribute('src',tiledeskScriptBaseLocation + '/main.js')
221
-
222
- let body= iframe.contentWindow.document.getElementsByTagName('body')[0]
223
- body.appendChild(document.createElement('chat-root'))
224
- body.appendChild(script_1)
225
- body.appendChild(script_2)
226
- body.appendChild(script_3)
227
- body.appendChild(script_4)
228
- body.appendChild(script_5)
229
- }
230
-
231
-
232
- function initAysncEvents() {
233
- console.log('INIT ASYNC EVENTS')
234
-
235
- window.tileDeskAsyncInit = function() {
236
- // console.log('launch tiledeskAsyncInit:::', window.Tiledesk.q)
237
- window.tiledesk.on('onLoadParams', function(event_data) {
238
- if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
239
- window.Tiledesk.q.forEach(f => {
240
- if (f.length>=1) {
241
- var functionName = f[0];
242
- if (functionName==="onLoadParams") {
243
- //CALLING ONLY FUNCTION 'onLoadParams'
244
- if (f.length==2) {
245
- var functionCallback = f[1];
246
- if(typeof functionCallback === "function") {
247
- window.tiledesk.on(functionName, functionCallback);
248
- functionCallback(event_data);
249
- } else {
250
- console.error("initAysncEvents --> functionCallback is not a function.");
251
- }
252
- }
253
- }else if(functionName=='setParameter'){
254
- //CALLING ONLY METHOD 'setParameter' AND CHECK IF IT HAS OBJECT ARG
255
- if (f.length==2) {
256
- var functionArgs = f[1];
257
- if(typeof functionArgs === "object") {
258
- window.tiledesk[functionName](functionArgs);
259
- } else {
260
- console.error("initAysncEvents --> functionArgs is not a object.");
261
- }
262
- }
263
- }
264
- }
265
- });
266
- }
267
- });
268
-
269
- window.tiledesk.on('onBeforeInit', function(event_data) {
270
- if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
271
- // console.log("w.q", window.Tiledesk.q);
272
- window.Tiledesk.q.forEach(f => {
273
- if (f.length>=1) {
274
- var functionName = f[0];
275
- if (functionName==="onLoadParams" || functionName==="setParameter") {
276
- //SKIP FUNCTION WITH NAMES 'onLoadParams' AND METHOD 'setParameter'
277
- } else if (functionName.startsWith("on")) {
278
- // CALLING METHOD THAT STARTS WITH 'on'
279
- if (f.length==2) {
280
- var functionCallback = f[1];
281
- if(typeof functionCallback === "function"){
282
- window.tiledesk.on(functionName, functionCallback); //potrei usare window.Tiledesk ?!?
283
- if (functionName==="onBeforeInit") {
284
- functionCallback(event_data)
285
- }
286
- } else {
287
- console.error("functionCallback is not a function.");
288
- }
289
- }
290
- } else {
291
- //CALLING REMAININGS METHOD and CHECK IF CONTAINS ARG TO PASS THROUGH THE METHOD
292
- if (f.length==2) {
293
- let args = f[1]
294
- window.tiledesk[functionName](args);
295
- } else {
296
- window.tiledesk[functionName]();
297
- }
298
- }
299
-
300
- }
301
- });
302
-
303
- }
304
-
305
- // RICHIAMATO DOPO L'INIT DEL WIDGET
306
- window.Tiledesk = function() {
307
- if (arguments.length>=1) {
308
- var functionName = arguments[0];
309
- if (arguments.length==2) {
310
- var functionCallback = arguments[1];
311
- }
312
- var methodOrProperty = window.tiledesk[functionName];
313
- if(typeof methodOrProperty==="function"){
314
- return window.tiledesk[functionName](functionCallback);
315
- }else { //property
316
- return window.tiledesk[functionName];
317
- }
318
- }
319
- };
320
-
321
- });
322
- }
323
- }
324
-
325
-
326
- /**
327
- *
328
- */
329
- function initWidget() {
330
- var tiledeskroot = document.createElement('chat-root');
331
- var tiledeskScriptLocation = document.getElementById("tiledesk-jssdk").src;
332
- //var currentScript = document.currentScript;
333
- //var tiledeskScriptLocation = '';
334
- //setInterval(function(){
335
- //tiledeskScriptLocation = currentScript.src;
336
- var tiledeskScriptBaseLocation = tiledeskScriptLocation.replace("/launch.js","");
337
- window.tiledesk = new function() {
338
- //this.type = "macintosh";
339
- this.tiledeskroot = tiledeskroot;
340
- this.on = function (event_name, handler) {
341
- tiledeskroot.addEventListener(event_name, handler);
342
- };
343
- this.getBaseLocation = function() {
344
- return tiledeskScriptBaseLocation;
345
- }
346
- }
347
-
348
- try {
349
- window.tileDeskAsyncInit();
350
- }catch(er) {
351
- if (typeof window.tileDeskAsyncInit == "undefined") {
352
- console.log("tileDeskAsyncInit() doesn't exists");
353
- } else {
354
- console.log(er);
355
- }
356
- }
357
- document.body.appendChild(tiledeskroot);
358
- initCSSWidget(tiledeskScriptBaseLocation);
359
- loadIframe(tiledeskScriptBaseLocation);
360
- //},2000);
361
- }
362
-
363
-
364
-
365
-
366
-
367
- function initCSSWidget(tiledeskScriptBaseLocation) {
368
- var cssId = 'iframeCss'; // you could encode the css path itself to generate id..
369
- // if (!document.getElementById(cssId))
370
- // {
371
- var head = document.getElementsByTagName('head')[0];
372
- var link = document.createElement('link');
373
- link.id = cssId;
374
- link.rel = 'stylesheet';
375
- link.type = 'text/css';
376
- link.href = tiledeskScriptBaseLocation+'/iframe-style.css';
377
- link.media = 'all';
378
- head.appendChild(link);
379
- // }
380
- }
381
-
382
-
383
- //DEPRECATED
384
- function signInWithCustomToken() {
385
- let json = JSON.stringify({
386
- "id_project": "5b55e806c93dde00143163dd"
387
- });
388
- var httpRequest = createCORSRequest('POST', 'https://tiledesk-server-pre.herokuapp.com/auth/signinAnonymously',true);
389
- if (!httpRequest) {
390
- throw new Error('CORS not supported');
391
- }
392
- httpRequest.setRequestHeader('Content-type','application/json');
393
- httpRequest.send(json);
394
- httpRequest.onload = function() {
395
- if (httpRequest.readyState === XMLHttpRequest.DONE) {
396
- if (httpRequest.status === 200) {
397
- try {
398
- var response = JSON.parse(httpRequest.responseText);
399
- window.tiledesk.signInWithCustomToken(response);
400
- }
401
- catch(err) {
402
- console.error(err.message);
403
- }
404
- return true;
405
- } else {
406
- alert('There was a problem with the request.');
407
- }
408
- }
409
- };
410
- httpRequest.onerror = function() {
411
- console.error('There was an error!');
412
- return false;
413
- };
414
- }
415
-
416
-
417
- function createCORSRequest(method, url, async) {
418
- var xhr = new XMLHttpRequest();
419
- if ("withCredentials" in xhr) {
420
- xhr.open(method, url, async);
421
- } else if (typeof XDomainRequest != "undefined") {
422
- xhr = new XDomainRequest();
423
- xhr.open(method, url);
424
- } else {
425
- xhr = null;
426
- }
427
- return xhr;
428
- }