Skip to content

Commit

Permalink
Merge branch 'ds-johnny'
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Troisi committed Nov 15, 2023
2 parents 1a4a2dc + 286e0d9 commit 4f8fb64
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<div *ngIf="previewMode" class="cds-action-content cds-action-preview" style="position: relative;">

<div class="action-row">
<div class="action-row-left">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="none">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M20 8h-3V4H3c-1.1 0-2 .9-2 2v11h2c0 1.66 1.34 3 3 3s3-1.34 3-3h6c0 1.66 1.34 3 3 3s3-1.34 3-3h2v-5l-3-4zM6 18.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm13.5-9l1.96 2.5H17V9.5h2.5zm-1.5 9c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"/>
</svg>
</div>
<div *ngIf="action?.trackingNumber" class="action-row-right">
{{action?.trackingNumber}}
</div>
<div *ngIf="!action?.trackingNumber" class="action-row-right empty">
Enter the tracking number
</div>
</div>

</div>

<div *ngIf="!previewMode && action_locked == false" class="content-panel-intent-detail no-footer">

<div class="field-box">
<label class="title-label">Tracking Number</label>
<cds-textarea id="assignTo"
[textLimitBtn]="false"
[emojiPikerBtn]="false"
[setAttributeBtn]="true"
[minRow]="1" [maxRow]="1"
[readonly]="false"
[text]="action.trackingNumber"
[placeholder]="'Tracking number to search'"
(changeTextarea)="changeTextarea($event, 'trackingNumber')">
</cds-textarea>
</div>

<div class="field-box">
<label class="title-label">Qapla Api Key</label>
<cds-textarea id="assignTo"
[textLimitBtn]="false"
[emojiPikerBtn]="false"
[setAttributeBtn]="false"
[minRow]="1" [maxRow]="1"
[readonly]="false"
[text]="action.apiKey"
[placeholder]="'Your Api Key'"
(changeTextarea)="changeTextarea($event, 'apiKey')">
</cds-textarea>
</div>

<hr class="custom-divider">

<div class="field-box">
<label class="title-label">Status</label>
<cds-textarea id="assignTo"
[textLimitBtn]="false"
[emojiPikerBtn]="false"
[setAttributeBtn]="true"
[minRow]="1" [maxRow]="1"
[readonly]="true"
[text]="action.assignStatusTo"
(selectedAttribute)="onSelectedAttribute($event, 'assignStatusTo')"
(clearSelectedAttribute)="onSelectedAttribute($event, 'assignStatusTo')">
</cds-textarea>
</div>

<div class="field-box">
<label class="title-label">Result</label>
<cds-textarea id="assignTo"
[textLimitBtn]="false"
[emojiPikerBtn]="false"
[setAttributeBtn]="true"
[minRow]="1" [maxRow]="1"
[readonly]="true"
[text]="action.assignResultTo"
(selectedAttribute)="onSelectedAttribute($event, 'assignResultTo')"
(clearSelectedAttribute)="onSelectedAttribute($event, 'assignResultTo')">
</cds-textarea>
</div>

<div class="field-box">
<label class="title-label">Error</label>
<cds-textarea id="assignTo"
[textLimitBtn]="false"
[emojiPikerBtn]="false"
[setAttributeBtn]="true"
[minRow]="1" [maxRow]="1"
[readonly]="true"
[text]="action.assignErrorTo"
(selectedAttribute)="onSelectedAttribute($event, 'assignErrorTo')"
(clearSelectedAttribute)="onSelectedAttribute($event, 'assignErrorTo')">
</cds-textarea>
</div>

</div>

<div *ngIf="!previewMode && action_locked == true" class="content-panel-intent-detail no-footer">

<div class="block-overlay">
<span class="material-icons lock-icon">lock</span>
<p>Feature available from <b>Scale</b> plan</p>

<button id="cds-publish-btn" class="btn btn-primary cds-blue-button" type="button" (click)="goToPricing()">
<span class="material-icons">bolt</span>
Upgrade now!
</button>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

.block-overlay {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 60px;


.lock-icon {
font-size: 40px;
margin-bottom: 16px;
color: #506493b0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CdsActionQaplaComponent } from './cds-action-qapla.component';

describe('CdsActionQaplaComponent', () => {
let component: CdsActionQaplaComponent;
let fixture: ComponentFixture<CdsActionQaplaComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CdsActionQaplaComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(CdsActionQaplaComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ActionQapla } from 'src/app/models/action-model';
import { Intent } from 'src/app/models/intent-model';
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
import { variableList } from '../../../../../utils';
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
import { Project } from 'src/app/models/project-model';
import { DashboardService } from 'src/app/services/dashboard.service';
import { AppConfigService } from 'src/app/services/app-config';

@Component({
selector: 'cds-action-qapla',
templateUrl: './cds-action-qapla.component.html',
styleUrls: ['./cds-action-qapla.component.scss']
})
export class CdsActionQaplaComponent implements OnInit {

@Input() intentSelected: Intent;
@Input() action: ActionQapla;
@Input() previewMode: boolean = true;
@Output() updateAndSaveAction = new EventEmitter;

project: Project;
action_locked: boolean = false;

private logger: LoggerService = LoggerInstance.getInstance();

constructor(
private dashboardService: DashboardService,
private appConfigService: AppConfigService,
) { }

ngOnInit(): void {
console.log("[ACTION QAPLA] action:", this.action);
this.initializeAttributes();
this.project = this.dashboardService.project;
console.log("this.project: ", this.project);
this.availabilityCheck();
}

availabilityCheck() {
console.log("availabilityCheck profile plan: ", this.project.profile.name)
if (this.project.profile.name !== 'Scale' && this.project.profile.name !== 'Plus') {
console.log("availabilityCheck BLOCK ACTION!!");
this.action_locked = true;
}
}

private initializeAttributes() {
let new_attributes = [];
if (!variableList.userDefined.some(v => v.name === 'qapla_status')) {
new_attributes.push({ name: "qapla_status", value: "qapla_status" });
}
if (!variableList.userDefined.some(v => v.name === 'qapla_result')) {
new_attributes.push({ name: "qapla_result", value: "qapla_result" });
}
if (!variableList.userDefined.some(v => v.name === 'qapla_error')) {
new_attributes.push({ name: "qapla_error", value: "qapla_error" });
}
variableList.userDefined = [...variableList.userDefined, ...new_attributes];
this.logger.debug("[ACTION GPT-TASK] Initialized variableList.userDefined: ", variableList.userDefined);
}

changeTextarea($event: string, property: string) {
this.logger.debug("[ACTION QAPLA] changeTextarea event: ", $event);
this.logger.debug("[ACTION QAPLA] changeTextarea propery: ", property);
this.action[property] = $event;
console.log("[ACTION QAPLA] Action updated: ", this.action);
this.updateAndSaveAction.emit();
}

onSelectedAttribute(event, property) {
this.logger.log("[ACTION QAPLA] onEditableDivTextChange event", event)
this.logger.log("[ACTION QAPLA] onEditableDivTextChange property", property)
this.action[property] = event.value;
console.log("[ACTION QAPLA] Action updated: ", this.action);
this.updateAndSaveAction.emit();
}

goToPricing() {
let dashbordBaseUrl = this.appConfigService.getConfig().dashboardBaseUrl + '#/project/'+ this.dashboardService.projectID + '/pricing'
window.open(dashbordBaseUrl, '_self')
//this.hideShowWidget('show');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@
[action]="action"
(updateAndSaveAction)="onUpdateAndSaveAction($event)">
</cds-action-capture-user-reply>

<cds-action-qapla *ngSwitchCase="TYPE_ACTION.QAPLA"
class="panel-response"
[action]="action"
(updateAndSaveAction)="onUpdateAndSaveAction($event)">
</cds-action-qapla>

</div>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@
(updateAndSaveAction)="onSaveIntent($event)"
(onConnectorChange)="onConnectorChange($event.type, $event.fromId, $event.toId)">
</cds-action-capture-user-reply>

<cds-action-qapla *ngSwitchCase="typeAction.QAPLA"
class="panel-response"
[intentSelected]="intentSelected"
[action]="elementSelected"
[project_id]="project_id"
[previewMode]="false"
(updateAndSaveAction)="onSaveIntent($event)">
</cds-action-qapla>

<!-- <cds-action-assign-function *ngSwitchCase="typeAction.ASSIGN_FUNCTION"
[action]="elementSelected">
Expand Down
2 changes: 2 additions & 0 deletions src/app/chatbot-design-studio/chatbot-design-studio.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ import { CdsRuleComponent } from './cds-dashboard/cds-rule/cds-rule.component';

import { CdsOptionsComponent } from './cds-dashboard/cds-canvas/cds-options/cds-options.component';
import { CdsPanelConnectorMenuComponent } from './cds-dashboard/cds-canvas/cds-panel-connector-menu/cds-panel-connector-menu.component';
import { CdsActionQaplaComponent } from './cds-dashboard/cds-canvas/actions/list/cds-action-qapla/cds-action-qapla.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -351,6 +352,7 @@ import { CdsPanelConnectorMenuComponent } from './cds-dashboard/cds-canvas/cds-p
CdsRuleComponent,
CdsOptionsComponent,
CdsPanelConnectorMenuComponent,
CdsActionQaplaComponent,

],
imports: [
Expand Down
52 changes: 50 additions & 2 deletions src/app/chatbot-design-studio/services/intent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Subject, BehaviorSubject } from 'rxjs';
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';

import { ActionReply, ActionAgent, ActionAssignFunction, ActionAssignVariable, ActionChangeDepartment, ActionClose, ActionDeleteVariable, ActionEmail, ActionHideMessage, ActionIntentConnected, ActionJsonCondition, ActionOnlineAgent, ActionOpenHours, ActionRandomReply, ActionReplaceBot, ActionWait, ActionWebRequest, Command, Wait, Message, Expression, Action, ActionAskGPT, ActionWhatsappAttribute, ActionWhatsappStatic, ActionWebRequestV2, ActionGPTTask, ActionCaptureUserReply } from 'src/app/models/action-model';
import { ActionReply, ActionAgent, ActionAssignFunction, ActionAssignVariable, ActionChangeDepartment, ActionClose, ActionDeleteVariable, ActionEmail, ActionHideMessage, ActionIntentConnected, ActionJsonCondition, ActionOnlineAgent, ActionOpenHours, ActionRandomReply, ActionReplaceBot, ActionWait, ActionWebRequest, Command, Wait, Message, Expression, Action, ActionAskGPT, ActionWhatsappAttribute, ActionWhatsappStatic, ActionWebRequestV2, ActionGPTTask, ActionCaptureUserReply, ActionQapla } from 'src/app/models/action-model';
import { Intent } from 'src/app/models/intent-model';
import { FaqService } from 'src/app/services/faq.service';
import { FaqKbService } from 'src/app/services/faq-kb.service';
Expand All @@ -11,6 +11,9 @@ import { ConnectorService } from '../services/connector.service';
import { ControllerService } from '../services/controller.service';
import { StageService } from '../services/stage.service';
import { DashboardService } from 'src/app/services/dashboard.service';
import { TiledeskAuthService } from 'src/chat21-core/providers/tiledesk/tiledesk-auth.service';
import { environment } from 'src/environments/environment';
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';

/** CLASSE DI SERVICES PER TUTTE LE AZIONI RIFERITE AD OGNI SINGOLO INTENT **/

Expand Down Expand Up @@ -57,7 +60,7 @@ export class IntentService {
public arrayREDO: Array<any> = [];
public lastActionUndoRedo: boolean;


private logger: LoggerService = LoggerInstance.getInstance();

constructor(
private faqService: FaqService,
Expand All @@ -66,6 +69,7 @@ export class IntentService {
private controllerService: ControllerService,
private stageService: StageService,
private dashboardService: DashboardService,
private tiledeskAuthService: TiledeskAuthService
) { }


Expand Down Expand Up @@ -887,11 +891,55 @@ export class IntentService {
if(typeAction === TYPE_ACTION.CAPTURE_USER_REPLY) {
action = new ActionCaptureUserReply();
}
if(typeAction === TYPE_ACTION.QAPLA) {
action = new ActionQapla();
action.assignStatusTo = 'qapla_status';
action.assignResultTo = 'qapla_result';
action.assignErrorTo = 'qapla_error';
this.segmentActionAdded(TYPE_ACTION.QAPLA);
}
return action;
}
// END ATTRIBUTE FUNCTIONS //


private segmentActionAdded(action_type: string){
let chatbot = this.dashboardService.selectedChatbot;
let id_project = this.dashboardService.projectID;
const that = this
let user = this.tiledeskAuthService.getCurrentUser();

if(window['analytics']){
try {
window['analytics'].page("CDS, Added Action", {
version: environment.VERSION
});
} catch (err) {
this.logger.error('Event: CDS Added Action ', action_type, ' [page] error', err);
}

try {
window['analytics'].identify(user.uid, {
name: user.firstname + ' ' + user.lastname,
email: user.email,
});
} catch (err) {
this.logger.error('Event: CDS Added Action ', action_type, ' [identify] error', err);
}
// Segments
try {
window['analytics'].track('Action Added', {
"username": user.firstname + ' ' + user.lastname,
"userId": user.uid,
"chatbot_id": chatbot._id,
"project_id": id_project,
"action_type": action_type
});
} catch (err) {
this.logger.error('Event: CDS Added Action ', action_type, ' [track] error', err);
}
}
}


public patchButtons(buttons, idAction){
Expand Down
4 changes: 3 additions & 1 deletion src/app/chatbot-design-studio/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export enum TYPE_ACTION {
OPEN_HOURS = 'ifopenhours',
HIDE_MESSAGE = 'hmessage',
JSON_CONDITION = 'jsoncondition',
CAPTURE_USER_REPLY = 'capture_user_reply'
CAPTURE_USER_REPLY = 'capture_user_reply',
QAPLA = "qapla"
}

export enum TYPE_ACTION_CATEGORY {
Expand Down Expand Up @@ -263,6 +264,7 @@ export const ACTIONS_LIST: {[key: string]: {name: string, category: TYPE_ACTION_
CHANGE_DEPARTMENT: { name: 'Change dept', category: TYPE_ACTION_CATEGORY.SPECIAL, type: TYPE_ACTION.CHANGE_DEPARTMENT, src: "assets/images/actions/change_department.svg", status: "active" },
// ASSIGN_FUNCTION: { name: 'Set function', category: TYPE_ACTION_CATEGORY.NEW, type: TYPE_ACTION.ASSIGN_FUNCTION, src: "assets/images/actions/assign_var.svg" },
CAPTURE_USER_REPLY: { name: 'Capture User Reply', category: TYPE_ACTION_CATEGORY.FLOW, type: TYPE_ACTION.CAPTURE_USER_REPLY, src: "assets/images/actions/capture_user_reply.svg", status: "active", description: 'This action allow to capture the user reply' },
QAPLA: { name: 'Qapla', category: TYPE_ACTION_CATEGORY.INTEGRATIONS, type: TYPE_ACTION.QAPLA, src: "assets/images/actions/qapla.svg", status: "active", description: 'This action allow to connect with Qapla' },
}

export const EVENTS_LIST = {
Expand Down
Loading

0 comments on commit 4f8fb64

Please sign in to comment.