From 5d73db10a7de5728ba520fec63f5e12a4462010f Mon Sep 17 00:00:00 2001 From: Gabriele Panico Date: Mon, 11 Nov 2024 10:32:15 +0100 Subject: [PATCH] added: success/else connectors in send-whatsapp action --- .../cds-action-send-whatsapp.component.html | 81 ++++++++--- .../cds-action-send-whatsapp.component.ts | 135 +++++++++++++++++- .../cds-panel-action-detail.component.html | 3 +- .../services/connector.service.ts | 28 ++++ .../services/intent.service.ts | 3 +- 5 files changed, 221 insertions(+), 29 deletions(-) diff --git a/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.html b/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.html index 706b7ecc..61137e21 100644 --- a/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.html +++ b/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.html @@ -83,6 +83,65 @@ +
+ + + + +
+
+ + +
+
+ +
+ +
+ +
+
+
+ +
+ {{'CDSCanvas.Success' | translate }} +
+ + +
+ +
+
+ {{'CDSCanvas.Else' | translate | titlecase }} +
+ + +
+
@@ -111,26 +170,6 @@ target="_blank">{{'CDSCanvas.CreateOneNow' | translate}}

-
- - - - -
-
- - -
-
- -
+ diff --git a/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.ts b/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.ts index 6ef98feb..69457bfe 100644 --- a/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.ts +++ b/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/actions/list/cds-action-send-whatsapp/cds-action-send-whatsapp.component.ts @@ -1,4 +1,7 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { Subscription } from 'rxjs'; +import { IntentService } from 'src/app/chatbot-design-studio/services/intent.service'; +import { TYPE_UPDATE_ACTION } from 'src/app/chatbot-design-studio/utils'; import { ActionSendWhatsapp } from 'src/app/models/action-model'; import { Intent } from 'src/app/models/intent-model'; import { DashboardService } from 'src/app/services/dashboard.service'; @@ -17,7 +20,19 @@ export class CdsActionSendWhatsappComponent implements OnInit { @Input() intentSelected: Intent; @Input() previewMode: boolean = true; @Output() updateAndSaveAction = new EventEmitter(); - + @Output() onConnectorChange = new EventEmitter<{type: 'create' | 'delete', fromId: string, toId: string}>() + + listOfIntents: Array<{name: string, value: string, icon?:string}>; + + // Connectors + idIntentSelected: string; + idConnectorTrue: string; + idConnectorFalse: string; + isConnectedTrue: boolean = false; + isConnectedFalse: boolean = false; + connector: any; + private subscriptionChangedConnector: Subscription; + project_id: string; templates_list = []; @@ -32,11 +47,87 @@ export class CdsActionSendWhatsappComponent implements OnInit { constructor( private dashboardService: DashboardService, + private intentService: IntentService, private whatsapp: WhatsappService, public el: ElementRef ) { } ngOnInit(): void { + this.logger.debug("[ACTION-SEND WHATSAPP] action detail: ", this.action); + this.subscriptionChangedConnector = this.intentService.isChangedConnector$.subscribe((connector: any) => { + this.logger.debug('[ACTION-SEND WHATSAPP] isChangedConnector -->', connector); + this.connector = connector; + this.updateConnector(); + }); + this.initialize(); + } + + /** */ + ngOnDestroy() { + if (this.subscriptionChangedConnector) { + this.subscriptionChangedConnector.unsubscribe(); + } + } + + private checkConnectionStatus(){ + if(this.action.trueIntent){ + this.isConnectedTrue = true; + } else { + this.isConnectedTrue = false; + } + if(this.action.falseIntent){ + this.isConnectedFalse = true; + } else { + this.isConnectedFalse = false; + } + } + + initializeConnector() { + this.idIntentSelected = this.intentSelected.intent_id; + this.idConnectorTrue = this.idIntentSelected+'/'+this.action._tdActionId + '/true'; + this.idConnectorFalse = this.idIntentSelected+'/'+this.action._tdActionId + '/false'; + this.listOfIntents = this.intentService.getListOfIntents(); + this.checkConnectionStatus(); + } + + private updateConnector(){ + try { + const array = this.connector.fromId.split("/"); + const idAction= array[1]; + if(idAction === this.action._tdActionId){ + if(this.connector.deleted){ + if(array[array.length -1] === 'true'){ + this.action.trueIntent = null + this.isConnectedTrue = false + } + if(array[array.length -1] === 'false'){ + this.action.falseIntent = null + this.isConnectedFalse = false; + } + if(this.connector.save)this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.CONNECTOR, element: this.connector}); + } else { + this.logger.debug('[ACTION-SEND WHATSAPP] updateConnector', this.connector.toId, this.connector.fromId ,this.action, array[array.length-1]); + if(array[array.length -1] === 'true'){ + this.isConnectedTrue = true; + this.action.trueIntent = '#'+this.connector.toId; + if(this.connector.save)this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.CONNECTOR, element: this.connector}); + } + if(array[array.length -1] === 'false'){ + this.isConnectedFalse = true; + if(this.action.falseIntent !== '#'+this.connector.toId){ + this.action.falseIntent = '#'+this.connector.toId; + if(this.connector.save)this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.CONNECTOR, element: this.connector}); + } + } + } + + } + } catch (error) { + this.logger.error('[ACTION-SEND WHATSAPP] updateConnector error: ', error); + } + } + + private initialize(){ this.project_id = this.dashboardService.projectID this.action.payload.id_project = this.project_id if (this.previewMode == false) { @@ -44,6 +135,9 @@ export class CdsActionSendWhatsappComponent implements OnInit { this.showLoader = true; this.getTemplates(); } + if(this.intentSelected){ + this.initializeConnector(); + } } getTemplates() { @@ -62,9 +156,9 @@ export class CdsActionSendWhatsappComponent implements OnInit { }, error: (error) => { this.showLoader = false; - this.logger.log("[SEND WHATSAPP] error get templates: ", error); + this.logger.log("[ACTION-SEND WHATSAPP] error get templates: ", error); }, complete: () => { - this.logger.log("[SEND WHATSAPP] get templates completed: "); + this.logger.log("[ACTION-SEND WHATSAPP] get templates completed: "); if (this.action.templateName) { this.selected_template = this.templates_list.find(t => t.name === this.action.templateName); } @@ -73,7 +167,7 @@ export class CdsActionSendWhatsappComponent implements OnInit { } onChangeSelect(event) { - this.logger.debug("[ACTION SEND WHATSAPP] onChangeSelect event", event); + this.logger.debug("[ACTION-SEND WHATSAPP] onChangeSelect event", event); this.selected_template = event; this.action.templateName = this.selected_template.name; this.action.payload.template.name = this.selected_template.name; @@ -100,14 +194,43 @@ export class CdsActionSendWhatsappComponent implements OnInit { this.updateAndSaveAction.emit(); } - this.logger.debug("[ACTION WHATSAPP] Action updated ", this.action.payload); + this.logger.debug("[ACTION-SEND WHATSAPP] Action updated ", this.action.payload); + } + } + + onChangeBlockSelect(event:{name: string, value: string}, type: 'trueIntent' | 'falseIntent') { + if(event){ + this.action[type]=event.value + + switch(type){ + case 'trueIntent': + this.onConnectorChange.emit({ type: 'create', fromId: this.idConnectorTrue, toId: this.action.trueIntent}) + break; + case 'falseIntent': + this.onConnectorChange.emit({ type: 'create', fromId: this.idConnectorFalse, toId: this.action.falseIntent}) + break; + } + this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.ACTION, element: this.action}); + } + } + + onResetBlockSelect(event:{name: string, value: string}, type: 'trueIntent' | 'falseIntent') { + switch(type){ + case 'trueIntent': + this.onConnectorChange.emit({ type: 'delete', fromId: this.idConnectorTrue, toId: this.action.trueIntent}) + break; + case 'falseIntent': + this.onConnectorChange.emit({ type: 'delete', fromId: this.idConnectorFalse, toId: this.action.falseIntent}) + break; } + this.action[type] = null; + this.updateAndSaveAction.emit({type: TYPE_UPDATE_ACTION.ACTION, element: this.action}); } onReceiverEmitted(event, index) { // update receiver this.action.payload.receiver_list[index] = event; - this.logger.log("[ACTION WHATSAPP] Action updated ", this.action.payload); + this.logger.log("[ACTION-SEND WHATSAPP] Action updated ", this.action.payload); this.updateAndSaveAction.emit() } diff --git a/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/cds-panel-action-detail/cds-panel-action-detail.component.html b/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/cds-panel-action-detail/cds-panel-action-detail.component.html index 01978e76..79a9f9cc 100644 --- a/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/cds-panel-action-detail/cds-panel-action-detail.component.html +++ b/src/app/chatbot-design-studio/cds-dashboard/cds-canvas/cds-panel-action-detail/cds-panel-action-detail.component.html @@ -386,9 +386,10 @@ diff --git a/src/app/chatbot-design-studio/services/connector.service.ts b/src/app/chatbot-design-studio/services/connector.service.ts index 749d3be8..5abbc716 100644 --- a/src/app/chatbot-design-studio/services/connector.service.ts +++ b/src/app/chatbot-design-studio/services/connector.service.ts @@ -836,6 +836,34 @@ export class ConnectorService { } } + /** SEND WHATSAPP */ + if(action._tdActionType === TYPE_ACTION.SEND_WHATSAPP){ + if(action.trueIntent && action.trueIntent !== ''){ + idConnectorFrom = intent.intent_id+'/'+action._tdActionId + '/true'; + idConnectorTo = action.trueIntent.replace("#", ""); + if(!this.intentExists(idConnectorTo)){ + action.trueIntent = ''; + idConnectorTo = null; + } + this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorFrom', idConnectorFrom); + this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorTo', idConnectorTo); + // this.createConnectorFromId(idConnectorFrom, idConnectorTo); + this.createConnector(intent, idConnectorFrom, idConnectorTo); + } + if(action.falseIntent && action.falseIntent !== ''){ + idConnectorFrom = intent.intent_id+'/'+action._tdActionId + '/false'; + idConnectorTo = action.falseIntent.replace("#", ""); + if(!this.intentExists(idConnectorTo)){ + action.falseIntent = ''; + idConnectorTo = null; + } + this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorFrom', idConnectorFrom); + this.logger.log('[CONNECTOR-SERV] - ONLINE_AGENTS ACTION -> idConnectorTo', idConnectorTo); + // this.createConnectorFromId(idConnectorFrom, idConnectorTo); + this.createConnector(intent, idConnectorFrom, idConnectorTo); + } + } + }); } diff --git a/src/app/chatbot-design-studio/services/intent.service.ts b/src/app/chatbot-design-studio/services/intent.service.ts index 0d1c3531..dc1ce609 100644 --- a/src/app/chatbot-design-studio/services/intent.service.ts +++ b/src/app/chatbot-design-studio/services/intent.service.ts @@ -1094,7 +1094,8 @@ export class IntentService { if(typeAction === TYPE_ACTION.SEND_WHATSAPP){ action = new ActionSendWhatsapp(); - action.payload = new WhatsappBroadcast(); + action.payload = new WhatsappBroadcast(); + (action.payload as WhatsappBroadcast).id_project = this.intentSelected.id_project } return action; }