@chat21/chat21-web-widget 5.0.53-rc.4 → 5.0.53
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 +3 -14
- package/package.json +1 -1
- package/src/app/app.component.ts +8 -18
- package/src/app/app.module.ts +8 -10
- package/src/app/component/conversation-detail/conversation/conversation.component.ts +1 -15
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +2 -2
- package/src/app/component/last-message/last-message.component.html +72 -83
- package/src/app/component/last-message/last-message.component.scss +42 -98
- package/src/app/component/last-message/last-message.component.spec.ts +2 -2
- package/src/app/component/last-message/last-message.component.ts +25 -49
- package/src/app/component/list-all-conversations/list-all-conversations.component.ts +1 -1
- package/src/app/component/message/bubble-message/bubble-message.component.html +5 -0
- package/src/app/component/message/html/html.component.spec.ts +1 -1
- package/src/app/component/message/info-message/info-message.component.spec.ts +1 -1
- package/src/app/component/message/text/text.component.scss +0 -4
- package/src/app/component/message/text/text.component.spec.ts +2 -2
- package/src/app/component/message-attachment/message-attachment.component.html +1 -1
- package/src/app/component/message-attachment/message-attachment.component.ts +0 -2
- package/src/app/{pipe → directives}/html-entites-encode.pipe.spec.ts +0 -0
- package/src/app/{pipe → directives}/html-entities-encode.pipe.ts +0 -0
- package/src/app/{pipe → directives}/marked.pipe.spec.ts +0 -0
- package/src/app/{pipe → directives}/marked.pipe.ts +0 -0
- package/src/app/{pipe → directives}/safe-html.pipe.spec.ts +0 -0
- package/src/app/{pipe → directives}/safe-html.pipe.ts +0 -0
- package/src/app/providers/global-settings.service.ts +12 -11
- package/src/app/utils/globals.ts +0 -3
- package/src/app/utils/rules.ts +5 -88
- package/src/assets/js/chat21client.js +4 -27
- package/src/assets/twp/index-dev.html +1 -1
- package/src/assets/twp/index.html +1 -1
- package/src/chat21-core/models/conversation.ts +2 -2
- package/src/chat21-core/models/upload.ts +0 -1
- package/src/chat21-core/providers/abstract/presence.service.ts +0 -1
- package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +106 -78
- package/src/chat21-core/providers/firebase/firebase-presence.service.ts +0 -4
- package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +29 -2
- package/src/chat21-core/providers/mqtt/mqtt-presence.service.ts +156 -13
- package/src/chat21-core/providers/tiledesk/tiledesk-requests.service.ts +4 -21
- package/src/chat21-core/utils/utils-message.ts +0 -36
- package/src/iframe-style.css +2 -2
- package/src/models/project.ts +1 -4
- package/src/app/providers/events.service.spec.ts +0 -16
- package/src/app/providers/events.service.ts +0 -76
- package/src/launch_old.js +0 -446
- package/src/models/rule.ts +0 -18
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
export type EventHandler = (...args: any[]) => any;
|
|
3
|
-
@Injectable({
|
|
4
|
-
providedIn: 'root'
|
|
5
|
-
})
|
|
6
|
-
export class EventsService {
|
|
7
|
-
private c = new Map<string, EventHandler[]>();
|
|
8
|
-
constructor() { }
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Subscribe to an event topic. Events that get posted to that topic will trigger the provided handler.
|
|
12
|
-
*
|
|
13
|
-
* @param topic the topic to subscribe to
|
|
14
|
-
* @param handler the event handler
|
|
15
|
-
*/
|
|
16
|
-
subscribe(topic: string, ...handlers: EventHandler[]) {
|
|
17
|
-
let topics = this.c.get(topic);
|
|
18
|
-
if (!topics) {
|
|
19
|
-
this.c.set(topic, topics = []);
|
|
20
|
-
}
|
|
21
|
-
topics.push(...handlers);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Unsubscribe from the given topic. Your handler will no longer receive events published to this topic.
|
|
26
|
-
*
|
|
27
|
-
* @param topic the topic to unsubscribe from
|
|
28
|
-
* @param handler the event handler
|
|
29
|
-
*
|
|
30
|
-
* @return true if a handler was removed
|
|
31
|
-
*/
|
|
32
|
-
unsubscribe(topic: string, handler?: EventHandler): boolean {
|
|
33
|
-
if (!handler) {
|
|
34
|
-
return this.c.delete(topic);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const topics = this.c.get(topic);
|
|
38
|
-
if (!topics) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// We need to find and remove a specific handler
|
|
43
|
-
const index = topics.indexOf(handler);
|
|
44
|
-
|
|
45
|
-
if (index < 0) {
|
|
46
|
-
// Wasn't found, wasn't removed
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
topics.splice(index, 1);
|
|
50
|
-
if (topics.length === 0) {
|
|
51
|
-
this.c.delete(topic);
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Publish an event to the given topic.
|
|
58
|
-
*
|
|
59
|
-
* @param topic the topic to publish to
|
|
60
|
-
* @param eventData the data to send as the event
|
|
61
|
-
*/
|
|
62
|
-
publish(topic: string, ...args: any[]): any[] | null {
|
|
63
|
-
const topics = this.c.get(topic);
|
|
64
|
-
if (!topics) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return topics.map(handler => {
|
|
68
|
-
try {
|
|
69
|
-
return handler(...args);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.error(e);
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
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
|
-
}
|
package/src/models/rule.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface IRules {
|
|
2
|
-
[id: string]:Rule[]
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export interface Rule {
|
|
6
|
-
uid: string,
|
|
7
|
-
name: string,
|
|
8
|
-
description?: string,
|
|
9
|
-
when: {
|
|
10
|
-
regexOption: string,
|
|
11
|
-
text: string,
|
|
12
|
-
urlMatches: string,
|
|
13
|
-
triggerEvery: number},
|
|
14
|
-
do: [
|
|
15
|
-
{wait: number},
|
|
16
|
-
{message: any}
|
|
17
|
-
]
|
|
18
|
-
}
|