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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/package.json +1 -1
  3. package/src/app/app.component.html +1 -1
  4. package/src/app/app.component.ts +18 -8
  5. package/src/app/app.module.ts +10 -8
  6. package/src/app/component/conversation-detail/conversation/conversation.component.ts +15 -1
  7. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +2 -2
  8. package/src/app/component/form/inputs/form-text/form-text.component.scss +2 -0
  9. package/src/app/component/last-message/last-message.component.html +83 -72
  10. package/src/app/component/last-message/last-message.component.scss +119 -42
  11. package/src/app/component/last-message/last-message.component.spec.ts +2 -2
  12. package/src/app/component/last-message/last-message.component.ts +49 -25
  13. package/src/app/component/list-all-conversations/list-all-conversations.component.ts +1 -1
  14. package/src/app/component/message/bubble-message/bubble-message.component.html +0 -5
  15. package/src/app/component/message/html/html.component.spec.ts +1 -1
  16. package/src/app/component/message/info-message/info-message.component.spec.ts +1 -1
  17. package/src/app/component/message/text/text.component.scss +4 -0
  18. package/src/app/component/message/text/text.component.spec.ts +2 -2
  19. package/src/app/component/message-attachment/message-attachment.component.html +1 -1
  20. package/src/app/component/message-attachment/message-attachment.component.ts +2 -0
  21. package/src/app/{directives → pipe}/html-entites-encode.pipe.spec.ts +0 -0
  22. package/src/app/{directives → pipe}/html-entities-encode.pipe.ts +0 -0
  23. package/src/app/{directives → pipe}/marked.pipe.spec.ts +0 -0
  24. package/src/app/{directives → pipe}/marked.pipe.ts +0 -0
  25. package/src/app/{directives → pipe}/safe-html.pipe.spec.ts +0 -0
  26. package/src/app/{directives → pipe}/safe-html.pipe.ts +0 -0
  27. package/src/app/providers/events.service.spec.ts +16 -0
  28. package/src/app/providers/events.service.ts +76 -0
  29. package/src/app/providers/global-settings.service.ts +11 -12
  30. package/src/app/utils/globals.ts +4 -1
  31. package/src/app/utils/rules.ts +88 -5
  32. package/src/assets/js/chat21client.js +27 -4
  33. package/src/assets/twp/chatbot-panel.html +0 -5
  34. package/src/assets/twp/index-dev.html +1 -1
  35. package/src/assets/twp/index.html +6 -6
  36. package/src/chat21-core/models/conversation.ts +2 -2
  37. package/src/chat21-core/models/upload.ts +1 -0
  38. package/src/chat21-core/providers/abstract/presence.service.ts +1 -0
  39. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +78 -106
  40. package/src/chat21-core/providers/firebase/firebase-presence.service.ts +4 -0
  41. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +2 -29
  42. package/src/chat21-core/providers/mqtt/mqtt-presence.service.ts +13 -156
  43. package/src/chat21-core/providers/tiledesk/tiledesk-requests.service.ts +21 -4
  44. package/src/chat21-core/utils/utils-message.ts +36 -0
  45. package/src/iframe-style.css +2 -2
  46. package/src/models/project.ts +4 -1
  47. package/src/models/rule.ts +19 -0
@@ -28,7 +28,7 @@ import {
28
28
  conversationMessagesRef
29
29
  } from '../../utils/utils';
30
30
  import { v4 as uuidv4 } from 'uuid';
31
- import { messageType, checkIfIsMemberJoinedGroup, hideInfoMessage, isJustRecived } from '../../utils/utils-message';
31
+ import { messageType, checkIfIsMemberJoinedGroup, hideInfoMessage, isJustRecived, isSender } from '../../utils/utils-message';
32
32
 
33
33
  // @Injectable({ providedIn: 'root' })
34
34
  @Injectable()
@@ -187,7 +187,6 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
187
187
  type: typeMsg,
188
188
  attributes: attributes,
189
189
  channel_type: channelType
190
- // isSender: true
191
190
  });
192
191
 
193
192
  // const message = new MessageModel(
@@ -310,7 +309,7 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
310
309
  // }
311
310
 
312
311
  // verifico che il sender è il logged user
313
- msg.isSender = this.isSender(msg.sender, this.loggedUser.uid);
312
+ msg.isSender = isSender(msg.sender, this.loggedUser.uid);
314
313
  //check if message contains only an emojii
315
314
  // msg.emoticon = isEmojii(msg.text)
316
315
 
@@ -335,7 +334,7 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
335
334
  // }
336
335
 
337
336
  // verifico che il sender è il logged user
338
- msg.isSender = this.isSender(msg.sender, this.loggedUser.uid);
337
+ msg.isSender = isSender(msg.sender, this.loggedUser.uid);
339
338
  //check if message contains only an emojii
340
339
  // msg.emoticon = isEmojii(msg.text)
341
340
 
@@ -453,118 +452,91 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
453
452
  }
454
453
  }
455
454
 
456
- /**
457
- * controllo se il messaggio è stato inviato da loggerUser
458
- * richiamato dalla pagina elenco messaggi della conversazione
459
- */
460
- private isSender(sender: string, currentUserId: string) {
461
- if (currentUserId) {
462
- if (sender === currentUserId) {
463
- return true;
464
- } else {
465
- return false;
455
+
456
+ unsubscribe(key: string) {
457
+ this.listSubsriptions.forEach(sub => {
458
+ this.logger.debug('[FIREBASEConversationHandlerSERVICE] unsubscribe: ', sub.uid, key);
459
+ if (sub.uid === key) {
460
+ this.logger.debug('[FIREBASEConversationHandlerSERVICE] unsubscribe: ', sub.uid, key);
461
+ sub.unsubscribe(key, null);
462
+ return;
466
463
  }
467
- } else {
468
- return false;
469
- }
464
+ });
470
465
  }
471
466
 
472
467
 
473
- /** */
474
- // updateMetadataMessage(uid: string, metadata: any) {
475
- // metadata.status = true;
476
- // const message = {
477
- // metadata: metadata
478
- // };
479
- // const firebaseMessages = firebase.database().ref(this.urlNodeFirebase + uid);
480
- // firebaseMessages.set(message);
481
- // }
482
-
483
-
484
- unsubscribe(key: string) {
485
- this.listSubsriptions.forEach(sub => {
486
- this.logger.debug('[FIREBASEConversationHandlerSERVICE] unsubscribe: ', sub.uid, key);
487
- if (sub.uid === key) {
488
- this.logger.debug('[FIREBASEConversationHandlerSERVICE] unsubscribe: ', sub.uid, key);
489
- sub.unsubscribe(key, null);
490
- return;
491
- }
492
- });
493
- }
494
-
495
-
496
- private addCommandMessage(msg: MessageModel){
497
- const that = this;
498
- const commands = msg.attributes.commands;
499
- let i=0;
500
- function execute(command){
501
- if(command.type === "message"){
502
- that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> type="message"', command, i)
503
- if (i >= 2) {
504
-
505
- //check if previus wait message type has time value, otherwize set to 1000ms
506
- !commands[i-1].time? commands[i-1].time= 1000 : commands[i-1].time
507
- command.message.timestamp = commands[i-2].message.timestamp + commands[i-1].time;
508
-
509
- /** CHECK IF MESSAGE IS JUST RECEIVED: IF false, set next message time (if object exist) to 0 -> this allow to show it immediately */
510
- if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
511
- let previewsTimeMsg = msg.timestamp;
512
- commands[i-2]? previewsTimeMsg = commands[i-2].message.timestamp : null;
513
- command.message.timestamp = previewsTimeMsg + 100
514
- commands[i+1]? commands[i+1].time = 0 : null
515
- }
516
- } else { /**MANAGE FIRST MESSAGE */
517
- command.message.timestamp = msg.timestamp;
518
- if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
519
- commands[i+1]? commands[i+1].time = 0 : null
520
- }
521
- }
522
- that.generateMessageObject(msg, command.message, function () {
523
- i += 1
524
- if (i < commands.length) {
525
- execute(commands[i])
468
+ private addCommandMessage(msg: MessageModel){
469
+ const that = this;
470
+ const commands = msg.attributes.commands;
471
+ let i=0;
472
+ function execute(command){
473
+ if(command.type === "message"){
474
+ that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> type="message"', command, i)
475
+ if (i >= 2) {
476
+
477
+ //check if previus wait message type has time value, otherwize set to 1000ms
478
+ !commands[i-1].time? commands[i-1].time= 1000 : commands[i-1].time
479
+ command.message.timestamp = commands[i-2].message.timestamp + commands[i-1].time;
480
+
481
+ /** CHECK IF MESSAGE IS JUST RECEIVED: IF false, set next message time (if object exist) to 0 -> this allow to show it immediately */
482
+ if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
483
+ let previewsTimeMsg = msg.timestamp;
484
+ commands[i-2]? previewsTimeMsg = commands[i-2].message.timestamp : null;
485
+ command.message.timestamp = previewsTimeMsg + 100
486
+ commands[i+1]? commands[i+1].time = 0 : null
487
+ }
488
+ } else { /**MANAGE FIRST MESSAGE */
489
+ command.message.timestamp = msg.timestamp;
490
+ if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
491
+ commands[i+1]? commands[i+1].time = 0 : null
492
+ }
526
493
  }
527
- else {
528
- that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> last command executed (wait), exit')
494
+ that.generateMessageObject(msg, command.message, function () {
495
+ i += 1
496
+ if (i < commands.length) {
497
+ execute(commands[i])
498
+ }
499
+ else {
500
+ that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> last command executed (wait), exit')
501
+ }
502
+ })
503
+ }else if(command.type === "wait"){
504
+ that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> type="wait"', command, i, commands.length)
505
+ //publish waiting event to simulate user typing
506
+ if(isJustRecived(that.startTime.getTime(), msg.timestamp)){
507
+ that.messageWait.next({uid: that.conversationWith, uidUserTypingNow: msg.sender, nameUserTypingNow: msg.sender_fullname, waitTime: command.time, command: command})
529
508
  }
530
- })
531
- }else if(command.type === "wait"){
532
- that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> type="wait"', command, i, commands.length)
533
- //publish waiting event to simulate user typing
534
- if(isJustRecived(that.startTime.getTime(), msg.timestamp)){
535
- that.messageWait.next({uid: that.conversationWith, uidUserTypingNow: msg.sender, nameUserTypingNow: msg.sender_fullname, waitTime: command.time, command: command})
509
+ setTimeout(function() {
510
+ i += 1
511
+ if (i < commands.length) {
512
+ execute(commands[i])
513
+ }
514
+ else {
515
+ that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> last command executed (send message), exit')
516
+ }
517
+ },command.time)
536
518
  }
537
- setTimeout(function() {
538
- i += 1
539
- if (i < commands.length) {
540
- execute(commands[i])
541
- }
542
- else {
543
- that.logger.debug('[FIREBASEConversationHandlerSERVICE] addCommandMessage --> last command executed (send message), exit')
544
- }
545
- },command.time)
546
519
  }
520
+ execute(commands[0]) //START render first message
547
521
  }
548
- execute(commands[0]) //START render first message
549
- }
550
522
 
551
- private generateMessageObject(message, command_message, callback) {
552
- let parentUid = message.uid
553
- command_message.uid = uuidv4();
554
- if(command_message.text) command_message.text = command_message.text.trim()//remove black msg with only spaces
555
- command_message.language = message.language;
556
- command_message.recipient = message.recipient;
557
- command_message.recipient_fullname = message.recipient_fullname;
558
- command_message.sender = message.sender;
559
- command_message.sender_fullname = message.sender_fullname;
560
- command_message.channel_type = message.channel_type;
561
- command_message.status = message.status;
562
- command_message.isSender = message.isSender;
563
- command_message.attributes? command_message.attributes.commands = true : command_message.attributes = {commands : true}
564
- command_message.attributes.parentUid = parentUid //added to manage message STATUS UPDATES
565
- this.addedNew(command_message)
566
- callback();
567
- }
523
+ private generateMessageObject(message, command_message, callback) {
524
+ let parentUid = message.uid
525
+ command_message.uid = uuidv4();
526
+ if(command_message.text) command_message.text = command_message.text.trim()//remove black msg with only spaces
527
+ command_message.language = message.language;
528
+ command_message.recipient = message.recipient;
529
+ command_message.recipient_fullname = message.recipient_fullname;
530
+ command_message.sender = message.sender;
531
+ command_message.sender_fullname = message.sender_fullname;
532
+ command_message.channel_type = message.channel_type;
533
+ command_message.status = message.status;
534
+ command_message.isSender = message.isSender;
535
+ command_message.attributes? command_message.attributes.commands = true : command_message.attributes = {commands : true}
536
+ command_message.attributes.parentUid = parentUid //added to manage message STATUS UPDATES
537
+ this.addedNew(command_message)
538
+ callback();
539
+ }
568
540
 
569
541
 
570
542
  private isValidMessage(msgToCkeck:MessageModel): boolean{
@@ -180,4 +180,8 @@ export class FirebasePresenceService extends PresenceService {
180
180
  return connectionsRef;
181
181
  }
182
182
 
183
+ public imHere(){
184
+ //NOT IMPLEMENTED FOR FIREBASE ENGINE
185
+ }
186
+
183
187
  }
@@ -24,7 +24,7 @@ import {
24
24
  conversationMessagesRef
25
25
  } from '../../utils/utils';
26
26
  import { v4 as uuidv4 } from 'uuid';
27
- import { messageType, checkIfIsMemberJoinedGroup, hideInfoMessage, isJustRecived } from '../../utils/utils-message';
27
+ import { messageType, checkIfIsMemberJoinedGroup, hideInfoMessage, isJustRecived, isSender } from '../../utils/utils-message';
28
28
 
29
29
 
30
30
  // @Injectable({ providedIn: 'root' })
@@ -308,7 +308,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
308
308
  // }
309
309
  // verifico che il sender è il logged user
310
310
  this.logger.log("[MQTTConversationHandlerSERVICE] ****>msg.sender:" + msg.sender);
311
- msg.isSender = this.isSender(msg.sender, this.loggedUser.uid);
311
+ msg.isSender = isSender(msg.sender, this.loggedUser.uid);
312
312
  // traduco messaggi se sono del server
313
313
  if (messageType(MESSAGE_TYPE_INFO, msg)) {
314
314
  this.translateInfoSupportMessages(msg);
@@ -420,33 +420,6 @@ export class MQTTConversationHandler extends ConversationHandlerService {
420
420
  }
421
421
  }
422
422
 
423
- /**
424
- * controllo se il messaggio è stato inviato da loggerUser
425
- * richiamato dalla pagina elenco messaggi della conversazione
426
- */
427
- private isSender(sender: string, currentUserId: string) {
428
- if (currentUserId) {
429
- if (sender === currentUserId) {
430
- return true;
431
- } else {
432
- return false;
433
- }
434
- } else {
435
- return false;
436
- }
437
- }
438
-
439
-
440
- /** */
441
- // updateMetadataMessage(uid: string, metadata: any) {
442
- // metadata.status = true;
443
- // const message = {
444
- // metadata: metadata
445
- // };
446
- // const firebaseMessages = firebase.database().ref(this.urlNodeFirebase + uid);
447
- // firebaseMessages.set(message);
448
- // }
449
-
450
423
 
451
424
  unsubscribe(key: string) {
452
425
  this.logger.log('[MQTTConversationHandlerSERVICE] unsubscribe: ', key);
@@ -1,3 +1,4 @@
1
+ import { Chat21Service } from 'src/chat21-core/providers/mqtt/chat-service';
1
2
  import { Injectable } from '@angular/core';
2
3
  import { BehaviorSubject, Observable } from 'rxjs';
3
4
 
@@ -19,6 +20,7 @@ import { LoggerInstance } from '../logger/loggerInstance';
19
20
  // @Injectable({ providedIn: 'root' })
20
21
  @Injectable()
21
22
  export class MQTTPresenceService extends PresenceService {
23
+
22
24
 
23
25
  // BehaviorSubject
24
26
  BSIsOnline: BehaviorSubject<any> = new BehaviorSubject<any>(null);
@@ -30,7 +32,7 @@ export class MQTTPresenceService extends PresenceService {
30
32
  private logger: LoggerService = LoggerInstance.getInstance();
31
33
 
32
34
  constructor(
33
- // private events: EventsService
35
+ public chat21Service: Chat21Service
34
36
  ) {
35
37
  super();
36
38
  }
@@ -47,40 +49,11 @@ export class MQTTPresenceService extends PresenceService {
47
49
  }
48
50
 
49
51
  lastOnlineForUser(userid: string) {
50
- // console.log('lastOnlineForUser', userid);
51
- // const that = this;
52
- // const urlNodeLastOnLine = this.urlNodePresence + userid + '/lastOnline';
53
- // console.log('urlNodeLastOnLine: ', urlNodeLastOnLine);
54
- // const lastOnlineRef = firebase.database().ref().child(urlNodeLastOnLine);
55
- // lastOnlineRef.on('value', (child) => {
56
- // if (child.val()) {
57
- // that.events.publish('last-connection-date-' + userid, userid, child.val());
58
- // } else {
59
- // that.events.publish('last-connection-date-' + userid, userid, '');
60
- // }
61
- // });
52
+
62
53
  }
63
54
 
64
55
  public setPresence(userid: string): void {
65
- // console.log(' setPresence: ', userid);
66
- // this.onlineConnectionsRef = this.referenceOnlineForUser(userid);
67
- // this.lastOnlineConnectionsRef = this.referenceLastOnlineForUser(userid);
68
- // const connectedRefURL = '/.info/connected';
69
- // const conn = firebase.database().ref(connectedRefURL);
70
- // conn.on('value', (dataSnapshot) => {
71
- // // console.log('self.deviceConnectionRef: ', dataSnapshot.val());
72
- // if (dataSnapshot.val()) {
73
- // if (this.onlineConnectionsRef) {
74
- // this.keyConnectionRef = this.onlineConnectionsRef.push(true);
75
- // this.keyConnectionRef.onDisconnect().remove();
76
- // const now: Date = new Date();
77
- // const timestamp = now.valueOf();
78
- // this.lastOnlineConnectionsRef.onDisconnect().set(timestamp);
79
- // } else {
80
- // console.log('This is an error. self.deviceConnectionRef already set. Cannot be set again.');
81
- // }
82
- // }
83
- // });
56
+
84
57
  }
85
58
 
86
59
  /**
@@ -88,130 +61,14 @@ export class MQTTPresenceService extends PresenceService {
88
61
  * richiamato prima del logout
89
62
  */
90
63
  public removePresence(): void {
91
- // if (this.onlineConnectionsRef) {
92
- // const now: Date = new Date();
93
- // const timestamp = now.valueOf();
94
- // this.lastOnlineConnectionsRef.set(timestamp);
95
- // this.onlineConnectionsRef.off();
96
- // this.onlineConnectionsRef.remove();
97
- // console.log('goOffline onlineConnectionsRef', this.onlineConnectionsRef);
98
- // }
99
- }
100
-
101
- }
102
-
103
-
104
- /**
105
- * controlla se esiste una connessione per l'utente analizzato,
106
- * verificando se esiste un nodo in presence/uid/connections
107
- * mi sottosrivo al nodo
108
- * se non esiste pubblico utente offline
109
- * se esiste pubblico utente online
110
- * @param userid
111
- */
112
-
113
-
114
- /**
115
- * mi sottoscrivo al nodo presence/uid/lastOnline
116
- * e recupero la data dell'ultimo stato online
117
- * pubblico lastConnectionDate
118
- * @param userid
119
- */
120
-
121
-
122
- /**
123
- * calcolo tempo trascorso tra ora e timestamp passato
124
- * @param timestamp
125
- */
126
64
 
65
+ }
127
66
 
128
- // /**
129
- // * recupero la reference di lastOnline del currentUser
130
- // * usata in setupMyPresence
131
- // * @param userid
132
- // */
133
- // lastOnlineRefForUser(userid){
134
- // let lastOnlineRefURL = this.urlNodeFirebase+"/presence/"+userid+"/lastOnline";
135
- // const lastOnlineRef = firebase.database().ref().child(lastOnlineRefURL);
136
- // return lastOnlineRef;
137
- // }
138
-
139
- // /**
140
- // * recupero la reference di connections (online/offline) del currentUser
141
- // * usata in setupMyPresence
142
- // * @param userid
143
- // */
144
- // onlineRefForUser(userid){
145
- // let myConnectionsRefURL = this.urlNodeFirebase+"/presence/"+userid+"/connections";
146
- // const connectionsRef = firebase.database().ref().child(myConnectionsRefURL);
147
- // return connectionsRef;
148
- // }
149
-
150
- // /**
151
- // * 1 - imposto reference online/offline
152
- // * 2 - imposto reference lastConnection
153
- // * 3 - mi sincronizzo con /.info/connected
154
- // * 4 - se il valore esiste l'utente è online
155
- // * 5 - aggiungo nodo a connection (true)
156
- // * 6 - aggiungo job su onDisconnect di deviceConnectionRef che rimuove nodo connection
157
- // * 7 - aggiungo job su onDisconnect di lastOnlineRef che imposta timestamp
158
- // * 8 - salvo reference connected nel singlelton !!!!! DA FARE
159
- // * @param userid
160
- // */
161
- // setupMyPresence(userid){
162
- // let that = this;
163
- // this.myConnectionsRef = this.onlineRefForUser(userid);
164
- // this.lastOnlineRef = this.lastOnlineRefForUser(userid);
165
- // let connectedRefURL = "/.info/connected";
166
- // let conn = firebase.database().ref(connectedRefURL);
167
- // conn.on('value', function(dataSnapshot) {
168
- // //console.log("KEY: ",dataSnapshot,that.deviceConnectionRef);
169
- // if(dataSnapshot.val()){
170
- // console.log("self.deviceConnectionRef: ", that.myConnectionsRef);
171
- // //if (!that.myConnectionsRef || that.myConnectionsRef==='undefined') {
172
- // if (that.myConnectionsRef) {
173
- // //this.deviceConnectionRef = myConnectionsRef.set(true);
174
- // let conection = true;
175
- // //that.deviceConnectionRef =
176
- // const keyMyConnectionRef = that.myConnectionsRef.push(conection);
177
- // //!!! quando faccio logout devo disconnettermi
178
- // keyMyConnectionRef.onDisconnect().remove();
179
- // // when I disconnect, update the last time I was seen online
180
- // let now: Date = new Date();
181
- // let timestamp = now.valueOf();
182
- // that.lastOnlineRef.onDisconnect().set(timestamp);
183
- // } else {
184
- // console.log("This is an error. self.deviceConnectionRef already set. Cannot be set again.");
185
- // }
186
- // }
187
- // });
188
- // }
67
+ public imHere(): void {
68
+ this.logger.debug('[MQTT-PRESENCE] imHere', this.tenant);
69
+ setTimeout(() => {
70
+ this.chat21Service.chatClient.ImHere()
71
+ }, 2000);
72
+ }
189
73
 
190
- /**
191
- * rimuovo la references su lastOnline
192
- * rimuovo la references su connection
193
- */
194
- // goOffline() {
195
- // console.log("goOffline.", this.myConnectionsRef)
196
- // // this.removeConnectionReference();
197
- // this.removeLastOnlineReference();
198
- // }
199
-
200
- // removeConnectionReference(){
201
- // if(this.myConnectionsRef){
202
- // this.myConnectionsRef.off();
203
- // console.log("goOffline 1", this.myConnectionsRef)
204
- // this.myConnectionsRef.remove();
205
- // console.log("goOffline 2", this.myConnectionsRef)
206
- // }
207
- // this.myConnectionsRef = null;
208
- // }
209
-
210
- // removeLastOnlineReference(){
211
- // if(this.lastOnlineRef){
212
- // this.lastOnlineRef.off();
213
- // this.lastOnlineRef.remove();
214
- // }
215
- // this.lastOnlineRef = null;
216
- // }
217
- // }
74
+ }
@@ -1,5 +1,6 @@
1
1
  import { HttpClient, HttpHeaders } from '@angular/common/http';
2
2
  import { Injectable } from '@angular/core';
3
+ import { map } from 'rxjs/operators';
3
4
  import { AppStorageService } from '../abstract/app-storage.service';
4
5
  import { LoggerService } from '../abstract/logger.service';
5
6
  import { LoggerInstance } from '../logger/loggerInstance';
@@ -11,7 +12,7 @@ export class TiledeskRequestsService {
11
12
  public SERVER_BASE_URL: string;
12
13
 
13
14
  // private
14
- private URL_TILEDESK_CLOSE_REQUEST: string;
15
+ private URL_TILEDESK_REQUEST: string;
15
16
  private tiledeskToken: string;
16
17
 
17
18
  private logger: LoggerService = LoggerInstance.getInstance()
@@ -24,7 +25,7 @@ export class TiledeskRequestsService {
24
25
  initialize(serverBaseUrl: string, projectId: string,) {
25
26
  this.logger.debug('[TILEDESK-REQUEST-SERV] - initialize', projectId);
26
27
  this.SERVER_BASE_URL = serverBaseUrl;
27
- this.URL_TILEDESK_CLOSE_REQUEST = this.SERVER_BASE_URL + projectId +'/requests/';
28
+ this.URL_TILEDESK_REQUEST = this.SERVER_BASE_URL + projectId +'/requests/';
28
29
  }
29
30
 
30
31
 
@@ -37,8 +38,8 @@ export class TiledeskRequestsService {
37
38
  Authorization: this.tiledeskToken,
38
39
  });
39
40
  const requestOptions = { headers: headers };
40
- const that = this;
41
- const url = this.URL_TILEDESK_CLOSE_REQUEST + supportgroupid + '/closeg'
41
+
42
+ const url = this.URL_TILEDESK_REQUEST + supportgroupid + '/closeg'
42
43
  return new Promise((resolve, reject) => {
43
44
  this.logger.debug('[TILEDESK-REQUEST-SERV] - closeSupportGroup URLLLL', url, requestOptions);
44
45
  this.http.put(url, null, requestOptions).subscribe((data) => {
@@ -49,4 +50,20 @@ export class TiledeskRequestsService {
49
50
  });
50
51
  });
51
52
  }
53
+
54
+ public sendMessageToRequest(request_id: string, token: string, message: any): Promise<any> {
55
+ const url = this.URL_TILEDESK_REQUEST + request_id + '/messages'
56
+ this.logger.log('[TILEDESK-SERVICE] - SEND MESSAGE TO A REQUEST url ', url);
57
+ const httpOptions = {
58
+ headers: new HttpHeaders({
59
+ 'Content-Type': 'application/json',
60
+ Authorization: token
61
+ })
62
+ };
63
+ const body = message;
64
+ return this.http.post(url, body, httpOptions).toPromise().then(res => {
65
+ this.logger.log('[TILEDESK-SERVICE] - SEND MESSAGE TO A REQUEST res ', res);
66
+ return res
67
+ })
68
+ }
52
69
  }
@@ -1,3 +1,7 @@
1
+ import { convertMessage } from 'src/app/utils/utils';
2
+ import { MessageModel } from './../models/message';
3
+ import { ConversationModel } from './../models/conversation';
4
+ import { v4 as uuidv4 } from 'uuid';
1
5
  import {
2
6
  MESSAGE_TYPE_INFO,
3
7
  MESSAGE_TYPE_MINE,
@@ -69,6 +73,18 @@ export function isMine(message: any) {
69
73
  return false;
70
74
  }
71
75
 
76
+ export function isSender(sender: string, currentUserId: string) {
77
+ if (currentUserId) {
78
+ if (sender === currentUserId) {
79
+ return true;
80
+ } else {
81
+ return false;
82
+ }
83
+ } else {
84
+ return false;
85
+ }
86
+ }
87
+
72
88
  /** */
73
89
  export function messageType(msgType: string, message: any) {
74
90
 
@@ -177,3 +193,23 @@ export function hideInfoMessage(msg, infoMessageKeyEnabled): boolean{
177
193
  }
178
194
  return true
179
195
  }
196
+
197
+
198
+ export function conversationToMessage(conversation: ConversationModel, currentUserId: string): MessageModel{
199
+ let message: any = {}
200
+ message.uid = conversation['message_id']? conversation['message_id'] : uuidv4()
201
+ message.text = conversation.text? conversation.text.trim(): conversation.last_message_text.trim()
202
+ message.sender = conversation.sender
203
+ message.sender_fullname = conversation.sender_fullname
204
+ message.recipient = conversation.recipient
205
+ message.recipient_fullname = conversation.recipient_fullname
206
+ message.status = +conversation.status
207
+ message.timestamp = conversation.timestamp
208
+ message.metadata = conversation['metadata']
209
+ message.channel_type = conversation.channel_type
210
+ message.type = conversation.type
211
+ message.isSender = isSender(message.sender, currentUserId)
212
+ message.attributes = conversation.attributes
213
+
214
+ return message as MessageModel
215
+ }
@@ -69,8 +69,8 @@
69
69
  max-width: 400px;
70
70
  }
71
71
  #tiledesk-container.closed #tiledeskdiv.messagePreview {
72
- width: 340px;
73
- height: 300px;
72
+ width: 375px; /*340px*/
73
+ height: 440px; /*300px*/
74
74
  min-width: 340px;
75
75
  }
76
76
 
@@ -1,3 +1,5 @@
1
+ import { IRules } from './rule';
2
+
1
3
  export class ProjectModel {
2
4
  constructor(
3
5
  public id?: string,
@@ -22,6 +24,7 @@ export class ProjectModel {
22
24
  public color?: string,
23
25
  public welcomeTitle?: string,
24
26
  public welcomeMsg?: string,
27
+ public attributes?: IRules
25
28
  ) { }
26
29
 
27
30
  initialize (
@@ -40,7 +43,7 @@ export class ProjectModel {
40
43
  trialDaysLeft?: number,
41
44
  trialExpired?: boolean,
42
45
  updatedAt?: string,
43
- versions?: string
46
+ versions?: string,
44
47
  ) {
45
48
  this.id = id;
46
49
  this.activeOperatingHours = activeOperatingHours;
@@ -0,0 +1,19 @@
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
+ },
15
+ do: [
16
+ {wait: number},
17
+ {message: any}
18
+ ]
19
+ }