@chat21/chat21-web-widget 5.0.53-rc.2 → 5.0.53-rc.3
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 +9 -0
- package/angular.json +3 -4
- package/karma.conf.js +1 -0
- package/package.json +5 -5
- package/src/app/app-routing.module.ts +1 -1
- package/src/assets/twp/index-dev.html +3 -3
- package/src/assets/twp/index.html +4 -4
- package/src/chat21-core/providers/abstract/notifications.service.ts +1 -1
- package/src/chat21-core/providers/firebase/firebase-notifications.ts +1 -1
- package/src/chat21-core/providers/mqtt/mqtt-notifications.ts +1 -1
- package/src/launch.js +10 -6
- package/src/launch_old.js +446 -0
- package/src/main.ts +1 -0
- package/src/base_script.html +0 -57
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# chat21-web-widget ver 5.0
|
|
2
2
|
|
|
3
|
+
### 5.0.53-rc.3
|
|
4
|
+
- added: html descriptions to index.html and index-dev.html
|
|
5
|
+
- changed: script tag for style.css to link tag with rel="stylesheet"
|
|
6
|
+
- changed: binding to tiledesk iframe from scr to srcdoc
|
|
7
|
+
- removed: base_script.html
|
|
8
|
+
- removed: jquery plugin
|
|
9
|
+
- removed: relativeLinkResolution from forRoot in RooterModule
|
|
10
|
+
|
|
11
|
+
|
|
3
12
|
### 5.0.53-rc.2
|
|
4
13
|
- added: angular 15 engine
|
|
5
14
|
- added: custom tooltip directive
|
package/angular.json
CHANGED
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
],
|
|
47
47
|
"scripts": [
|
|
48
48
|
"src/assets/js/mqtt/4.2.6/mqtt.min.js",
|
|
49
|
-
"node_modules/jquery/dist/jquery.min.js",
|
|
50
49
|
"node_modules/bootstrap/dist/js/bootstrap.min.js",
|
|
51
50
|
"node_modules/popper.js/dist/umd/popper.min.js"
|
|
52
51
|
],
|
|
@@ -55,7 +54,8 @@
|
|
|
55
54
|
"buildOptimizer": false,
|
|
56
55
|
"allowedCommonJsDependencies": [
|
|
57
56
|
"rxjs-compat",
|
|
58
|
-
"moment"
|
|
57
|
+
"moment",
|
|
58
|
+
"idb"
|
|
59
59
|
],
|
|
60
60
|
"sourceMap": true,
|
|
61
61
|
"optimization": false,
|
|
@@ -142,8 +142,7 @@
|
|
|
142
142
|
"test": {
|
|
143
143
|
"builder": "@angular-devkit/build-angular:karma",
|
|
144
144
|
"options": {
|
|
145
|
-
"
|
|
146
|
-
"polyfills": "src/polyfills.ts",
|
|
145
|
+
"polyfills": ["zone.js", "zone.js/testing"],
|
|
147
146
|
"tsConfig": "tsconfig.spec.json",
|
|
148
147
|
"karmaConfig": "karma.conf.js",
|
|
149
148
|
"assets": [
|
package/karma.conf.js
CHANGED
|
@@ -7,6 +7,7 @@ module.exports = function (config) {
|
|
|
7
7
|
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
8
8
|
plugins: [
|
|
9
9
|
require('karma-jasmine'),
|
|
10
|
+
require('karma-coverage'),
|
|
10
11
|
require('karma-chrome-launcher'),
|
|
11
12
|
require('karma-jasmine-html-reporter'),
|
|
12
13
|
require('karma-coverage-istanbul-reporter'),
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chat21/chat21-web-widget",
|
|
3
3
|
"author": "Tiledesk SRL",
|
|
4
|
-
"version": "5.0.53-rc.
|
|
5
|
-
"license": "MIT
|
|
4
|
+
"version": "5.0.53-rc.3",
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.tiledesk.com",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@angular/platform-browser": "^15.0.4",
|
|
29
29
|
"@angular/platform-browser-dynamic": "^15.0.4",
|
|
30
30
|
"@angular/router": "^15.0.4",
|
|
31
|
-
"@ctrl/ngx-emoji-mart": "^
|
|
31
|
+
"@ctrl/ngx-emoji-mart": "^7.1.0",
|
|
32
32
|
"@ngx-translate/core": "^14.0.0",
|
|
33
33
|
"@ngx-translate/http-loader": "^4.0.0",
|
|
34
34
|
"@popperjs/core": "^2.11.5",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"file-saver": "^2.0.5",
|
|
39
39
|
"firebase": "^8.6.7",
|
|
40
40
|
"humanize-duration-ts": "^2.1.1",
|
|
41
|
-
"jquery": "^3.6.0",
|
|
42
41
|
"marked": "^4.0.16",
|
|
43
42
|
"moment": "^2.29.3",
|
|
44
43
|
"ngx-logger": "^5.0.11",
|
|
@@ -62,12 +61,13 @@
|
|
|
62
61
|
"jasmine-spec-reporter": "~5.0.0",
|
|
63
62
|
"karma": "~6.3.20",
|
|
64
63
|
"karma-chrome-launcher": "~3.1.0",
|
|
64
|
+
"karma-coverage": "^2.2.0",
|
|
65
65
|
"karma-coverage-istanbul-reporter": "~3.0.2",
|
|
66
66
|
"karma-jasmine": "~4.0.0",
|
|
67
67
|
"karma-jasmine-html-reporter": "^1.5.0",
|
|
68
68
|
"protractor": "~7.0.0",
|
|
69
69
|
"ts-node": "~7.0.0",
|
|
70
70
|
"tslint": "~6.1.0",
|
|
71
|
-
"typescript": "4.8.4"
|
|
71
|
+
"typescript": "^4.8.4"
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -5,7 +5,7 @@ import { Routes, RouterModule } from '@angular/router';
|
|
|
5
5
|
const routes: Routes = [];
|
|
6
6
|
|
|
7
7
|
@NgModule({
|
|
8
|
-
imports: [RouterModule.forRoot(routes
|
|
8
|
+
imports: [RouterModule.forRoot(routes)],
|
|
9
9
|
exports: [RouterModule]
|
|
10
10
|
})
|
|
11
11
|
export class AppRoutingModule { }
|
|
@@ -383,10 +383,10 @@
|
|
|
383
383
|
}
|
|
384
384
|
</script> -->
|
|
385
385
|
|
|
386
|
-
<meta property="og:title" content="
|
|
387
|
-
<meta property="og:description" content=""
|
|
386
|
+
<meta property="og:title" content="Try Tiledesk now!" />
|
|
387
|
+
<meta property="og:description" content="Qualify your leads to increase your sales faster. It's really easy to do it with the Tiledesk conversational form builder" />
|
|
388
|
+
<meta property="og:image" content="https://tiledesk.com/wp-content/uploads/2022/12/6029654-02-min.png" />
|
|
388
389
|
<meta property="og:locale" content="en">
|
|
389
|
-
<meta property="og:image" content="">
|
|
390
390
|
|
|
391
391
|
<link rel="icon" type="image/png" href="./tiledesk_widget_files/logo-short.png">
|
|
392
392
|
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
|
@@ -217,10 +217,10 @@
|
|
|
217
217
|
}
|
|
218
218
|
</script> -->
|
|
219
219
|
|
|
220
|
-
<meta property="og:title" content="
|
|
221
|
-
<meta property="og:description" content=""
|
|
220
|
+
<meta property="og:title" content="Try Tiledesk now!" />
|
|
221
|
+
<meta property="og:description" content="Qualify your leads to increase your sales faster. It's really easy to do it with the Tiledesk conversational form builder" />
|
|
222
|
+
<meta property="og:image" content="https://tiledesk.com/wp-content/uploads/2022/12/6029654-02-min.png" />
|
|
222
223
|
<meta property="og:locale" content="en">
|
|
223
|
-
<meta property="og:image" content="">
|
|
224
224
|
|
|
225
225
|
<link rel="icon" type="image/png" href="./tiledesk_widget_files/logo-short.png">
|
|
226
226
|
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
|
|
@@ -563,7 +563,7 @@
|
|
|
563
563
|
<div class="b-agent-demo_powered_by">
|
|
564
564
|
<a href="https://console.tiledesk.com/" target="_blank" style="cursor: pointer;text-decoration: none;">
|
|
565
565
|
<span style="position: relative; top: 2px;">Powered by</span>
|
|
566
|
-
<img src="./tiledesk_widget_files/logo@2x-black.png">
|
|
566
|
+
<img src="./tiledesk_widget_files/logo@2x-black.png" alt="Tiledesk">
|
|
567
567
|
</a>
|
|
568
568
|
</div>
|
|
569
569
|
</footer>
|
|
@@ -6,7 +6,7 @@ import { Injectable } from '@angular/core';
|
|
|
6
6
|
export abstract class NotificationsService {
|
|
7
7
|
|
|
8
8
|
private _tenant: string;
|
|
9
|
-
|
|
9
|
+
public BUILD_VERSION = environment.version
|
|
10
10
|
|
|
11
11
|
public setTenant(tenant): void {
|
|
12
12
|
this._tenant = tenant;
|
|
@@ -14,7 +14,7 @@ import { LoggerService } from '../abstract/logger.service';
|
|
|
14
14
|
@Injectable()
|
|
15
15
|
export class FirebaseNotifications extends NotificationsService {
|
|
16
16
|
|
|
17
|
-
public BUILD_VERSION: string;
|
|
17
|
+
// public BUILD_VERSION: string;
|
|
18
18
|
private FCMcurrentToken: string;
|
|
19
19
|
private userId: string;
|
|
20
20
|
private tenant: string;
|
|
@@ -15,7 +15,7 @@ import { Chat21Service } from './chat-service';
|
|
|
15
15
|
@Injectable()
|
|
16
16
|
export class MQTTNotifications extends NotificationsService {
|
|
17
17
|
|
|
18
|
-
public BUILD_VERSION: string;
|
|
18
|
+
// public BUILD_VERSION: string;
|
|
19
19
|
private FCMcurrentToken: string;
|
|
20
20
|
private userId: string;
|
|
21
21
|
private tenant: string;
|
package/src/launch.js
CHANGED
|
@@ -32,6 +32,7 @@ function loadIframe(tiledeskScriptBaseLocation) {
|
|
|
32
32
|
var ifrm = document.createElement("iframe");
|
|
33
33
|
ifrm.setAttribute("frameborder", "0");
|
|
34
34
|
ifrm.setAttribute("border", "0");
|
|
35
|
+
ifrm.setAttribute("title", "Tiledesk Widget")
|
|
35
36
|
|
|
36
37
|
var srcTileDesk = '<html lang="en">';
|
|
37
38
|
srcTileDesk += '<head>';
|
|
@@ -46,7 +47,7 @@ function loadIframe(tiledeskScriptBaseLocation) {
|
|
|
46
47
|
srcTileDesk += '<chat-root></chat-root>';
|
|
47
48
|
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/runtime.js"></script>';
|
|
48
49
|
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/polyfills.js"></script>';
|
|
49
|
-
srcTileDesk += '<
|
|
50
|
+
srcTileDesk += '<link type="text/css" rel="stylesheet" href="'+tiledeskScriptBaseLocation+'/styles.css" media="all"></link>';
|
|
50
51
|
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/vendor.js"></script>';
|
|
51
52
|
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/main.js"></script>';
|
|
52
53
|
srcTileDesk += '</body>';
|
|
@@ -163,11 +164,14 @@ function loadIframe(tiledeskScriptBaseLocation) {
|
|
|
163
164
|
|
|
164
165
|
iDiv.appendChild(ifrm);
|
|
165
166
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
if(tiledeskScriptBaseLocation.includes('localhost')){
|
|
168
|
+
ifrm.contentWindow.document.open();
|
|
169
|
+
ifrm.contentWindow.document.write(srcTileDesk);
|
|
170
|
+
ifrm.contentWindow.document.close();
|
|
171
|
+
}else {
|
|
172
|
+
ifrm.srcdoc = srcTileDesk
|
|
173
|
+
}
|
|
174
|
+
|
|
171
175
|
|
|
172
176
|
}
|
|
173
177
|
|
|
@@ -0,0 +1,446 @@
|
|
|
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
|
+
}
|
package/src/main.ts
CHANGED
package/src/base_script.html
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<html lang="en">
|
|
2
|
-
<head>
|
|
3
|
-
<meta charset="utf-8">
|
|
4
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
|
5
|
-
<title>Tilechat Widget</title>
|
|
6
|
-
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
7
|
-
<script>
|
|
8
|
-
var tiledeskScriptBaseLocation = window.location.href.replace("/base_script.html","");
|
|
9
|
-
|
|
10
|
-
var link_2 = document.createElement('link')
|
|
11
|
-
link_2.setAttribute('rel', 'stylesheet')
|
|
12
|
-
link_2.setAttribute('type', 'text/css')
|
|
13
|
-
link_2.setAttribute('href', tiledeskScriptBaseLocation + '/assets/styles/tiledesk_v1.scss')
|
|
14
|
-
link_2.setAttribute('media','all')
|
|
15
|
-
|
|
16
|
-
var script_1 = document.createElement('script')
|
|
17
|
-
script_1.setAttribute('type','text/javascript')
|
|
18
|
-
script_1.setAttribute('src',tiledeskScriptBaseLocation + '/runtime.js')
|
|
19
|
-
var script_2 = document.createElement('script')
|
|
20
|
-
script_2.setAttribute('type','text/javascript')
|
|
21
|
-
script_2.setAttribute('src',tiledeskScriptBaseLocation + '/polyfills.js')
|
|
22
|
-
var link = document.createElement('link')
|
|
23
|
-
link.setAttribute('type','text/css')
|
|
24
|
-
link.setAttribute('rel','stylesheet')
|
|
25
|
-
link.setAttribute('href',tiledeskScriptBaseLocation + '/styles.css')
|
|
26
|
-
link.setAttribute('media','all')
|
|
27
|
-
var script_4 = document.createElement('script')
|
|
28
|
-
script_4.setAttribute('type','text/javascript')
|
|
29
|
-
script_4.setAttribute('src',tiledeskScriptBaseLocation + '/vendor.js')
|
|
30
|
-
var script_5 = document.createElement('script')
|
|
31
|
-
script_5.setAttribute('type','text/javascript')
|
|
32
|
-
script_5.setAttribute('src',tiledeskScriptBaseLocation + '/main.js')
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
window.addEventListener("load", (event) => {
|
|
36
|
-
|
|
37
|
-
let head = document.getElementsByTagName('head')[0]
|
|
38
|
-
head.appendChild(link_2)
|
|
39
|
-
|
|
40
|
-
let body = document.getElementsByTagName('body')[0]
|
|
41
|
-
body.appendChild(script_1)
|
|
42
|
-
body.appendChild(script_2)
|
|
43
|
-
body.appendChild(link)
|
|
44
|
-
body.appendChild(script_4)
|
|
45
|
-
body.appendChild(script_5)
|
|
46
|
-
});
|
|
47
|
-
</script>
|
|
48
|
-
</head>
|
|
49
|
-
<body>
|
|
50
|
-
<chat-root></chat-root>
|
|
51
|
-
<!-- <script type="text/javascript" src="http://localhost:4202/runtime.js"></script>
|
|
52
|
-
<script type="text/javascript" src="http://localhost:4202/polyfills.js"></script>
|
|
53
|
-
<script type="text/css" src="http://localhost:4202/styles.css"></script>
|
|
54
|
-
<script type="text/javascript" src="http://localhost:4202/vendor.js"></script>
|
|
55
|
-
<script type="text/javascript" src="http://localhost:4202/main.js"></script> -->
|
|
56
|
-
</body>
|
|
57
|
-
</html>
|