@chat21/chat21-web-widget 5.1.0-rc11 → 5.1.0-rc12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,9 @@
6
6
  ### **Copyrigth**:
7
7
  *Tiledesk SRL*
8
8
 
9
+ # 5.1.0-rc12
10
+ - **added**: ability to get all my request from Tiledesk API
11
+
9
12
  # 5.1.0-rc11
10
13
  - **bug-fixed**: removed private note msgs
11
14
 
package/angular.json CHANGED
@@ -24,7 +24,7 @@
24
24
  "index": "src/index.html",
25
25
  "polyfills": [
26
26
  "src/polyfills.ts",
27
- "@angular/localize/init",
27
+ "@angular/localize/init"
28
28
  ],
29
29
  "tsConfig": "tsconfig.app.json",
30
30
  "assets": [
@@ -51,7 +51,7 @@
51
51
  ],
52
52
  "scripts": [
53
53
  "src/assets/js/mqtt/4.2.6/mqtt.min.js",
54
- "node_modules/bootstrap/dist/js/bootstrap.min.js",
54
+ "node_modules/bootstrap/dist/js/bootstrap.min.js"
55
55
  ],
56
56
  "extractLicenses": false,
57
57
  "allowedCommonJsDependencies": [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-web-widget",
3
3
  "author": "Tiledesk SRL",
4
- "version": "5.1.0-rc11",
4
+ "version": "5.1.0-rc12",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.tiledesk.com",
7
7
  "repository": {
@@ -363,14 +363,21 @@ export class ConversationComponent implements OnInit, AfterViewInit, OnChanges {
363
363
  // this.logger.debug('[CONV-COMP] ------ 5: updateConversationbage ------ ');
364
364
  // this.updateConversationBadge();
365
365
 
366
- this.logger.debug('[CONV-COMP] ------ 6: getConversationDetail ------ ', this.conversationId);
367
- this.getConversationDetail((isConversationArchived) => {
368
- this.logger.debug('[CONV-COMP] ------ 6: updateConversationbage ------ ');
369
- this.updateConversationBadge();
370
- return;
371
- }) //check if conv is archived or not
366
+
367
+ // this.getConversationDetail((isConversationArchived) => {
368
+ // this.logger.debug('[CONV-COMP] ------ 6: updateConversationbage ------ ');
369
+ // this.updateConversationBadge();
370
+ // return;
371
+ // }) //check if conv is archived or not
372
372
  // this.checkListMessages();
373
373
 
374
+ this.logger.debug('[CONV-COMP] ------ 5: getConversationDetail ------ ', this.conversationId);
375
+ await this.getConversationDetail();
376
+
377
+
378
+ this.logger.debug('[CONV-COMP] ------ 6: updateConversationBadge ------ ');
379
+ this.updateConversationBadge();
380
+
374
381
  if(this.g.customAttributes){
375
382
  this.updateUserInfo(this.g.customAttributes)
376
383
  }
@@ -384,7 +391,7 @@ export class ConversationComponent implements OnInit, AfterViewInit, OnChanges {
384
391
  * @param callback
385
392
  * @returns isConversationArchived (status conversation archived: boolean)
386
393
  */
387
- getConversationDetail(callback:(isConversationArchived: boolean)=>void){
394
+ getConversationDetail_old(callback:(isConversationArchived: boolean)=>void){
388
395
  // if(!this.isConversationArchived){
389
396
  //get conversation from 'conversations' firebase node
390
397
  this.logger.debug('[CONV-COMP] getConversationDetail: isConversationArchived???', this.isConversationArchived, this.conversationWith)
@@ -414,39 +421,60 @@ export class ConversationComponent implements OnInit, AfterViewInit, OnChanges {
414
421
  })
415
422
  }
416
423
  });
417
- // } else { //get conversation from 'conversations' firebase node
418
- // this.archivedConversationsHandlerService.getConversationDetail(this.conversationId, (conv)=>{
419
- // this.logger.debug('[CONV-COMP] archivedConversationsHandlerService getConversationDetail', this.conversationId, conv, this.isConversationArchived)
420
- // if(conv){
421
- // this.conversation = conv;
422
- // this.isConversationArchived = true;
423
- // callback(this.isConversationArchived)
424
- // }
425
- // if(!conv){
426
- // this.conversationsHandlerService.getConversationDetail(this.conversationId, (conv)=>{
427
- // this.logger.debug('[CONV-COMP] conversationsHandlerService getConversationDetail', this.conversationId, conv, this.isConversationArchived)
428
- // conv? this.isConversationArchived = false : null
429
- // this.conversation = conv;
430
- // callback(this.isConversationArchived)
431
- // })
432
- // }
433
- // })
434
- // }
435
-
436
- // if(!this.isConversationArchived){ //get conversation from 'conversations' firebase node
437
- // this.conversationsHandlerService.getConversationDetail(this.conversationId, (conv)=>{
438
- // this.logger.debug('[CONV-COMP] conversationsHandlerService getConversationDetail', this.conversationId, conv)
439
- // this.conversation = conv;
440
- // callback(this.isConversationArchived)
441
- // })
442
- // }else { //get conversation from 'conversations' firebase node
443
- // this.archivedConversationsHandlerService.getConversationDetail(this.conversationId, (conv)=>{
444
- // this.logger.debug('[CONV-COMP] archivedConversationsHandlerService getConversationDetail', this.conversationId, conv)
445
- // this.conversation = conv;
446
- // callback(this.isConversationArchived)
447
- // })
448
- // }
449
- // this.updateConversationBadge()
424
+ }
425
+
426
+ /**
427
+ * @description get detail of conversation by uid and then return callback with conversation status
428
+ * @param callback
429
+ * @returns isConversationArchived (status conversation archived: boolean)
430
+ */
431
+ async getConversationDetail(): Promise<boolean | null> {
432
+ this.logger.debug('[CONV-COMP] getConversationDetail: isConversationArchived???', this.isConversationArchived, this.conversationWith);
433
+
434
+ const conv = await new Promise<any>((resolve) => {
435
+ this.conversationsHandlerService.getConversationDetail(this.conversationWith, resolve);
436
+ });
437
+
438
+ if (conv) {
439
+ this.logger.debug('[CONV-COMP] getConversationDetail: conversationsHandlerService ', this.conversationWith, conv, this.isConversationArchived);
440
+ this.conversation = conv;
441
+ this.isConversationArchived = false;
442
+ return this.isConversationArchived;
443
+ }
444
+
445
+ this.logger.debug('[CONV-COMP] getConversationDetail: conv not exist --> search in archived list', this.isConversationArchived, this.conversationWith);
446
+
447
+ const archivedConv = await new Promise<any>((resolve) => {
448
+ this.archivedConversationsHandlerService.getConversationDetail(this.conversationWith, resolve);
449
+ });
450
+
451
+ if (archivedConv) {
452
+ this.logger.debug('[CONV-COMP] getConversationDetail: archivedConversationsHandlerService', this.conversationWith, archivedConv, this.isConversationArchived);
453
+ this.conversation = archivedConv;
454
+ this.isConversationArchived = true;
455
+ return this.isConversationArchived;
456
+ }
457
+
458
+ //FALLBACK TO TILEDESK
459
+ const requests_list = await this.tiledeskRequestService.getMyRequests().catch(err => {
460
+ this.logger.error('[CONV-COMP] getConversationDetail: error getting request from Tiledesk', err);
461
+ this.isConversationArchived=true
462
+ return { requests: [] }
463
+ });
464
+ if (requests_list && requests_list.requests.length > 0) {
465
+ this.logger.debug('[CONV-COMP] getConversationDetail: request exist on Tiledesk', requests_list);
466
+ let conversation = requests_list.requests.find((request)=> request.request_id === this.conversationId)
467
+ if(conversation){
468
+ this.isConversationArchived = false
469
+ return this.isConversationArchived
470
+ }
471
+ this.logger.debug('[CONV-COMP] getConversationDetail: request NOT EXIST on Tiledesk', requests_list);
472
+ this.isConversationArchived = true
473
+ return this.isConversationArchived
474
+ }
475
+
476
+ this.isConversationArchived = true;
477
+ return null;
450
478
  }
451
479
 
452
480
  /**
@@ -744,6 +772,7 @@ export class ConversationComponent implements OnInit, AfterViewInit, OnChanges {
744
772
  subscribtion = this.conversationHandlerService.messageAdded.pipe(takeUntil(this.unsubscribe$)).subscribe((msg: MessageModel) => {
745
773
  this.logger.debug('[CONV-COMP] ***** DETAIL messageAdded *****', msg);
746
774
  if (msg) {
775
+
747
776
  that.newMessageAdded(msg);
748
777
  this.checkMessagesLegntForTranscriptDownloadMenuOption();
749
778
  this.resetTimeout();
@@ -68,4 +68,18 @@ export class TiledeskRequestsService {
68
68
  return res
69
69
  })
70
70
  }
71
+
72
+ public getMyRequests(): Promise<{ requests: Array<any>}> {
73
+ this.tiledeskToken = this.appStorage.getItem('tiledeskToken')
74
+ const url = this.URL_TILEDESK_REQUEST + '/me?preflight=true'
75
+ this.logger.log('[TILEDESK-SERVICE] - GET REQUEST url ', url);
76
+ const httpOptions = {
77
+ headers: new HttpHeaders({
78
+ 'Content-Type': 'application/json',
79
+ Authorization: this.tiledeskToken
80
+ })
81
+ }
82
+
83
+ return this.http.get<{ requests: Array<any>}>(url, httpOptions).toPromise()
84
+ }
71
85
  }