@chat21/chat21-ionic 3.4.13-rc3 → 3.4.13-rc4

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 (31) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/package.json +1 -1
  3. package/src/app/app.component.ts +7 -6
  4. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.html +1 -26
  5. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.ts +1 -1
  6. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.html +1 -0
  7. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.ts +1 -0
  8. package/src/app/chatlib/conversation-detail/message/options/options.component.html +1 -1
  9. package/src/app/chatlib/conversation-detail/message/options/options.component.ts +1 -0
  10. package/src/app/components/canned-response/canned-response.component.ts +1 -2
  11. package/src/app/components/conversation-detail/message-text-area/message-text-area.component.html +1 -1
  12. package/src/app/components/conversation-detail/message-text-area/message-text-area.component.ts +1 -0
  13. package/src/app/components/conversation-info/info-content/info-content.component.ts +9 -11
  14. package/src/app/components/conversation-info/info-group/info-group.component.ts +2 -10
  15. package/src/app/components/copilot-suggestions/copilot-suggestions.component.ts +13 -9
  16. package/src/app/components/navbar/navbar.component.ts +4 -4
  17. package/src/app/components/project-item/project-item.component.ts +3 -4
  18. package/src/app/modals/create-canned-response/create-canned-response.page.ts +1 -1
  19. package/src/app/pages/contacts-directory/contacts-directory.page.ts +5 -4
  20. package/src/app/pages/conversation-detail/conversation-detail.page.html +4 -2
  21. package/src/app/pages/conversation-detail/conversation-detail.page.ts +12 -26
  22. package/src/app/pages/conversations-list/conversations-list.page.ts +1 -1
  23. package/src/app/services/canned-responses/canned-responses.service.ts +22 -16
  24. package/src/app/services/contacts/contacts.service.ts +23 -20
  25. package/src/app/services/copilot/copilot.service.ts +27 -23
  26. package/src/app/services/projects/{projects.service.spec.ts → project.service.spec.ts} +2 -2
  27. package/src/app/services/projects/project.service.ts +68 -0
  28. package/src/app/services/tiledesk/tiledesk.service.ts +0 -35
  29. package/src/app/utils/project-utils.ts +140 -0
  30. package/src/chat21-core/utils/constants.ts +3 -0
  31. package/src/app/services/projects/projects.service.ts +0 -43
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # chat21-ionic ver 3.0
2
2
 
3
+ ### 3.4.13-rc.4
4
+ - added: management for copilot option in project.profile obj
5
+ - removed: token in each tiledesk Service method calls and added initialize method for each services
6
+
3
7
  ### 3.4.13-rc.3
4
8
  - added: copilot-popover on each received message
5
9
  - changed: canned-responsed no data ui
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-ionic",
3
3
  "author": "Tiledesk SRL",
4
- "version": "3.4.13-rc3",
4
+ "version": "3.4.13-rc4",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -40,7 +40,8 @@ import { Deeplinks } from '@ionic-native/deeplinks/ngx';
40
40
  import { TriggerEvents } from './services/triggerEvents/triggerEvents';
41
41
  import { Globals } from './utils/globals';
42
42
  import { GlobalSettingsService } from './services/global-settings/global-settings.service';
43
- import { commandToMessage, conversationToMessage, isSender } from 'src/chat21-core/utils/utils-message';
43
+ import { conversationToMessage } from 'src/chat21-core/utils/utils-message';
44
+ import { ProjectService } from './services/projects/project.service';
44
45
 
45
46
  @Component({
46
47
  selector: 'app-root',
@@ -103,13 +104,10 @@ export class AppComponent implements OnInit {
103
104
  private appConfigProvider: AppConfigProvider,
104
105
  public events: EventsService,
105
106
  public triggerEvents: TriggerEvents,
106
- public config: Config,
107
107
  public chatManager: ChatManager,
108
108
  public translate: TranslateService,
109
109
  public alertController: AlertController,
110
110
  public navCtrl: NavController,
111
- // public userService: UserService,
112
- // public currentUserService: CurrentUserService,
113
111
  public modalController: ModalController,
114
112
  public messagingAuthService: MessagingAuthService,
115
113
  public tiledeskAuthService: TiledeskAuthService,
@@ -137,7 +135,8 @@ export class AppComponent implements OnInit {
137
135
  public fcm: FCM,
138
136
  public el: ElementRef,
139
137
  public g: Globals,
140
- public globalSettingsService: GlobalSettingsService
138
+ public globalSettingsService: GlobalSettingsService,
139
+ public projectService: ProjectService
141
140
  ) {
142
141
 
143
142
  this.saveInStorageNumberOfOpenedChatTab();
@@ -1153,7 +1152,7 @@ export class AppComponent implements OnInit {
1153
1152
  // this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO-ONLINE isOnline ', this.isOnline);
1154
1153
  // clearTimeout(this.timeModalLogin);
1155
1154
  const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
1156
-
1155
+ const serverBaseURL = this.appConfigProvider.getConfig().apiUrl
1157
1156
  // const supportmode = this.appConfigProvider.getConfig().supportMode;
1158
1157
  // this.logger.log('[APP-COMP] - GO-ONLINE - supportmode ', supportmode);
1159
1158
  // if (supportmode === true) {
@@ -1166,6 +1165,8 @@ export class AppComponent implements OnInit {
1166
1165
  this.logger.log('[APP-COMP] - GO-ONLINE - currentUser ', currentUser);
1167
1166
  this.chatManager.setTiledeskToken(tiledeskToken);
1168
1167
  this.chatManager.setCurrentUser(currentUser);
1168
+
1169
+ this.projectService.initialize(serverBaseURL)
1169
1170
  // this.chatManager.startApp();
1170
1171
 
1171
1172
  // ----------------------------------------------
@@ -97,16 +97,6 @@
97
97
  <div role="messaggio" *ngIf="messageType(MESSAGE_TYPE_MINE, message)" class="msg_container base_sent">
98
98
 
99
99
  <div class="message-date-hover"> {{message.timestamp | date:'HH:mm' }} </div>
100
-
101
- <!-- <ng-container *ngIf="areVisibleCAR && supportMode">
102
- <ion-button shape="round" size="small" class="btn-add-msg canned" ion-button fill="clear"
103
- (click)="presentCreateCannedResponseModal(message)" [tooltip]="addAsCannedResponseTooltipText"
104
- [options]="tooltipOptions" placement="bottom">
105
- <ion-icon slot="icon-only" name="flash-outline" style="font-size: 1em;"> </ion-icon>
106
- <span class="add-canned-response-add-icon">+</span>
107
- </ion-button>
108
- </ng-container> -->
109
-
110
100
 
111
101
  <div class="bubble-container">
112
102
 
@@ -174,6 +164,7 @@
174
164
  [fontSize]="stylesMap?.get('fontSize')"
175
165
  [fontFamily]="stylesMap?.get('fontFamily')"
176
166
  [stylesMap]="stylesMap"
167
+ [isCopilotEnabled]="isCopilotEnabled"
177
168
  (onBeforeMessageRender)="onBeforeMessageRenderFN($event)"
178
169
  (onAfterMessageRender)="onAfterMessageRenderFN($event)"
179
170
  (onElementRendered)="onElementRenderedFN($event)"
@@ -189,22 +180,6 @@
189
180
  </ion-button>
190
181
  </ng-container>
191
182
 
192
- <!-- <ng-container *ngIf="areVisibleCAR && supportMode">
193
- <ion-button shape="round" size="small" class="btn-add-msg canned" ion-button fill="clear"
194
- (click)="presentCreateCannedResponseModal(message)" [tooltip]="addAsCannedResponseTooltipText"
195
- [options]="tooltipOptions" placement="bottom">
196
- <ion-icon slot="icon-only" name="flash-outline" style="font-size: 1em;"> </ion-icon>
197
- <span class="add-canned-response-add-icon">+</span>
198
- </ion-button>
199
- </ng-container> -->
200
- <!-- <ng-container *ngIf="supportMode">
201
- <ion-button shape="round" size="small" class="btn-add-msg emoji" ion-button fill="clear"
202
- (click)="presentEmojiiModal()" tooltip="{{addAsCannedResponseTooltipText}}"
203
- [options]="tooltipOptions" placement="bottom">
204
- <ion-icon slot="icon-only" name="happy-outline" style="font-size: 1em;"> </ion-icon>
205
- </ion-button>
206
- </ng-container> -->
207
-
208
183
  <div class="message-date-hover" *ngIf="isChannelTypeGroup(channelType)"> {{message.timestamp | date:'HH:mm' }} </div>
209
184
  </div>
210
185
 
@@ -29,6 +29,7 @@ export class IonConversationDetailComponent extends ConversationContentComponent
29
29
  @Input() senderId: string;
30
30
  @Input() channelType: string;
31
31
  @Input() areVisibleCAR: boolean;
32
+ @Input() isCopilotEnabled: boolean = false
32
33
  @Input() supportMode: boolean;
33
34
  @Input() isMobile: boolean;
34
35
  @Input() openInfoConversation: boolean;
@@ -166,7 +167,6 @@ export class IonConversationDetailComponent extends ConversationContentComponent
166
167
  }else if(event.option === 'jsonInfo'){
167
168
  this.presentJsonMessageModal(event.data.message)
168
169
  } else if(event.option === 'copilot_question'){
169
- console.log('hereeeeeee', event)
170
170
  this.eventService.publish('copilot:new_question', {text: event.data.text})
171
171
 
172
172
  }
@@ -11,6 +11,7 @@
11
11
  </div> -->
12
12
  <chat-options
13
13
  [message]="message"
14
+ [isCopilotEnabled]="isCopilotEnabled"
14
15
  [logLevel]="logger.getLoggerConfig().logLevel"
15
16
  (onOptionsDataReturned)="onOptionsDataReturnedFN($event)">
16
17
  </chat-options>
@@ -26,6 +26,7 @@ export class BubbleMessageComponent implements OnInit, OnChanges {
26
26
  @Input() fontFamily: string;
27
27
  @Input() stylesMap: Map<string, string>;
28
28
  @Input() supportMode: boolean;
29
+ @Input() isCopilotEnabled: boolean = false;
29
30
  @Output() onBeforeMessageRender = new EventEmitter();
30
31
  @Output() onAfterMessageRender = new EventEmitter();
31
32
  @Output() onElementRendered = new EventEmitter<{element: string, status: boolean}>();
@@ -2,7 +2,7 @@
2
2
  <div class="options-logo" (click)="onClickOptionsMessage($event)" >
3
3
  <ion-icon name="chevron-down"></ion-icon>
4
4
  </div>
5
- <div class="options-logo" (click)="onClickOptionsCopilot($event)">
5
+ <div *ngIf="isCopilotEnabled" class="options-logo" (click)="onClickOptionsCopilot($event)">
6
6
  <ion-icon id="copilot" src="assets/images/icons/copilot.svg"></ion-icon>
7
7
  </div>
8
8
  </div>
@@ -14,6 +14,7 @@ import { CopilotPopoverComponent } from 'src/app/components/copilot-popover/copi
14
14
  export class OptionsComponent implements OnInit {
15
15
 
16
16
  @Input() message: MessageModel;
17
+ @Input() isCopilotEnabled: boolean = false;
17
18
  @Input() logLevel: number;
18
19
  @Output() onOptionsDataReturned = new EventEmitter<{option: string, data: any}>();
19
20
 
@@ -120,12 +120,11 @@ export class CannedResponseComponent implements OnInit {
120
120
  }
121
121
 
122
122
  getAndShowCannedResponses(strSearch, projectId) {
123
- const tiledeskToken = this.tiledeskAuthService.getTiledeskToken()
124
123
  this.logger.log('[CANNED] - loadTagsCanned tagsCanned.length', this.tagsCanned.length)
125
124
  //if(this.tagsCanned.length <= 0 ){
126
125
  this.tagsCanned = []
127
126
  this.showLoading = true;
128
- this.cannedResponsesService.getAll(tiledeskToken, projectId).subscribe((res) => {
127
+ this.cannedResponsesService.getAll(projectId).subscribe((res) => {
129
128
  this.logger.log('[CANNED] - loadTagsCanned getCannedResponses RES', res)
130
129
 
131
130
  this.tagsCanned = res
@@ -28,7 +28,7 @@
28
28
  </div>
29
29
  </div>
30
30
 
31
- <div>
31
+ <div *ngIf="isCopilotEnabled">
32
32
  <!-- COPILOT-OPTION -->
33
33
  <div class="section-option" id="copilot" tooltip="{{translationMap?.get('COPILOT.ASK_AI')}}" placement="top">
34
34
  <ion-button id="copilot" fill="clear" [class.active]="section ==='copilot'" (click)="onOpenSection('copilot')">
@@ -52,6 +52,7 @@ export class MessageTextAreaComponent implements OnInit, AfterViewInit, OnChange
52
52
  @Input() channel: string;
53
53
  @Input() tagsCannedFilter: any;
54
54
  @Input() areVisibleCAR: boolean;
55
+ @Input() isCopilotEnabled: boolean = false;
55
56
  @Input() supportMode: boolean;
56
57
  @Input() leadInfo: {lead_id: string, hasEmail: boolean, email: string, projectId: string, presence: {}};
57
58
  @Input() fileUploadAccept: string;
@@ -225,17 +225,15 @@ export class InfoContentComponent implements OnInit {
225
225
 
226
226
  this.member = null;
227
227
 
228
- const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
229
- this.contactsService.loadContactDetail(tiledeskToken, this.conversationWith)
230
- .subscribe(res => {
231
- this.logger.log('[INFO-CONTENT-COMP] - setInfoDirect loadContactDetail RES', res);
232
- this.member = res
233
- this.logger.log('[INFO-CONTENT-COMP] - setInfoDirect member', this.member);
234
- }, (error) => {
235
- this.logger.error('[INFO-CONTENT-COMP] - setInfoDirect loadContactDetail - ERROR ', error);
236
- }, () => {
237
- this.logger.log('I[INFO-CONTENT-COMP] - setInfoDirect loadContactDetail * COMPLETE *');
238
- });
228
+ this.contactsService.loadContactDetail(this.conversationWith).subscribe(res => {
229
+ this.logger.log('[INFO-CONTENT-COMP] - setInfoDirect loadContactDetail RES', res);
230
+ this.member = res
231
+ this.logger.log('[INFO-CONTENT-COMP] - setInfoDirect member', this.member);
232
+ }, (error) => {
233
+ this.logger.error('[INFO-CONTENT-COMP] - setInfoDirect loadContactDetail - ERROR ', error);
234
+ }, () => {
235
+ this.logger.log('I[INFO-CONTENT-COMP] - setInfoDirect loadContactDetail * COMPLETE *');
236
+ });
239
237
  }
240
238
 
241
239
  // ---------------------------------------------------
@@ -38,7 +38,6 @@ export class InfoGroupComponent implements OnInit, AfterViewInit, OnChanges {
38
38
  constructor(
39
39
  public imageRepoService: ImageRepoService,
40
40
  public presenceService: PresenceService,
41
- public tiledeskAuthService: TiledeskAuthService,
42
41
  public contactsService: ContactsService,
43
42
  public renderer: Renderer2,
44
43
  private router: Router,
@@ -56,10 +55,7 @@ export class InfoGroupComponent implements OnInit, AfterViewInit, OnChanges {
56
55
  // const currentUrl = this.router.url;
57
56
  // this.logger.log('InfoGroupComponent current_url ', currentUrl);
58
57
  // .pipe(takeUntil(this.unsubscribe$))
59
- router.events
60
- .pipe(filter(event => event instanceof NavigationEnd))
61
-
62
- .subscribe((event: NavigationEnd) => {
58
+ router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
63
59
  // console.log('InfoGroupComponent - router.events prev url :', event.url);
64
60
  this.previousUrl = event.url;
65
61
 
@@ -122,8 +118,6 @@ export class InfoGroupComponent implements OnInit, AfterViewInit, OnChanges {
122
118
 
123
119
  if (this.groupDetail) {
124
120
  if (this.groupDetail.uid.startsWith('group-')) {
125
- const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
126
-
127
121
  this.member_array = []
128
122
  const members_isonline_array = []
129
123
 
@@ -156,9 +150,7 @@ export class InfoGroupComponent implements OnInit, AfterViewInit, OnChanges {
156
150
 
157
151
  });
158
152
 
159
- this.contactsService.loadContactDetail(tiledeskToken, key)
160
- .pipe(takeUntil(this.unsubscribe$))
161
- .subscribe(user => {
153
+ this.contactsService.loadContactDetail(key).pipe(takeUntil(this.unsubscribe$)).subscribe(user => {
162
154
  this.logger.log('InfoGroupComponent group detail loadContactDetail RES', user);
163
155
  // this.logger.log('InfoGroupComponent group detail this.presenceService.BSIsOnline.value()', this.presenceService.BSIsOnline.getValue);
164
156
 
@@ -1,3 +1,4 @@
1
+ import { AppConfigProvider } from 'src/app/services/app-config';
1
2
  import { filter } from 'rxjs/operators';
2
3
  import { Component, ElementRef, EventEmitter, HostListener, Input, OnInit, Output, SimpleChange } from '@angular/core';
3
4
  import { CopilotService } from 'src/app/services/copilot/copilot.service';
@@ -39,19 +40,23 @@ export class CopilotSuggestionsComponent implements OnInit {
39
40
  public tiledeskAuthService: TiledeskAuthService,
40
41
  public tiledeskService: TiledeskService,
41
42
  public copilotService: CopilotService,
43
+ public appConfigProvider: AppConfigProvider,
42
44
  public el: ElementRef
43
- ) { }
45
+ ) {
46
+ const serverBaseUrl = this.appConfigProvider.getConfig().apiUrl
47
+ this.copilotService.initialize(serverBaseUrl)
48
+ }
44
49
 
45
50
  ngOnInit() {
46
51
  this.loggedUser = this.tiledeskAuthService.getCurrentUser()
47
52
  }
48
53
 
49
54
  ngOnChanges(changes: SimpleChange){
50
- this.logger.debug('[COPILOT] - loadTagsCanned strSearch ', this.currentString)
51
- if(changes && changes['conversationWith'] && (changes['conversationWith'].previousValue !== changes['conversationWith'].currentValue)){
52
- this.projectID = getProjectIdSelectedConversation(this.conversationWith)
53
- }
54
- this.loadSuggestions(this.conversationWith)
55
+ this.logger.debug('[COPILOT] - loadTagsCanned strSearch ', this.currentString)
56
+ if(changes && changes['conversationWith'] && (changes['conversationWith'].previousValue !== changes['conversationWith'].currentValue)){
57
+ this.projectID = getProjectIdSelectedConversation(this.conversationWith)
58
+ }
59
+ this.loadSuggestions(this.conversationWith)
55
60
  }
56
61
 
57
62
 
@@ -90,13 +95,12 @@ export class CopilotSuggestionsComponent implements OnInit {
90
95
 
91
96
 
92
97
  getAndShowSuggestions(projectId) {
93
- const tiledeskToken = this.tiledeskAuthService.getTiledeskToken()
94
98
  this.logger.log('[COPILOT] - loadTagsCanned tagsCanned.length', this.suggestions.length)
95
99
  //if(this.tagsCanned.length <= 0 ){
96
100
  this.suggestions = []
97
101
  this.showLoading = true;
98
102
  if(this.question && this.question !== ''){
99
- this.copilotService.getAllFromQuestion(this.question, tiledeskToken, projectId, this.conversationWith).subscribe((res) => {
103
+ this.copilotService.getAllFromQuestion(this.question, projectId, this.conversationWith).subscribe((res) => {
100
104
  this.logger.log('[COPILOT] - loadTagsCanned getCannedResponses RES', res)
101
105
  this.suggestions = res.map(el => ({ ...el, disabled : true }))
102
106
  this.logger.log('[COPILOT] - loadTagsCanned getCannedResponses tagsCannedCount', this.suggestions)
@@ -108,7 +112,7 @@ export class CopilotSuggestionsComponent implements OnInit {
108
112
  this.onLoadedSuggestions.emit(this.suggestions)
109
113
  })
110
114
  } else {
111
- this.copilotService.getAll(tiledeskToken, projectId, this.conversationWith).subscribe((res) => {
115
+ this.copilotService.getAll(projectId, this.conversationWith).subscribe((res) => {
112
116
  this.logger.log('[COPILOT] - loadTagsCanned getCannedResponses RES', res)
113
117
  this.suggestions = res.map(el => ({ ...el, disabled : true }))
114
118
  this.logger.log('[COPILOT] - loadTagsCanned getCannedResponses tagsCannedCount', this.suggestions)
@@ -1,7 +1,7 @@
1
1
  import { AppConfigProvider } from 'src/app/services/app-config';
2
2
  import { TiledeskAuthService } from 'src/chat21-core/providers/tiledesk/tiledesk-auth.service';
3
3
  import { EventsService } from 'src/app/services/events-service';
4
- import { ProjectsService } from './../../services/projects/projects.service';
4
+ import { ProjectService } from '../../services/projects/project.service';
5
5
  import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
6
6
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
7
7
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
@@ -33,7 +33,7 @@ export class NavbarComponent implements OnInit {
33
33
  public MT: boolean;
34
34
 
35
35
  constructor(
36
- private projectsService: ProjectsService,
36
+ private projectService: ProjectService,
37
37
  private tiledeskAuthService: TiledeskAuthService,
38
38
  private appConfigProvider: AppConfigProvider,
39
39
  private translateService: CustomTranslateService,
@@ -78,7 +78,7 @@ export class NavbarComponent implements OnInit {
78
78
 
79
79
  getProjects() {
80
80
  this.logger.log('[NAVBAR] calling getProjects ... ');
81
- this.projectsService.getProjects(this.tiledeskToken).subscribe((projects: any) => {
81
+ this.projectService.getProjects().subscribe((projects: any) => {
82
82
  this.logger.log('[NAVBAR] getProjects PROJECTS ', projects);
83
83
  if (projects) {
84
84
  // this.projects = projects;
@@ -170,7 +170,7 @@ export class NavbarComponent implements OnInit {
170
170
  url = baseUrl + '#/project/' + this.project.id_project.id + '/project-settings/general' + '?token=' + this.tiledeskToken
171
171
  }else if(event ==='allProjects'){
172
172
  url = baseUrl + '#/projects/' + '?token=' + this.tiledeskToken
173
- }else if('addProject'){
173
+ }else if(event === 'addProject'){
174
174
  url = baseUrl + '#/create-new-project/' + '?token=' + this.tiledeskToken
175
175
  }
176
176
  console.log('onClickDropdownOption-->', url)
@@ -14,6 +14,7 @@ import { WebSocketJs } from 'src/app/services/websocket/websocket-js';
14
14
  import { AppConfigProvider } from 'src/app/services/app-config';
15
15
  import { ConvertRequestToConversation } from 'src/chat21-core/utils/convertRequestToConversation';
16
16
  import { compareValues } from 'src/chat21-core/utils/utils';
17
+ import { ProjectService } from 'src/app/services/projects/project.service';
17
18
 
18
19
  @Component({
19
20
  selector: 'app-project-item',
@@ -46,7 +47,7 @@ export class ProjectItemComponent implements OnInit {
46
47
  public appStorageService: AppStorageService,
47
48
  private translateService: CustomTranslateService,
48
49
  public tiledeskAuthService: TiledeskAuthService,
49
- public tiledeskService: TiledeskService,
50
+ public projectService: ProjectService,
50
51
  public webSocketJs: WebSocketJs,
51
52
  private appConfigProvider: AppConfigProvider,
52
53
  public events: EventsService,
@@ -174,9 +175,7 @@ export class ProjectItemComponent implements OnInit {
174
175
 
175
176
  if (!stored_project || stored_project === 'undefined') {
176
177
  this.logger.log('PROJECT-ITEM - THERE IS NOT STORED LAST PROJECT OR IS UNDEFINED ', stored_project)
177
- const tiledeskToken = this.appStorageService.getItem('tiledeskToken');
178
- this.logger.log('[PROJECT-ITEM] - GET PROJECTS - tiledeskToken', tiledeskToken);
179
- this.tiledeskService.getProjects(tiledeskToken).subscribe(projects => {
178
+ this.projectService.getProjects().subscribe(projects => {
180
179
  this.logger.log('[PROJECT-ITEM - GET PROJECTS - RES', projects);
181
180
 
182
181
  this.logger.log('[INFO-CONTENT-COMP] - GET PROJECTS - RES this.project', this.project);
@@ -177,7 +177,7 @@ export class CreateCannedResponsePage implements OnInit {
177
177
  this.logger.log('[CREATE-CANNED-RES] - CREATE CANNED RESP - MSG ', message);
178
178
  this.logger.log('[CREATE-CANNED-RES] - CREATE CANNED RESP - TITLE ', title);
179
179
 
180
- this.cannedResponsesService.add(this.tiledeskToken, this.prjctID, title.trim(), message.trim()).subscribe((responses: any) => {
180
+ this.cannedResponsesService.add(this.prjctID, title.trim(), message.trim()).subscribe((responses: any) => {
181
181
  this.logger.log('[CREATE-CANNED-RES] - CREATE CANNED RESP - RES ', responses);
182
182
  }, (error) => {
183
183
  this.logger.error('[CREATE-CANNED-RES]- CREATE CANNED RESP - ERROR ', error);
@@ -10,6 +10,7 @@ import { EventsService } from '../../services/events-service';
10
10
  // Logger
11
11
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
12
12
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
13
+ import { AppConfigProvider } from 'src/app/services/app-config';
13
14
 
14
15
  @Component({
15
16
  selector: 'app-contacts-directory',
@@ -18,7 +19,6 @@ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance'
18
19
  })
19
20
  export class ContactsDirectoryPage implements OnInit {
20
21
 
21
- @Input() token: string;
22
22
  @Input() isMobile: boolean;
23
23
  @Input() stylesMap: Map<string, string>;
24
24
  // @Input() user: string;
@@ -31,22 +31,23 @@ export class ContactsDirectoryPage implements OnInit {
31
31
  private navService: NavProxyService,
32
32
  // private contactsDirectoryService: ContactsDirectoryService,
33
33
  private contactsService: ContactsService,
34
+ private appConfigProvider: AppConfigProvider,
34
35
  public events: EventsService
35
36
  ) {
37
+ const serverBaseUrl = this.appConfigProvider.getConfig().apiUrl
38
+ this.contactsService.initialize(serverBaseUrl)
36
39
  }
37
40
 
38
41
  ngOnInit() {
39
- this.logger.log('[CONTACT-DIRECTORY-PAGE] - TOKEN (ngOnInit)', this.token);
40
42
  this.initialize();
41
43
  }
42
44
 
43
45
  /** */
44
46
  initialize() {
45
47
  this.logger.log('[CONTACT-DIRECTORY-PAGE] - initialize');
46
- this.logger.log('[CONTACT-DIRECTORY-PAGE] - token: ', this.token);
47
48
  this.contacts = [];
48
49
  this.initSubscriptions();
49
- this.contactsService.loadContactsFromUrl(this.token);
50
+ this.contactsService.loadContactsFromUrl();
50
51
  }
51
52
 
52
53
  /**
@@ -135,7 +135,8 @@
135
135
  [messages]="messages"
136
136
  [senderId]="loggedUser.uid"
137
137
  [baseLocation]="window?.location?.origin"
138
- [areVisibleCAR]="areVisibleCAR"
138
+ [areVisibleCAR]="areVisibleCAR"
139
+ [isCopilotEnabled]="isCopilotEnabled"
139
140
  [supportMode]= "supportMode"
140
141
  [isMobile]="isMobile"
141
142
  [isTypings]="isTypings"
@@ -203,7 +204,8 @@
203
204
  [channelType]="channelType"
204
205
  [channel]="conversation?.attributes?.request_channel"
205
206
  [tagsCannedFilter]="tagsCannedFilter"
206
- [areVisibleCAR]="areVisibleCAR"
207
+ [areVisibleCAR]="areVisibleCAR"
208
+ [isCopilotEnabled]="isCopilotEnabled"
207
209
  [supportMode]="supportMode"
208
210
  [leadInfo]="leadInfo"
209
211
  [fileUploadAccept]="appConfigProvider.getConfig().fileUploadAccept"
@@ -1,3 +1,4 @@
1
+ import { ProjectPlanUtils } from './../../utils/project-utils';
1
2
  import { DomSanitizer } from '@angular/platform-browser';
2
3
  import {
3
4
  Component,
@@ -81,6 +82,7 @@ import { EventsService } from '../../services/events-service'
81
82
  import { WebsocketService } from 'src/app/services/websocket/websocket.service';
82
83
  import { Project } from 'src/chat21-core/models/projects';
83
84
  import { Globals } from 'src/app/utils/globals';
85
+ import { ProjectService } from 'src/app/services/projects/project.service';
84
86
 
85
87
  @Component({
86
88
  selector: 'app-conversation-detail',
@@ -147,6 +149,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
147
149
 
148
150
  public_Key: any;
149
151
  areVisibleCAR: boolean;
152
+ isCopilotEnabled: boolean;
150
153
  supportMode: boolean;
151
154
  isEmailEnabled: boolean;
152
155
  offlineMsgEmail: boolean;
@@ -234,10 +237,11 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
234
237
  public presenceService: PresenceService,
235
238
  public toastController: ToastController,
236
239
  public tiledeskService: TiledeskService,
240
+ public projectService: ProjectService,
237
241
  private networkService: NetworkService,
238
242
  private events: EventsService,
239
243
  private webSocketService: WebsocketService,
240
- private sanitizer: DomSanitizer,
244
+ public projectPlanUtils: ProjectPlanUtils,
241
245
  private g: Globals,
242
246
  ) {
243
247
  // Change list on date change
@@ -498,6 +502,8 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
498
502
  this.isEmailEnabled = (this.appConfigProvider.getConfig().emailSection === 'true' || this.appConfigProvider.getConfig().emailSection === true) ? true : false;
499
503
  this.isWhatsappTemplatesEnabled = (this.appConfigProvider.getConfig().whatsappTemplatesSection === 'true' || this.appConfigProvider.getConfig().whatsappTemplatesSection === true) ? true : false;
500
504
 
505
+ this.cannedResponsesService.initialize(appconfig.apiUrl)
506
+
501
507
  if (checkPlatformIsMobile()) {
502
508
  this.isMobile = true
503
509
  // this.openInfoConversation = false; // indica se è aperto il box info conversazione
@@ -544,7 +550,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
544
550
  this.logger.log('[CONVS-DETAIL] - GET PROJECTID BY CONV RECIPIENT RES + projectId', res, res.id_project)
545
551
  if (res) {
546
552
  const projectId = res.id_project
547
- this.getProjectById(tiledeskToken, projectId)
553
+ this.getProjectById(projectId)
548
554
  }
549
555
  }, (error) => {
550
556
  this.logger.error('[CONVS-DETAIL] - GET PROJECTID BY CONV RECIPIENT - ERROR ',conversationWith, error)
@@ -558,13 +564,14 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
558
564
 
559
565
  }
560
566
 
561
- getProjectById(tiledeskToken, projectId) {
562
- this.tiledeskService.getProjectById(tiledeskToken, projectId).subscribe((project) => {
567
+ getProjectById(projectId) {
568
+ this.projectService.getProjectById(projectId).subscribe(async (project) => {
563
569
  this.logger.log('[CONVS-DETAIL] - GET PROJECTID BY CONV RECIPIENT RES', project)
564
570
  if (project) {
565
571
  const projectId = project.id_project
566
- this.canShowCanned = this.checkPlanIsExpired(project)
572
+ this.canShowCanned = this.projectPlanUtils.checkPlanIsExpired(project)
567
573
  this.offlineMsgEmail = this.checkOfflineMsgEmailIsEnabled(project)
574
+ this.isCopilotEnabled = this.projectPlanUtils.checkProjectProfileFeature(project, 'copilot')
568
575
  }
569
576
  }, (error) => {
570
577
  this.logger.error('[CONVS-DETAIL] - GET PROJECTID BY CONV RECIPIENT - ERROR ', error)
@@ -577,27 +584,6 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
577
584
  }
578
585
 
579
586
 
580
- checkPlanIsExpired(project: Project): boolean {
581
- let check: boolean = false
582
-
583
- //case FREE plan
584
- if(project && project.trialExpired && project.profile.type=== 'trial'){
585
- check = true
586
- }else if(project && !project.trialExpired && project.profile.type=== 'trial'){
587
- check = false
588
- }
589
-
590
- //case PAYMENT plan
591
- if(project && project.isActiveSubscription && project.profile.type=== 'payment'){
592
- check = true
593
- }else if(project && !project.isActiveSubscription && project.profile.type=== 'payment'){
594
- check = false
595
- }
596
-
597
- return check
598
- }
599
-
600
-
601
587
  checkOfflineMsgEmailIsEnabled(project: Project): boolean {
602
588
  let check: boolean = true
603
589
 
@@ -911,7 +911,7 @@ export class ConversationListPage implements OnInit {
911
911
  isMobile: this.isMobile
912
912
  })
913
913
  } else {
914
- this.navService.push(ContactsDirectoryPage, { token: TOKEN })
914
+ this.navService.push(ContactsDirectoryPage, {})
915
915
  }
916
916
  }
917
917
 
@@ -6,38 +6,44 @@ import { map } from 'rxjs/operators';
6
6
  // Logger
7
7
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
8
8
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
9
+ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
9
10
 
10
11
  @Injectable({
11
12
  providedIn: 'root'
12
13
  })
13
14
  export class CannedResponsesService {
14
15
 
15
- private apiUrl: string;
16
+ private SERVER_BASE_URL: string;
17
+ private tiledeskToken: string;
18
+
16
19
  private logger: LoggerService = LoggerInstance.getInstance();
17
20
 
18
21
  constructor(
19
22
  public http: HttpClient,
20
- public appConfigProvider: AppConfigProvider
23
+ public appStorageService: AppStorageService
21
24
  ) {
22
-
23
25
  this.logger.log('[CANNED-RESPONSES-SERVICE] HELLO !');
24
- this.apiUrl = appConfigProvider.getConfig().apiUrl;
25
- this.logger.log('[CANNED-RESPONSES-SERVICE] apiUrl ', this.apiUrl);
26
+ }
27
+
28
+ initialize(serverBaseUrl: string) {
29
+ this.logger.log('[CANNED-RESPONSES-SERVICE] - initialize serverBaseUrl', serverBaseUrl);
30
+ this.SERVER_BASE_URL = serverBaseUrl;
31
+ this.tiledeskToken = this.appStorageService.getItem('tiledeskToken')
26
32
  }
27
33
 
28
34
 
29
- public getAll(token: string, projectid: string) {
30
- const cannedResponsesURL = this.apiUrl + projectid + "/canned/";
31
- this.logger.log('[CANNED-RESPONSES-SERVICE] getCannedResponses - URL ', cannedResponsesURL);
35
+ public getAll(projectid: string) {
36
+ const url = this.SERVER_BASE_URL + projectid + "/canned/";
37
+ this.logger.log('[CANNED-RESPONSES-SERVICE] getCannedResponses - URL ', url);
32
38
 
33
39
  const httpOptions = {
34
40
  headers: new HttpHeaders({
35
41
  'Content-Type': 'application/json',
36
- Authorization: token
42
+ Authorization: this.tiledeskToken
37
43
  })
38
44
  };
39
45
 
40
- return this.http.get(cannedResponsesURL, httpOptions).pipe(map((res: any) => {
46
+ return this.http.get(url, httpOptions).pipe(map((res: any) => {
41
47
  this.logger.log('[CANNED-RESPONSES-SERVICE] getCannedResponses - RES ', res);
42
48
  return res
43
49
  }))
@@ -46,14 +52,14 @@ export class CannedResponsesService {
46
52
  // -------------------------------------------------------------------------------------
47
53
  // @ Create - Save (POST) new canned response
48
54
  // -------------------------------------------------------------------------------------
49
- public add(token: string, projectid: string, title: string, message: string) {
50
- const url = this.apiUrl + projectid + '/canned/'
55
+ public add(projectid: string, title: string, message: string) {
56
+ const url = this.SERVER_BASE_URL + projectid + '/canned/'
51
57
  this.logger.log('[TILEDESK-SERVICE] - CREATE CANNED-RES - URL', url);
52
58
 
53
59
  const httpOptions = {
54
60
  headers: new HttpHeaders({
55
61
  'Content-Type': 'application/json',
56
- Authorization: token
62
+ Authorization: this.tiledeskToken
57
63
  })
58
64
  };
59
65
 
@@ -70,13 +76,13 @@ export class CannedResponsesService {
70
76
  }
71
77
 
72
78
  public edit(token: string, projectid: string, canned: any){
73
- const cannedResponsesURL = this.apiUrl + projectid + "/canned/"+ canned._id;
79
+ const cannedResponsesURL = this.SERVER_BASE_URL + projectid + "/canned/"+ canned._id;
74
80
  this.logger.log('[CANNED-RESPONSES-SERVICE] editCannedResponses - URL ', cannedResponsesURL);
75
81
 
76
82
  const httpOptions = {
77
83
  headers: new HttpHeaders({
78
84
  'Content-Type': 'application/json',
79
- Authorization: token
85
+ Authorization: this.tiledeskToken
80
86
  })
81
87
  };
82
88
 
@@ -92,7 +98,7 @@ export class CannedResponsesService {
92
98
  }
93
99
 
94
100
  public delete(token: string, projectid: string, cannedID: string){
95
- const cannedResponsesURL = this.apiUrl + projectid + "/canned/"+cannedID;
101
+ const cannedResponsesURL = this.SERVER_BASE_URL + projectid + "/canned/"+cannedID;
96
102
  this.logger.log('[CANNED-RESPONSES-SERVICE] deleteCannedResponses - URL ', cannedResponsesURL);
97
103
 
98
104
  const httpOptions = {
@@ -14,6 +14,7 @@ import { map } from 'rxjs/operators';
14
14
  // Logger
15
15
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
16
16
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
17
+ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
17
18
 
18
19
  @Injectable({
19
20
  providedIn: 'root'
@@ -26,36 +27,41 @@ export class ContactsService {
26
27
  BScontactDetail: BehaviorSubject<UserModel> = new BehaviorSubject<UserModel>(null);
27
28
 
28
29
  // private
29
- private urlRemoteContacts: string;
30
+ private SERVER_BASE_URL: string;
31
+ private tiledeskToken: string;
32
+
30
33
  private contacts: UserModel[];
31
34
  private logger: LoggerService = LoggerInstance.getInstance();
32
35
 
33
36
  constructor(
34
37
  public http: HttpClient,
35
- public appConfigProvider: AppConfigProvider
38
+ public appStorageService: AppStorageService
36
39
  ) {
37
- this.urlRemoteContacts = appConfigProvider.getConfig().apiUrl + 'chat21/contacts';
40
+ this.logger.log('[COPILOT-SERVICE] HELLO !');
38
41
  }
39
42
 
43
+ initialize(serverBaseUrl: string) {
44
+ this.logger.log('[COPILOT-SERVICE] - initialize serverBaseUrl', serverBaseUrl);
45
+ this.SERVER_BASE_URL = serverBaseUrl;
46
+ this.tiledeskToken = this.appStorageService.getItem('tiledeskToken')
47
+ }
40
48
 
41
- // initialize() {}
42
49
 
43
50
  /** */
44
- public loadContactsFromUrl(token: string) {
45
- this.contacts = [];
46
- this.logger.log('[CONTACT-SERVICE] loadContactsFromUrl token', token);
47
- this.logger.log('[CONTACT-SERVICE] loadContactsFromUrl urlRemoteContacts', this.urlRemoteContacts)
51
+ public loadContactsFromUrl() {
52
+ const url = this.SERVER_BASE_URL + 'chat21/contacts';
53
+ this.logger.log('[CONTACT-SERVICE] loadContactsFromUrl urlRemoteContacts', url)
48
54
  // if (this.urlRemoteContacts.startsWith('http') && token) {
49
55
  const that = this;
50
56
  const httpOptions = {
51
57
  headers: new HttpHeaders({
52
58
  'Content-Type': 'application/json',
53
- Authorization: token
59
+ Authorization: this.tiledeskToken
54
60
  })
55
61
  };
56
-
57
-
58
- this.http.get<any[]>(this.urlRemoteContacts, httpOptions).subscribe(users => {
62
+
63
+ this.contacts = [];
64
+ this.http.get<any[]>(url, httpOptions).subscribe(users => {
59
65
  this.logger.log('[CONTACT-SERVICE] loadContactsFromUrl users ', users);
60
66
  users.forEach(user => {
61
67
  const member = that.createCompleteUser(user);
@@ -103,24 +109,21 @@ export class ContactsService {
103
109
  * @param token
104
110
  * @param uid
105
111
  */
106
- public loadContactDetail(token: string, uid: string) {
112
+ public loadContactDetail(uid: string) {
107
113
  this.contacts = [];
114
+ const url = this.SERVER_BASE_URL + 'chat21/contacts/' + uid;
108
115
  this.logger.log('[CONTACT-SERVICE] - loadContactDetail - uid ', uid);
109
- this.logger.log('[CONTACT-SERVICE] - loadContactDetail - token ', token);
110
- const urlRemoteContactDetail = this.urlRemoteContacts + '/' + uid;
111
116
  // if (urlRemoteContactDetail.startsWith('http') && token) {
112
117
 
113
118
  const httpOptions = {
114
119
  headers: new HttpHeaders({
115
120
  'Content-Type': 'application/json',
116
- Authorization: token
121
+ Authorization: this.tiledeskToken
117
122
  })
118
123
  };
119
124
  // const postData = {};
120
- this.logger.log('[CONTACT-SERVICE] - loadContactDetail url ', urlRemoteContactDetail);
121
- return this.http
122
- .get(urlRemoteContactDetail, httpOptions)
123
- .pipe(map((res: any) => {
125
+ this.logger.log('[CONTACT-SERVICE] - loadContactDetail url ', url);
126
+ return this.http.get(url, httpOptions).pipe(map((res: any) => {
124
127
  this.logger.log('[CONTACT-SERVICE] - loadContactDetail - loadContactDetail RES ', res);
125
128
  if (res.uid) {
126
129
  let user = this.createCompleteUser(res)
@@ -5,61 +5,65 @@ import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service
5
5
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
6
6
  import { map, filter } from 'rxjs/operators';
7
7
  import * as uuid from 'uuid';
8
+ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
8
9
 
9
10
  @Injectable({
10
11
  providedIn: 'root'
11
12
  })
12
13
  export class CopilotService {
13
14
 
14
- private apiUrl: string;
15
+ private SERVER_BASE_URL: string;
16
+ private tiledeskToken: string;
17
+
15
18
  private logger: LoggerService = LoggerInstance.getInstance();
16
19
 
17
20
  constructor(
18
21
  public http: HttpClient,
19
- public appConfigProvider: AppConfigProvider
22
+ public appStorageService: AppStorageService
20
23
  ) {
21
24
  this.logger.log('[COPILOT-SERVICE] HELLO !');
22
- this.apiUrl = appConfigProvider.getConfig().apiUrl;
23
- this.logger.log('[COPILOT-SERVICE] apiUrl ', this.apiUrl);
24
25
  }
25
26
 
26
- public getAll(token: string, projectid: string, conversWith: string) {
27
- const url = this.apiUrl + projectid + "/copilot?request_id=" + conversWith;
28
- this.logger.log('[COPILOT-SERVICE] getAllSuggestions - URL ', url);
27
+ initialize(serverBaseUrl: string) {
28
+ this.logger.log('[COPILOT-SERVICE] - initialize serverBaseUrl', serverBaseUrl);
29
+ this.SERVER_BASE_URL = serverBaseUrl;
30
+ this.tiledeskToken = this.appStorageService.getItem('tiledeskToken')
31
+ }
32
+
33
+ public getAll(projectid: string, conversWith: string) {
34
+ const url = this.SERVER_BASE_URL + projectid + "/copilot?request_id=" + conversWith;
35
+ this.logger.log('[COPILOT-SERVICE] getAllSuggestions - URL ', url);
29
36
 
30
- const httpOptions = {
31
- headers: new HttpHeaders({
32
- 'Content-Type': 'application/json',
33
- Authorization: token
34
- })
35
- };
37
+ const httpOptions = {
38
+ headers: new HttpHeaders({
39
+ 'Content-Type': 'application/json',
40
+ Authorization: this.tiledeskToken
41
+ })
42
+ };
36
43
 
37
- return this.http.get(url, httpOptions).pipe(map((res: [any]) => {
38
- let suggestions = res.filter(el => el !== null).map(el => ({ ...el, _id: uuid.v4()} ));
39
- this.logger.log('[COPILOT-SERVICE] getCannedResponses - RES ', suggestions);
40
- return suggestions
41
- }))
44
+ return this.http.get(url, httpOptions).pipe(map((res: [any]) => {
45
+ let suggestions = res.filter(el => el !== null).map(el => ({ ...el, _id: uuid.v4()} ));
46
+ return suggestions
47
+ }))
42
48
  }
43
49
 
44
- public getAllFromQuestion(question: string, token: string, projectid: string, conversWith: string) {
45
- const url = this.apiUrl + projectid + "/copilot?request_id=" + conversWith;
50
+ public getAllFromQuestion(question: string, projectid: string, conversWith: string) {
51
+ const url = this.SERVER_BASE_URL + projectid + "/copilot?request_id=" + conversWith;
46
52
  this.logger.log('[COPILOT-SERVICE] getAllSuggestions - URL ', url);
47
53
 
48
54
  const httpOptions = {
49
55
  headers: new HttpHeaders({
50
56
  'Content-Type': 'application/json',
51
- Authorization: token
57
+ Authorization: this.tiledeskToken
52
58
  })
53
59
  };
54
60
 
55
- console.log('questionnnn', question)
56
61
  const body = {
57
62
  text: question
58
63
  };
59
64
 
60
65
  return this.http.post(url, body, httpOptions).pipe(map((res: [any]) => {
61
66
  let suggestions = res.filter(el => el !== null).map(el => ({ ...el, _id: uuid.v4()} ));
62
- this.logger.log('[COPILOT-SERVICE] getCannedResponses - RES ', suggestions);
63
67
  return suggestions
64
68
  }))
65
69
  }
@@ -1,12 +1,12 @@
1
1
  import { TestBed } from '@angular/core/testing';
2
2
 
3
- import { ProjectsService } from './projects.service';
3
+ import { ProjectService } from './project.service';
4
4
 
5
5
  describe('ProjectsService', () => {
6
6
  beforeEach(() => TestBed.configureTestingModule({}));
7
7
 
8
8
  it('should be created', () => {
9
- const service: ProjectsService = TestBed.get(ProjectsService);
9
+ const service: ProjectService = TestBed.get(ProjectService);
10
10
  expect(service).toBeTruthy();
11
11
  });
12
12
  });
@@ -0,0 +1,68 @@
1
+ import { HttpClient, HttpHeaders } from '@angular/common/http';
2
+ import { Injectable } from '@angular/core';
3
+ import { map } from 'rxjs/operators';
4
+ import { Project } from 'src/chat21-core/models/projects';
5
+ import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
6
+ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
7
+ import { AppConfigProvider } from '../app-config';
8
+ import { Observable } from 'rxjs';
9
+ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
10
+
11
+ @Injectable({
12
+ providedIn: 'root'
13
+ })
14
+ export class ProjectService {
15
+
16
+ private SERVER_BASE_URL: string;
17
+ private tiledeskToken: string;
18
+
19
+ private logger: LoggerService = LoggerInstance.getInstance();
20
+
21
+ constructor(
22
+ public http: HttpClient,
23
+ public appStorageService: AppStorageService
24
+ ) {
25
+
26
+ this.logger.log('[PROJECTS-SERVICE] HELLO !');
27
+ }
28
+
29
+ initialize(serverBaseUrl: string) {
30
+ this.logger.log('[TILEDESK-PROJECTS-SERV] - initialize serverBaseUrl', serverBaseUrl);
31
+ this.SERVER_BASE_URL = serverBaseUrl;
32
+ this.tiledeskToken = this.appStorageService.getItem('tiledeskToken')
33
+ }
34
+
35
+ public getProjects(): Observable<Project[]> {
36
+ const url = this.SERVER_BASE_URL + "projects/";
37
+ this.logger.log('[PROJECTS-SERVICE] getProjects - URL ', url);
38
+
39
+ const httpOptions = {
40
+ headers: new HttpHeaders({
41
+ 'Content-Type': 'application/json',
42
+ Authorization: this.tiledeskToken
43
+ })
44
+ };
45
+
46
+ return this.http.get(url, httpOptions).pipe(map((res: Project[]) => {
47
+ this.logger.log('[PROJECTS-SERVICE] getProjects - RES ', res);
48
+ return res
49
+ }))
50
+ }
51
+
52
+ public getProjectById(id: string): Observable<Project> {
53
+ const url = this.SERVER_BASE_URL + 'projects/' + id;
54
+ this.logger.log('[TILEDESK-SERVICE] - GET PROJECT BY ID URL', url);
55
+
56
+ const httpOptions = {
57
+ headers: new HttpHeaders({
58
+ 'Content-Type': 'application/json',
59
+ Authorization: this.tiledeskToken
60
+ })
61
+ };
62
+ return this.http.get(url, httpOptions).pipe(map((project: Project) => {
63
+ this.logger.log('[TILEDESK-SERVICE] GET PROJECT BY ID URL - RES ', project);
64
+ return project
65
+ }))
66
+ }
67
+
68
+ }
@@ -89,41 +89,6 @@ export class TiledeskService {
89
89
  }))
90
90
  }
91
91
 
92
- public getProjects(token: string) {
93
- const url = this.apiUrl + 'projects/';
94
- this.logger.log('[TILEDESK-SERVICE] - GET PROJECTS URL', url);
95
-
96
- const httpOptions = {
97
- headers: new HttpHeaders({
98
- 'Content-Type': 'application/json',
99
- Authorization: token
100
- })
101
- };
102
-
103
- return this.http.get(url, httpOptions).pipe(map((res: any) => {
104
- this.logger.log('[TILEDESK-SERVICE] GET PROJECTS - RES ', res);
105
- return res
106
- }))
107
- }
108
-
109
-
110
- public getProjectById( token: string , id: string) {
111
- const url = this.apiUrl + 'projects/' + id;
112
- this.logger.log('[TILEDESK-SERVICE] - GET PROJECT BY ID URL', url);
113
-
114
- const httpOptions = {
115
- headers: new HttpHeaders({
116
- 'Content-Type': 'application/json',
117
- Authorization: token
118
- })
119
- };
120
- return this.http.get(url, httpOptions).pipe(map((res: any) => {
121
- this.logger.log('[TILEDESK-SERVICE] GET PROJECT BY ID URL - RES ', res);
122
- return res
123
- }))
124
- }
125
-
126
-
127
92
  public getProjectUsersByProjectId(project_id: string, token: string) {
128
93
  const url = this.apiUrl + project_id + '/project_users/';
129
94
  this.logger.log('[TILEDESK-SERVICE] - GET PROJECT-USER URL', url);
@@ -0,0 +1,140 @@
1
+ import { Injectable, OnInit } from "@angular/core";
2
+ import { PLAN_NAME } from "src/chat21-core/utils/constants";
3
+ import { LoggerService } from "src/chat21-core/providers/abstract/logger.service";
4
+ import { LoggerInstance } from "src/chat21-core/providers/logger/loggerInstance";
5
+ import { Project } from 'src/chat21-core/models/projects';
6
+ import { ProjectService } from "../services/projects/project.service";
7
+ import { AppConfigProvider } from "../services/app-config";
8
+
9
+ @Injectable({
10
+ providedIn: 'root'
11
+ })
12
+ export class ProjectPlanUtils {
13
+
14
+ project: Project
15
+
16
+ private logger: LoggerService = LoggerInstance.getInstance()
17
+ constructor(
18
+ private projectService: ProjectService
19
+ ){
20
+ }
21
+
22
+ checkProjectProfileFeature(project: Project, feature: string): boolean{
23
+
24
+ this.logger.log('[PROJECT_PROFILE] checkProjectProfileFeature -->', feature, project)
25
+
26
+ // this.project = await this.projectService.getProjectById(projectId).toPromise()
27
+ this.project = project;
28
+
29
+ if(this.project.profile.type === 'free'){
30
+ this.logger.log('[PROJECT_PROFILE] USECASE: Free Plan')
31
+ if(this.project.trialExpired === false){
32
+ // ------------------------------------------------------------------------
33
+ // USECASE: Free Plan (TRIAL ACTIVE i.e. Scale trial)
34
+ // ------------------------------------------------------------------------
35
+ return true
36
+ }else {
37
+ // ------------------------------------------------------------------------
38
+ // USECASE: Free Plan (TRIAL EXPIRED)
39
+ // ------------------------------------------------------------------------
40
+ return false
41
+ }
42
+ }else if(this.project.profile.type === 'payment'){
43
+ // ------------------------------------------------------------------------
44
+ // USECASE: PAYMENT Plan (TRIAL ACTIVE i.e. Scale trial)
45
+ // ------------------------------------------------------------------------
46
+ this.logger.log('[PROJECT_PROFILE] USECASE: payment')
47
+
48
+ /** check if the subscription is Active or NOT */
49
+ if(this.project.isActiveSubscription === false){
50
+ return false
51
+ }
52
+
53
+ /** get che current keyName for the current project (usefull to compare later)*/
54
+ /** before: MAKE A COMPARE BETWEEN OLD AND NEW PROJECT TYPE
55
+ * LEGEND:
56
+ * - A --> D
57
+ * - B --> E
58
+ * - C --> F
59
+ */
60
+ let currentPlanNameKey: string[] = ['A']
61
+ switch(this.project.profile.name.toUpperCase()){
62
+ case PLAN_NAME.A.toUpperCase(): {
63
+ this.logger.log('case A')
64
+ currentPlanNameKey = Object.keys(PLAN_NAME).filter(x => PLAN_NAME[x].toUpperCase() == PLAN_NAME.D.toUpperCase());
65
+ break;
66
+ }
67
+ case PLAN_NAME.B.toUpperCase(): {
68
+ this.logger.log('case B')
69
+ currentPlanNameKey = Object.keys(PLAN_NAME).filter(x => PLAN_NAME[x].toUpperCase() == PLAN_NAME.E.toUpperCase());
70
+ break;
71
+ }
72
+ case PLAN_NAME.C.toUpperCase(): {
73
+ this.logger.log('case C')
74
+ currentPlanNameKey = Object.keys(PLAN_NAME).filter(x => PLAN_NAME[x].toUpperCase() == PLAN_NAME.F.toUpperCase());
75
+ break;
76
+ }
77
+ default: {
78
+ currentPlanNameKey = Object.keys(PLAN_NAME).filter(x => PLAN_NAME[x].toUpperCase() == this.project.profile.name.toUpperCase());
79
+ break;
80
+ }
81
+
82
+ }
83
+
84
+ /** compare enums: current action enum plan >= current prject profile enum name (UPPERCASE) */
85
+ // if(currentPlanNameKey.length>0){
86
+ // let actionPlanNameKey: string[] = Object.keys(PLAN_NAME).filter(x => PLAN_NAME[x].toUpperCase() == actionPlanAvailability.toUpperCase());
87
+ // this.logger.log('check plan availability: currentPlanNameKey VS actionPlanNameKey -->', currentPlanNameKey[0], actionPlanNameKey[0])
88
+ // // this.logger.log('check plan availability: PLAN currentPlanNameKey VS PLAN actionPlanNameKey -->', PLAN_NAME[currentPlanNameKey[0]]> PLAN_NAME[actionPlanNameKey[0]])
89
+ // return currentPlanNameKey[0] >= actionPlanNameKey[0] ? true: false;
90
+ // }
91
+
92
+ /**check only CUSTOM PLAN */
93
+ this.logger.log('[PROJECT_PROFILE] USECASE: currentPlanNameKey', currentPlanNameKey[0], PLAN_NAME.F)
94
+ if(PLAN_NAME[currentPlanNameKey[0]] === PLAN_NAME.F){
95
+ return this.checkIfIsEnabledInProject(feature)
96
+ }
97
+
98
+ return false
99
+ }
100
+
101
+ }
102
+
103
+ public checkIfIsEnabledInProject(featureKey: string): boolean{
104
+
105
+ this.logger.log('[PROJECT_PROFILE] checkIfIsEnabledInProject -->', featureKey, this.project)
106
+ if (this.project.profile['customization'] === undefined){
107
+ // ------------------------------------------------------------------------
108
+ // USECASE: customization obj not exist
109
+ // ------------------------------------------------------------------------
110
+ return false
111
+ } else if(this.project.profile['customization'] && this.project.profile['customization'][featureKey]){
112
+ // ------------------------------------------------------------------------
113
+ // USECASE: customization obj exist AND customization.actions obj not exist
114
+ // ------------------------------------------------------------------------
115
+ return true
116
+ }
117
+ return false
118
+ }
119
+
120
+ checkPlanIsExpired(project: Project): boolean {
121
+ let check: boolean = false
122
+
123
+ //case FREE plan
124
+ if(project && project.trialExpired && project.profile.type=== 'trial'){
125
+ check = true
126
+ }else if(project && !project.trialExpired && project.profile.type=== 'trial'){
127
+ check = false
128
+ }
129
+
130
+ //case PAYMENT plan
131
+ if(project && project.isActiveSubscription && project.profile.type=== 'payment'){
132
+ check = true
133
+ }else if(project && !project.isActiveSubscription && project.profile.type=== 'payment'){
134
+ check = false
135
+ }
136
+
137
+ return check
138
+ }
139
+
140
+ }
@@ -141,6 +141,9 @@ export enum PLAN_NAME {
141
141
  A = 'Growth',
142
142
  B = 'Scale',
143
143
  C = 'Plus',
144
+ D = 'Basic',
145
+ E = 'Premium',
146
+ F = 'Custom'
144
147
  }
145
148
 
146
149
  export const tranlatedLanguage = ['it', 'en', 'de', 'es', 'pt', 'fr', 'ru', 'tr', 'sr', 'ar', 'uk', 'sv', 'az', 'kk', 'uz']
@@ -1,43 +0,0 @@
1
- import { HttpClient, HttpHeaders } from '@angular/common/http';
2
- import { Injectable } from '@angular/core';
3
- import { map } from 'rxjs/operators';
4
- import { Project } from 'src/chat21-core/models/projects';
5
- import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
6
- import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
7
- import { AppConfigProvider } from '../app-config';
8
-
9
- @Injectable({
10
- providedIn: 'root'
11
- })
12
- export class ProjectsService {
13
-
14
- private apiUrl: string;
15
- private logger: LoggerService = LoggerInstance.getInstance();
16
-
17
- constructor(
18
- public http: HttpClient,
19
- public appConfigProvider: AppConfigProvider
20
- ) {
21
-
22
- this.logger.log('[PROJECTS-SERVICE] HELLO !');
23
- this.apiUrl = appConfigProvider.getConfig().apiUrl;
24
- this.logger.log('[PROJECTS-SERVICE] apiUrl ', this.apiUrl);
25
- }
26
-
27
- public getProjects(token: string) {
28
- const url = this.apiUrl + "projects/";
29
- this.logger.log('[PROJECTS-SERVICE] getProjects - URL ', url);
30
-
31
- const httpOptions = {
32
- headers: new HttpHeaders({
33
- 'Content-Type': 'application/json',
34
- Authorization: token
35
- })
36
- };
37
-
38
- return this.http.get(url, httpOptions).pipe(map((res: Project[]) => {
39
- this.logger.log('[PROJECTS-SERVICE] getProjects - RES ', res);
40
- return res
41
- }))
42
- }
43
- }