@chat21/chat21-web-widget 5.0.53-rc.5 → 5.0.53-rc.7

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.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,19 @@
1
1
  # chat21-web-widget ver 5.0
2
2
 
3
+ ### 5.0.53-rc.7
4
+ - bug-fixed: start message was shown twice
5
+ - bug-fixed: is showAvailableAgents is false and no conversations exist, 'new conversation' button not displayed
6
+
7
+ ### 5.0.53-rc.6
8
+ - changed: removed wait object from Rule model
9
+ - bug-fixed: splitted message lose original parent message attributes
10
+ - bug-fixed: preChat form element UI padding
11
+
3
12
  ### 5.0.53-rc.5
4
13
  - changed: minor improvements for last-message component UI
5
14
  - changed: last-message UI for long text message and long attachment buttons
6
15
  - removed: automatic open widget after 3s on index.html
7
- - bug-fixed: on click over callout not opens widget correctly if singleConversation is active
16
+ - bug-fixed: on click over callout not opens widget correctly if singleConversation is active
8
17
 
9
18
  ### 5.0.53-rc.4
10
19
  - added: proactive rules from /widget/botsRules
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-web-widget",
3
3
  "author": "Tiledesk SRL",
4
- "version": "5.0.53-rc.5",
4
+ "version": "5.0.53-rc.7",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.tiledesk.com",
7
7
  "repository": {
@@ -109,7 +109,7 @@ input {
109
109
  border-radius: $chat-footer-border-radius;
110
110
  font-weight: 400;
111
111
  height: 48px;
112
- padding: 16px;
112
+ padding: 0px 16px;
113
113
  font-size: 14px;
114
114
  line-height: 1.42857143;
115
115
  display: block;
@@ -103,7 +103,7 @@ textarea {
103
103
  border-radius: $chat-footer-border-radius;
104
104
  font-weight: 400;
105
105
  // height: 36px;
106
- padding: 16px;
106
+ padding: 0px 16px;
107
107
  font-size: 14px;
108
108
  line-height: 1.42857143;
109
109
  display: block;
@@ -35,8 +35,8 @@
35
35
  <div class="c21-body">
36
36
 
37
37
 
38
-
39
- <div *ngIf="(!listConversations || listConversations.length == 0) && g.showAvailableAgents === true && availableAgents && availableAgents.length > 1" style="margin: 20px 30px;">
38
+ <!--CASE: no conversations EXIST - >1 agents is available -->
39
+ <div *ngIf="(!listConversations || listConversations.length == 0) && availableAgents && availableAgents.length > 1 && g.showAvailableAgents === true" style="margin: 20px 30px;">
40
40
  <div *ngFor="let agent of availableAgents" class="c21-pallozzo">
41
41
  <div class="c21-ball" [ngStyle] = "{ 'background-color':setColorFromString(agent.firstname) }" >
42
42
  <span class="c21-ball-label">{{avatarPlaceholder(agent.firstname)}}</span>
@@ -45,6 +45,7 @@
45
45
  </div>
46
46
  </div>
47
47
 
48
+ <!--CASE: no conversations EXIST - 1 agents is available -->
48
49
  <div class="flex-container" *ngIf="(!listConversations || listConversations.length == 0) && availableAgents && availableAgents.length === 1 && g.showAvailableAgents === true">
49
50
  <div *ngFor="let agent of availableAgents" class="c21-pallozzo flex-inline-agent ">
50
51
  <div class="c21-ball" [ngStyle] = "{ 'background-color':setColorFromString(agent.firstname) }" >
@@ -65,7 +66,8 @@
65
66
  </button>
66
67
  </div>
67
68
 
68
- <div *ngIf="(availableAgents && availableAgents.length > 1 ) || (listConversations && listConversations.length > 0 || (availableAgents && availableAgents.length === 0 ) )">
69
+ <!--CASE: conversations EXIST OR >1 agents is available OR showAvailableAgents=FALSE -->
70
+ <div *ngIf="(availableAgents && availableAgents.length > 1 ) || (listConversations && listConversations.length > 0 || (availableAgents && availableAgents.length === 0 ) || g.showAvailableAgents === false )">
69
71
  <chat-list-conversations *ngIf="(listConversations && listConversations.length > 0)"
70
72
  [listConversations]="listConversations"
71
73
  [limit]="3"
@@ -53,7 +53,6 @@ export class Rules {
53
53
  private doAction(action: Rule['do']){
54
54
  this.logger.info('[RULES] doAction', this.currentUser, action)
55
55
  let message = action.filter(obj => Object.keys(obj).includes('message'))
56
- let wait = action.filter(obj => Object.keys(obj).includes('wait'))
57
56
  if(message && message.length>0){
58
57
  message[0]['message'].attributes = { ...this.g.attributes, ...message[0]['message'].attributes}
59
58
  message[0]['message'].userAgent = this.g.attributes['client']
@@ -62,10 +61,7 @@ export class Rules {
62
61
  message[0]['message'].language = this.g.lang
63
62
  message[0]['message'].departmentid = this.g.attributes.departmentId
64
63
  console.log('message[0]', message[0]['message'])
65
- setTimeout(() => {
66
- this.tiledeskRequestsService.sendMessageToRequest(this.request_id, this.tiledeskToken, message[0]['message'])
67
- console.log('rulessss', this.appStorageService.getItem('_botsRules'))
68
- }, wait[0]['wait']);
64
+ this.tiledeskRequestsService.sendMessageToRequest(this.request_id, this.tiledeskToken, message[0]['message'])
69
65
  }
70
66
  }
71
67
 
@@ -534,6 +534,7 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
534
534
  command_message.isSender = message.isSender;
535
535
  command_message.attributes? command_message.attributes.commands = true : command_message.attributes = {commands : true}
536
536
  command_message.attributes.parentUid = parentUid //added to manage message STATUS UPDATES
537
+ command_message.attributes = {...message.attributes, ...command_message.attributes}
537
538
  this.addedNew(command_message)
538
539
  callback();
539
540
  }
@@ -113,7 +113,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
113
113
  }
114
114
 
115
115
  if (msg.attributes && msg.attributes.commands ) {
116
- this.logger.debug('[MQTTConversationHandlerSERVICE] splitted message::::', this.messages)
116
+ this.logger.debug('[MQTTConversationHandlerSERVICE] splitted message::::', this.messages, msg)
117
117
  this.addCommandMessage(msg)
118
118
  } else {
119
119
  // this.logger.debug('[MQTTConversationHandlerSERVICE] NOT splitted message::::', msg)
@@ -458,7 +458,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
458
458
  commands[i+1]? commands[i+1].time = 0 : null
459
459
  }
460
460
  }
461
- that.generateMessageObject(msg, command.message, function () {
461
+ that.generateMessageObject(msg, command.message, i, function () {
462
462
  i += 1
463
463
  if (i < commands.length) {
464
464
  execute(commands[i])
@@ -488,9 +488,10 @@ export class MQTTConversationHandler extends ConversationHandlerService {
488
488
  execute(commands[0]) //START render first message
489
489
  }
490
490
 
491
- private generateMessageObject(message, command_message, callback) {
491
+ private generateMessageObject(message, command_message, index, callback) {
492
492
  let parentUid = message.uid
493
- command_message.uid = uuidv4();
493
+ // command_message.uid = uuidv4();
494
+ command_message.uid = message.uid + '_' + index
494
495
  if(command_message.text) command_message.text = command_message.text.trim()//remove black msg with only spaces
495
496
  command_message.language = message.language;
496
497
  command_message.recipient = message.recipient;
@@ -502,6 +503,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
502
503
  command_message.isSender = message.isSender;
503
504
  command_message.attributes? command_message.attributes.commands = true : command_message.attributes = {commands : true}
504
505
  command_message.attributes.parentUid = parentUid //added to manage message STATUS UPDATES
506
+ command_message.attributes = {...message.attributes, ...command_message.attributes}
505
507
  this.addedMessage(command_message)
506
508
  callback();
507
509
  }
@@ -13,7 +13,7 @@ export interface Rule {
13
13
  triggerEvery: number
14
14
  },
15
15
  do: [
16
- {wait: number},
16
+ // {wait: number},
17
17
  {message: any}
18
18
  ]
19
19
  }
package/src/launch_old.js DELETED
@@ -1,446 +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
- ifrm.setAttribute("title", "Tiledesk Widget")
36
-
37
- var srcTileDesk = '<html lang="en">';
38
- srcTileDesk += '<head>';
39
- srcTileDesk += '<meta charset="utf-8">';
40
- srcTileDesk += '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />';
41
- srcTileDesk += '<title>Tilechat Widget</title>';
42
- srcTileDesk += '<base href="./">';
43
- srcTileDesk += '<link rel="icon" type="image/x-icon" href="favicon.ico">';
44
- srcTileDesk += '<link rel="stylesheet" type="text/css" href="' + tiledeskScriptBaseLocation +'/assets/styles/tiledesk_v1.scss" media="all">';
45
- srcTileDesk += '</head>';
46
- srcTileDesk += '<body>';
47
- srcTileDesk += '<chat-root></chat-root>';
48
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/runtime.js"></script>';
49
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/polyfills.js"></script>';
50
- srcTileDesk += '<link type="text/css" rel="stylesheet" href="'+tiledeskScriptBaseLocation+'/styles.css" media="all"></link>';
51
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/vendor.js"></script>';
52
- srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/main.js"></script>';
53
- srcTileDesk += '</body>';
54
- srcTileDesk += '</html>';
55
-
56
- ifrm.setAttribute('id','tiledeskiframe');
57
- ifrm.setAttribute('tiledesk_context','parent');
58
-
59
- /** */
60
- window.tiledesk.on('onInit', function(event_data) {
61
- // console.log("launch onInit isopen", tiledeskScriptBaseLocation, window.tiledesk.angularcomponent.component.g.isOpen);
62
- if (window.tiledesk.angularcomponent.component.g.isOpen) {
63
- containerDiv.classList.add("open");
64
- containerDiv.classList.remove("closed");
65
- iDiv.classList.remove("callout");
66
- } else {
67
- containerDiv.classList.add("closed");
68
- containerDiv.classList.remove("open");
69
- iDiv.classList.remove("messagePreview");
70
- }
71
- });
72
- /** */
73
- window.tiledesk.on('onOpen', function(event_data) {
74
- containerDiv.classList.add("open");
75
- containerDiv.classList.remove("closed");
76
- iDiv.classList.remove("callout");
77
- iDiv.classList.remove("messagePreview");
78
- });
79
- /** */
80
- window.tiledesk.on('onClose', function(event_data) {
81
- containerDiv.classList.add("closed");
82
- containerDiv.classList.remove("open");
83
- });
84
-
85
- /** */
86
- window.tiledesk.on('onOpenEyeCatcher', function(event_data) {
87
- iDiv.classList.add("callout");
88
- });
89
- /** */
90
- window.tiledesk.on('onClosedEyeCatcher', function(event_data) {
91
- iDiv.classList.remove("callout");
92
- });
93
-
94
- /** */
95
- window.tiledesk.on('onConversationUpdated', function(event_data) {
96
- const messagePreview = window.tiledesk.angularcomponent.component.g.isOpenNewMessage
97
- const isOpen = window.tiledesk.angularcomponent.component.g.isOpen
98
- try {
99
- if (!isOpen && messagePreview) {
100
- iDiv.classList.add("messagePreview");
101
- iDiv.classList.remove("callout");
102
- // ----------------------------//
103
- }
104
- } catch(er) {
105
- console.error("onConversationUpdated > error: " + er);
106
- }
107
- });
108
-
109
- window.tiledesk.on('onCloseMessagePreview', function(event_data) {
110
- try {
111
- iDiv.classList.remove("messagePreview");
112
- } catch(er) {
113
- console.error("onCloseMessagePreview > error: " + er);
114
- }
115
- });
116
-
117
-
118
- /**** BEGIN EVENST ****/
119
- /** */
120
- window.tiledesk.on('onNewConversation', function(event_data) {
121
- // console.log("test-custom-auth.html onNewConversation >>>",event_data);
122
- const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
123
- // console.log(">>>> tiledeskToken >>>> ",event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid);
124
- if(tiledeskToken) {
125
- 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
126
- httpRequest.setRequestHeader('Content-type', 'application/json');
127
- httpRequest.setRequestHeader('Authorization',tiledeskToken);
128
- 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}}));
129
- }
130
- });
131
-
132
- /** @deprecated event */
133
- window.tiledesk.on('onLoggedIn', function(event_data) {
134
- // console.log("test-custom-auth.html onLoggedIn",event_data);
135
- const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
136
- // console.log("------------------->>>> tiledeskToken: ",window.tiledesk.angularcomponent.component.g);
137
- if(tiledeskToken) {
138
- 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
139
- httpRequest.setRequestHeader('Content-type','application/json');
140
- httpRequest.setRequestHeader('Authorization',tiledeskToken);
141
- 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}}));
142
- }
143
- });
144
-
145
- /** */
146
- window.tiledesk.on('onAuthStateChanged', function(event_data) {
147
- // console.log("test-custom-auth.html onAuthStateChanged",event_data);
148
- const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
149
- // console.log("------------------->>>> tiledeskToken: ",window.tiledesk.angularcomponent.component.g);
150
- if(tiledeskToken) {
151
- 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
152
- httpRequest.setRequestHeader('Content-type','application/json');
153
- httpRequest.setRequestHeader('Authorization',tiledeskToken);
154
- 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}}));
155
- httpRequest.onload = function(event) {
156
- if(event.target && event.target.status === 401){
157
- window.tiledesk.hide()
158
- window.tiledesk.dispose()
159
- }
160
- }
161
- }
162
- });
163
- /**** END EVENST ****/
164
-
165
- iDiv.appendChild(ifrm);
166
-
167
- if(tiledeskScriptBaseLocation.includes('localhost')){
168
- // ifrm.src = tiledeskScriptBaseLocation + '/base_script.html'
169
- // buildIframeDOM(ifrm, tiledeskScriptBaseLocation)
170
- ifrm.contentWindow.document.open();
171
- ifrm.contentWindow.document.write(srcTileDesk);
172
- ifrm.contentWindow.document.close();
173
- }else {
174
- ifrm.srcdoc = srcTileDesk
175
- }
176
- // ifrm.onload = function(ev){
177
- // const obj = {tiledeskSettings: window.tiledeskSettings}
178
- // ifrm.contentWindow.postMessage(obj, "*")
179
- // console.log('iframe contentwindowwww', ifrm.contentWindow)
180
- // // ifrm.contentWindow.tiledesk = window.tiledesk
181
- // }
182
- // ifrm.innerHTML = srcTileDesk
183
- // ifrm.contentWindow.document.open();
184
-
185
-
186
- }
187
-
188
- function buildIframeDOM(iframe, tiledeskScriptBaseLocation){
189
-
190
-
191
-
192
- var Idocument = iframe.contentDocument
193
- console.log('iframeeee', Idocument)
194
- var meta = Idocument.createElement('meta');
195
- meta.setAttribute('charset', 'utf-8')
196
- var meta_2 = Idocument.createElement('meta')
197
- meta_2.setAttribute('name', 'viewport')
198
- meta_2.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0')
199
- var title = Idocument.createElement('title')
200
- title.title = 'Tilechat Widget'
201
- var base = Idocument.createElement('base')
202
- base.setAttribute('href', './')
203
- var link_1 = Idocument.createElement('link')
204
- link_1.setAttribute('rel', 'icon')
205
- link_1.setAttribute('type', 'image/x-icon')
206
- link_1.setAttribute('href', 'favicon.ico')
207
- var link_2 = Idocument.createElement('link')
208
- link_2.setAttribute('rel', 'stylesheet')
209
- link_2.setAttribute('type', 'text/css')
210
- link_2.setAttribute('href', tiledeskScriptBaseLocation + '/assets/styles/tiledesk_v1.scss')
211
- link_2.setAttribute('media','all')
212
-
213
-
214
- let head = Idocument.getElementsByTagName('head')[0]
215
- head.appendChild(meta)
216
- head.appendChild(meta_2)
217
- head.appendChild(title)
218
- head.appendChild(base)
219
- head.appendChild(link_1)
220
- head.appendChild(link_2)
221
-
222
- var script_1 = Idocument.createElement('script')
223
- script_1.setAttribute('type','text/javascript')
224
- script_1.setAttribute('src',tiledeskScriptBaseLocation + '/runtime.js')
225
- var script_2 = Idocument.createElement('script')
226
- script_2.setAttribute('type','text/javascript')
227
- script_2.setAttribute('src',tiledeskScriptBaseLocation + '/polyfills.js')
228
- var link = Idocument.createElement('link')
229
- link.setAttribute('type','text/css')
230
- link.setAttribute('rel','stylesheet')
231
- link.setAttribute('href',tiledeskScriptBaseLocation + '/styles.css')
232
- link.setAttribute('media','all')
233
- var script_4 = Idocument.createElement('script')
234
- script_4.setAttribute('type','text/javascript')
235
- script_4.setAttribute('src',tiledeskScriptBaseLocation + '/vendor.js')
236
- var script_5 = Idocument.createElement('script')
237
- script_5.setAttribute('type','text/javascript')
238
- script_5.setAttribute('src',tiledeskScriptBaseLocation + '/main.js')
239
-
240
- let body= Idocument.getElementsByTagName('body')[0]
241
- body.appendChild(Idocument.createElement('chat-root'))
242
- body.appendChild(script_1)
243
- body.appendChild(script_2)
244
- body.appendChild(link)
245
- body.appendChild(script_4)
246
- body.appendChild(script_5)
247
- }
248
-
249
-
250
- function initAysncEvents() {
251
- console.log('INIT ASYNC EVENTS')
252
-
253
- window.tileDeskAsyncInit = function() {
254
- // console.log('launch tiledeskAsyncInit:::', window.Tiledesk.q)
255
- window.tiledesk.on('onLoadParams', function(event_data) {
256
- if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
257
- window.Tiledesk.q.forEach(f => {
258
- if (f.length>=1) {
259
- var functionName = f[0];
260
- if (functionName==="onLoadParams") {
261
- //CALLING ONLY FUNCTION 'onLoadParams'
262
- if (f.length==2) {
263
- var functionCallback = f[1];
264
- if(typeof functionCallback === "function") {
265
- window.tiledesk.on(functionName, functionCallback);
266
- functionCallback(event_data);
267
- } else {
268
- console.error("initAysncEvents --> functionCallback is not a function.");
269
- }
270
- }
271
- }else if(functionName=='setParameter'){
272
- //CALLING ONLY METHOD 'setParameter' AND CHECK IF IT HAS OBJECT ARG
273
- if (f.length==2) {
274
- var functionArgs = f[1];
275
- if(typeof functionArgs === "object") {
276
- window.tiledesk[functionName](functionArgs);
277
- } else {
278
- console.error("initAysncEvents --> functionArgs is not a object.");
279
- }
280
- }
281
- }
282
- }
283
- });
284
- }
285
- });
286
-
287
- window.tiledesk.on('onBeforeInit', function(event_data) {
288
- if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
289
- // console.log("w.q", window.Tiledesk.q);
290
- window.Tiledesk.q.forEach(f => {
291
- if (f.length>=1) {
292
- var functionName = f[0];
293
- if (functionName==="onLoadParams" || functionName==="setParameter") {
294
- //SKIP FUNCTION WITH NAMES 'onLoadParams' AND METHOD 'setParameter'
295
- } else if (functionName.startsWith("on")) {
296
- // CALLING METHOD THAT STARTS WITH 'on'
297
- if (f.length==2) {
298
- var functionCallback = f[1];
299
- if(typeof functionCallback === "function"){
300
- window.tiledesk.on(functionName, functionCallback); //potrei usare window.Tiledesk ?!?
301
- if (functionName==="onBeforeInit") {
302
- functionCallback(event_data)
303
- }
304
- } else {
305
- console.error("functionCallback is not a function.");
306
- }
307
- }
308
- } else {
309
- //CALLING REMAININGS METHOD and CHECK IF CONTAINS ARG TO PASS THROUGH THE METHOD
310
- if (f.length==2) {
311
- let args = f[1]
312
- window.tiledesk[functionName](args);
313
- } else {
314
- window.tiledesk[functionName]();
315
- }
316
- }
317
-
318
- }
319
- });
320
-
321
- }
322
-
323
- // RICHIAMATO DOPO L'INIT DEL WIDGET
324
- window.Tiledesk = function() {
325
- if (arguments.length>=1) {
326
- var functionName = arguments[0];
327
- if (arguments.length==2) {
328
- var functionCallback = arguments[1];
329
- }
330
- var methodOrProperty = window.tiledesk[functionName];
331
- if(typeof methodOrProperty==="function"){
332
- return window.tiledesk[functionName](functionCallback);
333
- }else { //property
334
- return window.tiledesk[functionName];
335
- }
336
- }
337
- };
338
-
339
- });
340
- }
341
- }
342
-
343
-
344
- /**
345
- *
346
- */
347
- function initWidget() {
348
- var tiledeskroot = document.createElement('chat-root');
349
- var tiledeskScriptLocation = document.getElementById("tiledesk-jssdk").src;
350
- //var currentScript = document.currentScript;
351
- //var tiledeskScriptLocation = '';
352
- //setInterval(function(){
353
- //tiledeskScriptLocation = currentScript.src;
354
- var tiledeskScriptBaseLocation = tiledeskScriptLocation.replace("/launch.js","");
355
- window.tiledesk = new function() {
356
- //this.type = "macintosh";
357
- this.tiledeskroot = tiledeskroot;
358
- this.on = function (event_name, handler) {
359
- tiledeskroot.addEventListener(event_name, handler);
360
- };
361
- this.getBaseLocation = function() {
362
- return tiledeskScriptBaseLocation;
363
- }
364
- }
365
-
366
- try {
367
- window.tileDeskAsyncInit();
368
- }catch(er) {
369
- if (typeof window.tileDeskAsyncInit == "undefined") {
370
- console.log("tileDeskAsyncInit() doesn't exists");
371
- } else {
372
- console.log(er);
373
- }
374
- }
375
- document.body.appendChild(tiledeskroot);
376
- initCSSWidget(tiledeskScriptBaseLocation);
377
- loadIframe(tiledeskScriptBaseLocation);
378
- //},2000);
379
- }
380
-
381
-
382
-
383
-
384
-
385
- function initCSSWidget(tiledeskScriptBaseLocation) {
386
- var cssId = 'iframeCss'; // you could encode the css path itself to generate id..
387
- // if (!document.getElementById(cssId))
388
- // {
389
- var head = document.getElementsByTagName('head')[0];
390
- var link = document.createElement('link');
391
- link.id = cssId;
392
- link.rel = 'stylesheet';
393
- link.type = 'text/css';
394
- link.href = tiledeskScriptBaseLocation+'/iframe-style.css';
395
- link.media = 'all';
396
- head.appendChild(link);
397
- // }
398
- }
399
-
400
-
401
- //DEPRECATED
402
- function signInWithCustomToken() {
403
- let json = JSON.stringify({
404
- "id_project": "5b55e806c93dde00143163dd"
405
- });
406
- var httpRequest = createCORSRequest('POST', 'https://tiledesk-server-pre.herokuapp.com/auth/signinAnonymously',true);
407
- if (!httpRequest) {
408
- throw new Error('CORS not supported');
409
- }
410
- httpRequest.setRequestHeader('Content-type','application/json');
411
- httpRequest.send(json);
412
- httpRequest.onload = function() {
413
- if (httpRequest.readyState === XMLHttpRequest.DONE) {
414
- if (httpRequest.status === 200) {
415
- try {
416
- var response = JSON.parse(httpRequest.responseText);
417
- window.tiledesk.signInWithCustomToken(response);
418
- }
419
- catch(err) {
420
- console.error(err.message);
421
- }
422
- return true;
423
- } else {
424
- alert('There was a problem with the request.');
425
- }
426
- }
427
- };
428
- httpRequest.onerror = function() {
429
- console.error('There was an error!');
430
- return false;
431
- };
432
- }
433
-
434
-
435
- function createCORSRequest(method, url, async) {
436
- var xhr = new XMLHttpRequest();
437
- if ("withCredentials" in xhr) {
438
- xhr.open(method, url, async);
439
- } else if (typeof XDomainRequest != "undefined") {
440
- xhr = new XDomainRequest();
441
- xhr.open(method, url);
442
- } else {
443
- xhr = null;
444
- }
445
- return xhr;
446
- }