Skip to content

Commit 9e62a9f

Browse files
author
Gabriele Panico
committed
Merge branch 'features/whatsapp-parameters-PRE' into master-pre
2 parents f4a0a06 + ca54e23 commit 9e62a9f

File tree

5 files changed

+221
-29
lines changed

5 files changed

+221
-29
lines changed

src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.html

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,65 @@
8383
</cds-select>
8484
</div>
8585

86+
<div *ngIf="selected_template" class="receiver-list">
87+
88+
<!-- <cds-whatsapp-receiver *ngIf="receiver_list.length == 0" [template]="selected_template"
89+
[receiver]="receiver_list[0]" [index]=0 (receiverValue)="onReceiverEmitted($event, 0)"
90+
(deleteReceiver)="onReceiverDeleteEmitted($event)">
91+
</cds-whatsapp-receiver>
92+
-->
93+
94+
95+
<div *ngIf="action.payload.receiver_list.length > 0">
96+
<div *ngFor="let rcv of action.payload.receiver_list; let id = index">
97+
<cds-whatsapp-receiver
98+
[template]="selected_template"
99+
[receiver]="rcv"
100+
[index]=id
101+
(receiverValue)="onReceiverEmitted($event, id)">
102+
</cds-whatsapp-receiver>
103+
</div>
104+
</div>
105+
106+
</div>
107+
108+
<hr class="custom-divider">
109+
110+
<div class="field-box">
111+
<div class="condition-container">
112+
<div class="icon-action">
113+
<img class="active-icon" src="assets/images/icons/if_condition.svg">
114+
</div>
115+
<span class="condition-text">{{'CDSCanvas.Success' | translate }}</span>
116+
</div>
117+
<cds-select id="text-condition"
118+
[items]="listOfIntents"
119+
[bindLabelSelect]="'name'"
120+
[bindValueSelect]="'value'"
121+
[itemSelected]="action?.trueIntent"
122+
[placeholder]="'CDSCanvas.SelectABlock' | translate"
123+
[clearable]="true"
124+
(onSelected)="onChangeBlockSelect($event, 'trueIntent')"
125+
(onReset)="onResetBlockSelect($event, 'trueIntent')">
126+
</cds-select>
127+
</div>
128+
129+
<div class="field-box">
130+
<div class="condition-container">
131+
<span class="condition-text">{{'CDSCanvas.Else' | translate | titlecase }}</span>
132+
</div>
133+
<cds-select id="text-condition"
134+
[items]="listOfIntents"
135+
[bindLabelSelect]="'name'"
136+
[bindValueSelect]="'value'"
137+
[itemSelected]="action?.falseIntent"
138+
[placeholder]="'CDSCanvas.SelectABlock' | translate"
139+
[clearable]="true"
140+
(onSelected)="onChangeBlockSelect($event, 'falseIntent')"
141+
(onReset)="onResetBlockSelect($event, 'falseIntent')">
142+
</cds-select>
143+
</div>
144+
86145
</div>
87146

88147
<div *ngIf="showLoader" class="loader-container">
@@ -111,26 +170,6 @@
111170
target="_blank">{{'CDSCanvas.CreateOneNow' | translate}}</a></p>
112171
</div>
113172

114-
<div *ngIf="selected_template" class="receiver-list">
115-
116-
<!-- <cds-whatsapp-receiver *ngIf="receiver_list.length == 0" [template]="selected_template"
117-
[receiver]="receiver_list[0]" [index]=0 (receiverValue)="onReceiverEmitted($event, 0)"
118-
(deleteReceiver)="onReceiverDeleteEmitted($event)">
119-
</cds-whatsapp-receiver>
120-
-->
121-
122-
123-
<div *ngIf="action.payload.receiver_list.length > 0">
124-
<div *ngFor="let rcv of action.payload.receiver_list; let id = index">
125-
<cds-whatsapp-receiver
126-
[template]="selected_template"
127-
[receiver]="rcv"
128-
[index]=id
129-
(receiverValue)="onReceiverEmitted($event, id)">
130-
</cds-whatsapp-receiver>
131-
</div>
132-
</div>
133-
134-
</div>
173+
135174

136175
</div>

src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.ts

Lines changed: 129 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { Component, ElementRef, EventEmitter, Input, OnInit, Output } from '@angular/core';
2+
import { Subscription } from 'rxjs';
3+
import { IntentService } from 'src/app/chatbot-design-studio/services/intent.service';
4+
import { TYPE_UPDATE_ACTION } from 'src/app/chatbot-design-studio/utils';
25
import { ActionSendWhatsapp } from 'src/app/models/action-model';
36
import { Intent } from 'src/app/models/intent-model';
47
import { DashboardService } from 'src/app/services/dashboard.service';
@@ -17,7 +20,19 @@ export class CdsActionSendWhatsappComponent implements OnInit {
1720
@Input() intentSelected: Intent;
1821
@Input() previewMode: boolean = true;
1922
@Output() updateAndSaveAction = new EventEmitter();
20-
23+
@Output() onConnectorChange = new EventEmitter<{type: 'create' | 'delete', fromId: string, toId: string}>()
24+
25+
listOfIntents: Array<{name: string, value: string, icon?:string}>;
26+
27+
// Connectors
28+
idIntentSelected: string;
29+
idConnectorTrue: string;
30+
idConnectorFalse: string;
31+
isConnectedTrue: boolean = false;
32+
isConnectedFalse: boolean = false;
33+
connector: any;
34+
private subscriptionChangedConnector: Subscription;
35+
2136
project_id: string;
2237

2338
templates_list = [];
@@ -32,18 +47,97 @@ export class CdsActionSendWhatsappComponent implements OnInit {
3247

3348
constructor(
3449
private dashboardService: DashboardService,
50+
private intentService: IntentService,
3551
private whatsapp: WhatsappService,
3652
public el: ElementRef
3753
) { }
3854

3955
ngOnInit(): void {
56+
this.logger.debug("[ACTION-SEND WHATSAPP] action detail: ", this.action);
57+
this.subscriptionChangedConnector = this.intentService.isChangedConnector$.subscribe((connector: any) => {
58+
this.logger.debug('[ACTION-SEND WHATSAPP] isChangedConnector -->', connector);
59+
this.connector = connector;
60+
this.updateConnector();
61+
});
62+
this.initialize();
63+
}
64+
65+
/** */
66+
ngOnDestroy() {
67+
if (this.subscriptionChangedConnector) {
68+
this.subscriptionChangedConnector.unsubscribe();
69+
}
70+
}
71+
72+
private checkConnectionStatus(){
73+
if(this.action.trueIntent){
74+
this.isConnectedTrue = true;
75+
} else {
76+
this.isConnectedTrue = false;
77+
}
78+
if(this.action.falseIntent){
79+
this.isConnectedFalse = true;
80+
} else {
81+
this.isConnectedFalse = false;
82+
}
83+
}
84+
85+
initializeConnector() {
86+
this.idIntentSelected = this.intentSelected.intent_id;
87+
this.idConnectorTrue = this.idIntentSelected+'/'+this.action._tdActionId + '/true';
88+
this.idConnectorFalse = this.idIntentSelected+'/'+this.action._tdActionId + '/false';
89+
this.listOfIntents = this.intentService.getListOfIntents();
90+
this.checkConnectionStatus();
91+
}
92+
93+
private updateConnector(){
94+
try {
95+
const array = this.connector.fromId.split("/");
96+
const idAction= array[1];
97+
if(idAction === this.action._tdActionId){
98+
if(this.connector.deleted){
99+
if(array[array.length -1] === 'true'){
100+
this.action.trueIntent = null
101+
this.isConnectedTrue = false
102+
}
103+
if(array[array.length -1] === 'false'){
104+
this.action.falseIntent = null
105+
this.isConnectedFalse = false;
106+
}
107+
if(this.connector.save)this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.CONNECTOR, element: this.connector});
108+
} else {
109+
this.logger.debug('[ACTION-SEND WHATSAPP] updateConnector', this.connector.toId, this.connector.fromId ,this.action, array[array.length-1]);
110+
if(array[array.length -1] === 'true'){
111+
this.isConnectedTrue = true;
112+
this.action.trueIntent = '#'+this.connector.toId;
113+
if(this.connector.save)this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.CONNECTOR, element: this.connector});
114+
}
115+
if(array[array.length -1] === 'false'){
116+
this.isConnectedFalse = true;
117+
if(this.action.falseIntent !== '#'+this.connector.toId){
118+
this.action.falseIntent = '#'+this.connector.toId;
119+
if(this.connector.save)this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.CONNECTOR, element: this.connector});
120+
}
121+
}
122+
}
123+
124+
}
125+
} catch (error) {
126+
this.logger.error('[ACTION-SEND WHATSAPP] updateConnector error: ', error);
127+
}
128+
}
129+
130+
private initialize(){
40131
this.project_id = this.dashboardService.projectID
41132
this.action.payload.id_project = this.project_id
42133
if (this.previewMode == false) {
43134
this.logger.log("Whatsapp static project_id: ", this.project_id);
44135
this.showLoader = true;
45136
this.getTemplates();
46137
}
138+
if(this.intentSelected){
139+
this.initializeConnector();
140+
}
47141
}
48142

49143
getTemplates() {
@@ -62,9 +156,9 @@ export class CdsActionSendWhatsappComponent implements OnInit {
62156

63157
}, error: (error) => {
64158
this.showLoader = false;
65-
this.logger.log("[SEND WHATSAPP] error get templates: ", error);
159+
this.logger.log("[ACTION-SEND WHATSAPP] error get templates: ", error);
66160
}, complete: () => {
67-
this.logger.log("[SEND WHATSAPP] get templates completed: ");
161+
this.logger.log("[ACTION-SEND WHATSAPP] get templates completed: ");
68162
if (this.action.templateName) {
69163
this.selected_template = this.templates_list.find(t => t.name === this.action.templateName);
70164
}
@@ -73,7 +167,7 @@ export class CdsActionSendWhatsappComponent implements OnInit {
73167
}
74168

75169
onChangeSelect(event) {
76-
this.logger.debug("[ACTION SEND WHATSAPP] onChangeSelect event", event);
170+
this.logger.debug("[ACTION-SEND WHATSAPP] onChangeSelect event", event);
77171
this.selected_template = event;
78172
this.action.templateName = this.selected_template.name;
79173
this.action.payload.template.name = this.selected_template.name;
@@ -100,14 +194,43 @@ export class CdsActionSendWhatsappComponent implements OnInit {
100194
this.updateAndSaveAction.emit();
101195
}
102196

103-
this.logger.debug("[ACTION WHATSAPP] Action updated ", this.action.payload);
197+
this.logger.debug("[ACTION-SEND WHATSAPP] Action updated ", this.action.payload);
198+
}
199+
}
200+
201+
onChangeBlockSelect(event:{name: string, value: string}, type: 'trueIntent' | 'falseIntent') {
202+
if(event){
203+
this.action[type]=event.value
204+
205+
switch(type){
206+
case 'trueIntent':
207+
this.onConnectorChange.emit({ type: 'create', fromId: this.idConnectorTrue, toId: this.action.trueIntent})
208+
break;
209+
case 'falseIntent':
210+
this.onConnectorChange.emit({ type: 'create', fromId: this.idConnectorFalse, toId: this.action.falseIntent})
211+
break;
212+
}
213+
this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.ACTION, element: this.action});
214+
}
215+
}
216+
217+
onResetBlockSelect(event:{name: string, value: string}, type: 'trueIntent' | 'falseIntent') {
218+
switch(type){
219+
case 'trueIntent':
220+
this.onConnectorChange.emit({ type: 'delete', fromId: this.idConnectorTrue, toId: this.action.trueIntent})
221+
break;
222+
case 'falseIntent':
223+
this.onConnectorChange.emit({ type: 'delete', fromId: this.idConnectorFalse, toId: this.action.falseIntent})
224+
break;
104225
}
226+
this.action[type] = null;
227+
this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.ACTION, element: this.action});
105228
}
106229

107230
onReceiverEmitted(event, index) {
108231
// update receiver
109232
this.action.payload.receiver_list[index] = event;
110-
this.logger.log("[ACTION WHATSAPP] Action updated ", this.action.payload);
233+
this.logger.log("[ACTION-SEND WHATSAPP] Action updated ", this.action.payload);
111234
this.updateAndSaveAction.emit()
112235
}
113236

src/app/chatbot-design-studio/cds-dashboard/cds-canvas/cds-panel-action-detail/cds-panel-action-detail.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@
386386

387387
<cds-action-send-whatsapp *ngSwitchCase="TYPE_ACTION.SEND_WHATSAPP"
388388
class="panel-response"
389+
[intentSelected]="intentSelected"
389390
[action]="elementSelected"
390-
[intentName]="intentSelected.intent_display_name"
391391
[previewMode]="false"
392+
(onConnectorChange)="onConnectorChange($event.type, $event.fromId, $event.toId)"
392393
(updateAndSaveAction)="onSaveIntent($event)">
393394
</cds-action-send-whatsapp>
394395

src/app/chatbot-design-studio/services/connector.service.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,34 @@ export class ConnectorService {
836836
}
837837
}
838838

839+
/** SEND WHATSAPP */
840+
if(action._tdActionType === TYPE_ACTION.SEND_WHATSAPP){
841+
if(action.trueIntent && action.trueIntent !== ''){
842+
idConnectorFrom = intent.intent_id+'/'+action._tdActionId + '/true';
843+
idConnectorTo = action.trueIntent.replace("#", "");
844+
if(!this.intentExists(idConnectorTo)){
845+
action.trueIntent = '';
846+
idConnectorTo = null;
847+
}
848+
this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorFrom', idConnectorFrom);
849+
this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorTo', idConnectorTo);
850+
// this.createConnectorFromId(idConnectorFrom, idConnectorTo);
851+
this.createConnector(intent, idConnectorFrom, idConnectorTo);
852+
}
853+
if(action.falseIntent && action.falseIntent !== ''){
854+
idConnectorFrom = intent.intent_id+'/'+action._tdActionId + '/false';
855+
idConnectorTo = action.falseIntent.replace("#", "");
856+
if(!this.intentExists(idConnectorTo)){
857+
action.falseIntent = '';
858+
idConnectorTo = null;
859+
}
860+
this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorFrom', idConnectorFrom);
861+
this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorTo', idConnectorTo);
862+
// this.createConnectorFromId(idConnectorFrom, idConnectorTo);
863+
this.createConnector(intent, idConnectorFrom, idConnectorTo);
864+
}
865+
}
866+
839867

840868
});
841869
}

src/app/chatbot-design-studio/services/intent.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ export class IntentService {
10941094

10951095
if(typeAction === TYPE_ACTION.SEND_WHATSAPP){
10961096
action = new ActionSendWhatsapp();
1097-
action.payload = new WhatsappBroadcast();
1097+
action.payload = new WhatsappBroadcast();
1098+
(action.payload as WhatsappBroadcast).id_project = this.intentSelected.id_project
10981099
}
10991100
return action;
11001101
}

0 commit comments

Comments
 (0)