@chat21/chat21-web-widget 5.0.53-rc.1 → 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.
- package/.github/workflows/docker-community-push-latest.yml +1 -0
- package/.github/workflows/docker-image-tag-community-tag-push.yml +1 -0
- package/CHANGELOG.md +8 -0
- package/Dockerfile +2 -2
- package/angular.json +3 -18
- package/deploy_amazon_beta.sh +1 -1
- package/deploy_amazon_prod.sh +1 -1
- package/package.json +17 -18
- package/src/app/app.component.scss +38 -10
- package/src/app/app.module.ts +3 -3
- package/src/app/component/conversation-detail/conversation/conversation.component.ts +0 -10
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +0 -2
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +0 -10
- package/src/app/component/form/form-builder/form-builder.component.ts +1 -1
- package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +1 -1
- package/src/app/component/form/inputs/form-label/form-label.component.ts +1 -1
- package/src/app/component/form/inputs/form-text/form-text.component.ts +2 -2
- package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +2 -2
- package/src/app/component/form/prechat-form/prechat-form.component.ts +1 -1
- package/src/app/component/message/bubble-message/bubble-message.component.html +1 -4
- package/src/app/component/message/bubble-message/bubble-message.component.ts +1 -37
- package/src/app/component/message/image/image.component.ts +1 -9
- package/src/app/component/message/info-message/info-message.component.html +3 -3
- package/src/app/component/message/info-message/info-message.component.ts +0 -10
- package/src/app/directives/tooltip.directive.spec.ts +8 -0
- package/src/app/directives/tooltip.directive.ts +46 -0
- package/src/chat21-core/providers/abstract/archivedconversations-handler.service.ts +5 -5
- package/src/chat21-core/providers/abstract/conversation-handler.service.ts +6 -6
- package/src/chat21-core/providers/abstract/conversations-handler.service.ts +6 -6
- package/src/chat21-core/providers/abstract/groups-handler.service.ts +5 -5
- package/src/chat21-core/providers/abstract/messagingAuth.service.ts +2 -2
- package/src/chat21-core/providers/abstract/presence.service.ts +2 -2
- package/src/chat21-core/providers/abstract/typing.service.ts +2 -2
- package/src/chat21-core/providers/abstract/upload.service.ts +1 -1
- package/src/chat21-core/providers/firebase/firebase-archivedconversations-handler.ts +1 -1
- package/src/chat21-core/providers/firebase/firebase-groups-handler.ts +1 -1
- package/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts +1 -1
- package/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts +0 -1
- package/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts +1 -1
- package/src/chat21-core/utils/constants.ts +3 -2
- package/src/chat21-core/utils/utils.ts +2 -0
- package/src/polyfills.ts +0 -10
- package/src/test.ts +3 -1
- package/tsconfig.json +5 -3
- package/dist/3rdpartylicenses.txt +0 -942
- package/dist/assets/i18n/en.json +0 -94
- package/dist/assets/i18n/es.json +0 -90
- package/dist/assets/i18n/fr.json +0 -90
- package/dist/assets/i18n/it.json +0 -90
- package/dist/assets/images/avatar_bot_tiledesk.svg +0 -1
- package/dist/assets/images/chat_human_avatar.svg +0 -12
- package/dist/assets/images/f21ico-done.svg +0 -1
- package/dist/assets/images/f21ico-done_all.svg +0 -1
- package/dist/assets/images/f21ico-schedule.svg +0 -1
- package/dist/assets/images/file-alt-solid.png +0 -0
- package/dist/assets/images/light_avatar_placeholder.svg +0 -1
- package/dist/assets/images/tommy_bot_tiledesk.svg +0 -48
- package/dist/assets/images/website_mockup.jpg +0 -0
- package/dist/assets/js/chat21client.js +0 -1066
- package/dist/assets/js/mqtt/4.1.0/mqtt.min.js +0 -1
- package/dist/assets/js/mqtt/4.2.6/mqtt.min.js +0 -1
- package/dist/assets/js/mqtt/4.2.8/mqtt.min.js +0 -1
- package/dist/assets/sounds/Carme.mp3 +0 -0
- package/dist/assets/sounds/justsaying.mp3 +0 -0
- package/dist/assets/sounds/pling.mp3 +0 -0
- package/dist/assets/styles/tiledesk_v1.scss +0 -22
- package/dist/assets/twp/chatbot-panel.html +0 -424
- package/dist/assets/twp/index-dev.html +0 -2430
- package/dist/assets/twp/index.html +0 -603
- package/dist/assets/twp/tiledesk_widget_files/bootstrap.min.css +0 -5
- package/dist/assets/twp/tiledesk_widget_files/bootstrap.min.js +0 -7
- package/dist/assets/twp/tiledesk_widget_files/facebook.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/font-awesome.min.css +0 -4
- package/dist/assets/twp/tiledesk_widget_files/icon +0 -23
- package/dist/assets/twp/tiledesk_widget_files/jquery.min.js +0 -2
- package/dist/assets/twp/tiledesk_widget_files/linkedin.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/logo-black.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/logo-mobile.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/logo-short.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/logo.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/logo@2x-black.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/telegram.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/twitter.png +0 -0
- package/dist/assets/twp/tiledesk_widget_files/website-poly.min.css +0 -5623
- package/dist/assets/twp/tiledesk_widget_files/whatsapp.png +0 -0
- package/dist/base_script.html +0 -57
- package/dist/environments/real_data/widget-config-docker.json +0 -28
- package/dist/environments/real_data/widget-config-firebase.json +0 -30
- package/dist/environments/real_data/widget-config-mqtt.json +0 -27
- package/dist/environments/real_data/widget-config-native-mqtt.json +0 -28
- package/dist/environments/real_data/widget-config-native-prod.json +0 -27
- package/dist/f21ico-done.svg +0 -1
- package/dist/f21ico-done_all.svg +0 -1
- package/dist/f21ico-schedule.svg +0 -1
- package/dist/favicon.ico +0 -0
- package/dist/iframe-style.css +0 -189
- package/dist/index.html +0 -16
- package/dist/launch.js +0 -371
- package/dist/main.js +0 -1
- package/dist/polyfills-es5.js +0 -1
- package/dist/polyfills.js +0 -1
- package/dist/runtime.js +0 -1
- package/dist/scripts.js +0 -1
- package/dist/styles.css +0 -1
- package/dist/styles.js +0 -1
- package/dist/test-custom-auth.html +0 -50
- package/dist/test-new.html +0 -231
- package/dist/test.html +0 -142
- package/dist/tiledesk.js +0 -72
- package/dist/vendor.js +0 -1
- package/dist/widget-config-template.json +0 -29
- package/dist/widget-config.json +0 -29
- package/e2e/protractor.conf.js +0 -32
- package/src/environments/environment.pre.ts +0 -42
- package/src/environments/environment.prod.ts +0 -40
- package/src/environments/environment.ts +0 -41
- package/src/environments/real_data/widget-config-docker.json +0 -28
- package/src/environments/real_data/widget-config-firebase.json +0 -30
- package/src/environments/real_data/widget-config-mqtt.json +0 -27
- package/src/environments/real_data/widget-config-native-mqtt.json +0 -28
- package/src/environments/real_data/widget-config-native-prod.json +0 -27
package/dist/launch.js
DELETED
|
@@ -1,371 +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
|
-
// ifrm.contentWindow.document.open();
|
|
167
|
-
ifrm.src = tiledeskScriptBaseLocation + '/base_script.html'
|
|
168
|
-
// ifrm.contentWindow.document.open();
|
|
169
|
-
// ifrm.contentWindow.document.write(srcTileDesk);
|
|
170
|
-
// ifrm.contentWindow.document.close();
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
function initAysncEvents() {
|
|
176
|
-
console.log('INIT ASYNC EVENTS')
|
|
177
|
-
|
|
178
|
-
window.tileDeskAsyncInit = function() {
|
|
179
|
-
// console.log('launch tiledeskAsyncInit:::', window.Tiledesk.q)
|
|
180
|
-
window.tiledesk.on('onLoadParams', function(event_data) {
|
|
181
|
-
if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
|
|
182
|
-
window.Tiledesk.q.forEach(f => {
|
|
183
|
-
if (f.length>=1) {
|
|
184
|
-
var functionName = f[0];
|
|
185
|
-
if (functionName==="onLoadParams") {
|
|
186
|
-
//CALLING ONLY FUNCTION 'onLoadParams'
|
|
187
|
-
if (f.length==2) {
|
|
188
|
-
var functionCallback = f[1];
|
|
189
|
-
if(typeof functionCallback === "function") {
|
|
190
|
-
window.tiledesk.on(functionName, functionCallback);
|
|
191
|
-
functionCallback(event_data);
|
|
192
|
-
} else {
|
|
193
|
-
console.error("initAysncEvents --> functionCallback is not a function.");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}else if(functionName=='setParameter'){
|
|
197
|
-
//CALLING ONLY METHOD 'setParameter' AND CHECK IF IT HAS OBJECT ARG
|
|
198
|
-
if (f.length==2) {
|
|
199
|
-
var functionArgs = f[1];
|
|
200
|
-
if(typeof functionArgs === "object") {
|
|
201
|
-
window.tiledesk[functionName](functionArgs);
|
|
202
|
-
} else {
|
|
203
|
-
console.error("initAysncEvents --> functionArgs is not a object.");
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
window.tiledesk.on('onBeforeInit', function(event_data) {
|
|
213
|
-
if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
|
|
214
|
-
// console.log("w.q", window.Tiledesk.q);
|
|
215
|
-
window.Tiledesk.q.forEach(f => {
|
|
216
|
-
if (f.length>=1) {
|
|
217
|
-
var functionName = f[0];
|
|
218
|
-
if (functionName==="onLoadParams" || functionName==="setParameter") {
|
|
219
|
-
//SKIP FUNCTION WITH NAMES 'onLoadParams' AND METHOD 'setParameter'
|
|
220
|
-
} else if (functionName.startsWith("on")) {
|
|
221
|
-
// CALLING METHOD THAT STARTS WITH 'on'
|
|
222
|
-
if (f.length==2) {
|
|
223
|
-
var functionCallback = f[1];
|
|
224
|
-
if(typeof functionCallback === "function"){
|
|
225
|
-
window.tiledesk.on(functionName, functionCallback); //potrei usare window.Tiledesk ?!?
|
|
226
|
-
if (functionName==="onBeforeInit") {
|
|
227
|
-
functionCallback(event_data)
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
console.error("functionCallback is not a function.");
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
//CALLING REMAININGS METHOD and CHECK IF CONTAINS ARG TO PASS THROUGH THE METHOD
|
|
235
|
-
if (f.length==2) {
|
|
236
|
-
let args = f[1]
|
|
237
|
-
window.tiledesk[functionName](args);
|
|
238
|
-
} else {
|
|
239
|
-
window.tiledesk[functionName]();
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// RICHIAMATO DOPO L'INIT DEL WIDGET
|
|
249
|
-
window.Tiledesk = function() {
|
|
250
|
-
if (arguments.length>=1) {
|
|
251
|
-
var functionName = arguments[0];
|
|
252
|
-
if (arguments.length==2) {
|
|
253
|
-
var functionCallback = arguments[1];
|
|
254
|
-
}
|
|
255
|
-
var methodOrProperty = window.tiledesk[functionName];
|
|
256
|
-
if(typeof methodOrProperty==="function"){
|
|
257
|
-
return window.tiledesk[functionName](functionCallback);
|
|
258
|
-
}else { //property
|
|
259
|
-
return window.tiledesk[functionName];
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
*
|
|
271
|
-
*/
|
|
272
|
-
function initWidget() {
|
|
273
|
-
var tiledeskroot = document.createElement('chat-root');
|
|
274
|
-
var tiledeskScriptLocation = document.getElementById("tiledesk-jssdk").src;
|
|
275
|
-
//var currentScript = document.currentScript;
|
|
276
|
-
//var tiledeskScriptLocation = '';
|
|
277
|
-
//setInterval(function(){
|
|
278
|
-
//tiledeskScriptLocation = currentScript.src;
|
|
279
|
-
var tiledeskScriptBaseLocation = tiledeskScriptLocation.replace("/launch.js","");
|
|
280
|
-
window.tiledesk = new function() {
|
|
281
|
-
//this.type = "macintosh";
|
|
282
|
-
this.tiledeskroot = tiledeskroot;
|
|
283
|
-
this.on = function (event_name, handler) {
|
|
284
|
-
tiledeskroot.addEventListener(event_name, handler);
|
|
285
|
-
};
|
|
286
|
-
this.getBaseLocation = function() {
|
|
287
|
-
return tiledeskScriptBaseLocation;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
try {
|
|
292
|
-
window.tileDeskAsyncInit();
|
|
293
|
-
}catch(er) {
|
|
294
|
-
if (typeof window.tileDeskAsyncInit == "undefined") {
|
|
295
|
-
console.log("tileDeskAsyncInit() doesn't exists");
|
|
296
|
-
} else {
|
|
297
|
-
console.log(er);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
document.body.appendChild(tiledeskroot);
|
|
301
|
-
initCSSWidget(tiledeskScriptBaseLocation);
|
|
302
|
-
loadIframe(tiledeskScriptBaseLocation);
|
|
303
|
-
//},2000);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
function initCSSWidget(tiledeskScriptBaseLocation) {
|
|
311
|
-
var cssId = 'iframeCss'; // you could encode the css path itself to generate id..
|
|
312
|
-
// if (!document.getElementById(cssId))
|
|
313
|
-
// {
|
|
314
|
-
var head = document.getElementsByTagName('head')[0];
|
|
315
|
-
var link = document.createElement('link');
|
|
316
|
-
link.id = cssId;
|
|
317
|
-
link.rel = 'stylesheet';
|
|
318
|
-
link.type = 'text/css';
|
|
319
|
-
link.href = tiledeskScriptBaseLocation+'/iframe-style.css';
|
|
320
|
-
link.media = 'all';
|
|
321
|
-
head.appendChild(link);
|
|
322
|
-
// }
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
//DEPRECATED
|
|
327
|
-
function signInWithCustomToken() {
|
|
328
|
-
let json = JSON.stringify({
|
|
329
|
-
"id_project": "5b55e806c93dde00143163dd"
|
|
330
|
-
});
|
|
331
|
-
var httpRequest = createCORSRequest('POST', 'https://tiledesk-server-pre.herokuapp.com/auth/signinAnonymously',true);
|
|
332
|
-
if (!httpRequest) {
|
|
333
|
-
throw new Error('CORS not supported');
|
|
334
|
-
}
|
|
335
|
-
httpRequest.setRequestHeader('Content-type','application/json');
|
|
336
|
-
httpRequest.send(json);
|
|
337
|
-
httpRequest.onload = function() {
|
|
338
|
-
if (httpRequest.readyState === XMLHttpRequest.DONE) {
|
|
339
|
-
if (httpRequest.status === 200) {
|
|
340
|
-
try {
|
|
341
|
-
var response = JSON.parse(httpRequest.responseText);
|
|
342
|
-
window.tiledesk.signInWithCustomToken(response);
|
|
343
|
-
}
|
|
344
|
-
catch(err) {
|
|
345
|
-
console.error(err.message);
|
|
346
|
-
}
|
|
347
|
-
return true;
|
|
348
|
-
} else {
|
|
349
|
-
alert('There was a problem with the request.');
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
httpRequest.onerror = function() {
|
|
354
|
-
console.error('There was an error!');
|
|
355
|
-
return false;
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
function createCORSRequest(method, url, async) {
|
|
361
|
-
var xhr = new XMLHttpRequest();
|
|
362
|
-
if ("withCredentials" in xhr) {
|
|
363
|
-
xhr.open(method, url, async);
|
|
364
|
-
} else if (typeof XDomainRequest != "undefined") {
|
|
365
|
-
xhr = new XDomainRequest();
|
|
366
|
-
xhr.open(method, url);
|
|
367
|
-
} else {
|
|
368
|
-
xhr = null;
|
|
369
|
-
}
|
|
370
|
-
return xhr;
|
|
371
|
-
}
|