Skip to content

Commit

Permalink
Issue #ED-0000 merge: Merge pull request #130 from swayangjit/main
Browse files Browse the repository at this point in the history
Issue #ED-0000 merge: Merged 'release-2.0.0' with main
  • Loading branch information
swayangjit authored May 8, 2024
2 parents 76e8cae + 56aa9e0 commit ed1e0b6
Show file tree
Hide file tree
Showing 40 changed files with 541 additions and 135 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
resValue("string", "app_id", "${app_id}")
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 15
versionCode 17
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
Expand Down
2 changes: 1 addition & 1 deletion android/variables.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
minSdkVersion = 23
minSdkVersion = 26
compileSdkVersion = 33
targetSdkVersion = 33
androidxActivityVersion = '1.7.0'
Expand Down
120 changes: 78 additions & 42 deletions src/app/components/bot-messages/bot-messages.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, NgZone, OnInit, Output, ViewChild } from '@angular/core';
import { IonContent, Platform } from '@ionic/angular';
import { IonContent, ModalController } from '@ionic/angular';
import { BotMessage } from 'src/app/appConstants';
import { AppHeaderService, BotApiService, RecordingService, StorageService } from 'src/app/services';
import { Keyboard } from "@capacitor/keyboard";
Expand All @@ -10,6 +10,8 @@ import { TelemetryGeneratorService } from 'src/app/services/telemetry/telemetry.
import { CorrelationData } from 'src/app/services/telemetry/models/telemetry';
import { ChatMessage } from 'src/app/services/bot/db/models/chat.message';
import { v4 as uuidv4 } from "uuid";
import { BotPermissionComponent } from '../bot-permission/bot-permission.component';
import { Router } from '@angular/router';

@Component({
selector: 'app-bot-messages',
Expand All @@ -21,7 +23,6 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
textMessage: string = ''
chat!: BotMessage;
defaultLoaderMsg!: BotMessage;
botStartTimeStamp = Date.now();
@Input() config: any = {};
@Output() botMessageEvent = new EventEmitter();
@ViewChild('recordbtn', { read: ElementRef }) recordbtn: ElementRef | any;
Expand All @@ -32,33 +33,24 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
durationDisplay = '';
disabled = false;
audioRef!: HTMLAudioElement;
perModalOpen: boolean = false;
constructor(
private record: RecordingService,
private ngZone: NgZone,
private headerService: AppHeaderService,
private messageApi: BotApiService,
private translate: TranslateService,
private telemetryGeneratorService: TelemetryGeneratorService,
private storage: StorageService,
private platform: Platform
private modalCtrl: ModalController,
private router: Router,
private headerService: AppHeaderService
) {
this.defaultLoaderMsg = {identifier: "", message: this.translate.instant('Loading...'), messageType: 'text', displayMsg: this.translate.instant('Loading...'), type: 'received', time: '', timeStamp: '', readMore: false, likeMsg: false, dislikeMsg: false, requestId: ""};
this.botMessages = [];
this.audioRef = new Audio();
}

ngOnInit() {
this.initialiseBot();
this.platform.backButton.subscribeWithPriority(11, async () => {
this.handleBackNavigation();
});
this.headerService.headerEventEmitted$.subscribe((name: any) => {
if (name == "back" && !this.navigated) {
this.navigated = true;
console.log('bot message back event ');
this.handleBackNavigation();
}
})
Keyboard.addListener('keyboardWillShow', () => {
console.log('keyboard will show');
this.content.scrollToBottom();
Expand All @@ -84,10 +76,60 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
});
}

ngOnChanges() {
async checkBotPermission() {
if (!this.perModalOpen) {
this.perModalOpen = true
const modal = await this.modalCtrl.create({
component: BotPermissionComponent,
componentProps: {
type: this.config.type
},
cssClass: 'add-to-pitara',
breakpoints: [0, 1],
showBackdrop: false,
backdropDismiss: false,
initialBreakpoint: 1,
handle: false,
handleBehavior: "none"
});
await modal.present();
await modal.onDidDismiss().then((res) => {
this.perModalOpen = false;
if(res.data.type === "decline") {
this.telemetryGeneratorService.generateInteractTelemetry('CLICK', 'decline-bot', 'bot-message', 'bot-message');
this.router.navigate(['/tabs/home']);
}
this.telemetryGeneratorService.generateInteractTelemetry('CLICK', 'accept-bot', 'bot-message', 'bot-message');
})
}
}

async ngOnChanges() {
console.log('ng onchanges ', this.config);
if(this.config.disable) {
this.disabled = false
}
this.headerService.deviceBackbtnEmitted$.subscribe((ev: any) => {
if(ev.name == 'backBtn') {
if(this.modalCtrl) {
this.modalCtrl.dismiss({type: 'decline'})
}
this.handleBackNavigation()
}
})

this.headerService.headerEventEmitted$.subscribe((name: any) => {
if(name == 'back') {
this.handleBackNavigation()
}
})
if(await this.storage.getData(this.config.type) === 'false') {
this.checkBotPermission();
}
this.initialiseBot();
if (this.config?.notification && this.config?.notif?.body) {
this.textMessage = this.config.notif.body;
this.disabled = false;
this.handleMessage();
}
}
Expand All @@ -101,6 +143,21 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
this.record.gestureControl(this.recordbtn);
}

handleBackNavigation() {
if (this.botMessages.length > 0) {
this.botMessages.forEach(msg => {
if (msg.messageType == 'audio') {
if(this.audioRef) {
if(msg.audio) {
msg.audio.play = false;
}
this.audioRef.pause();
}
}
});
}
}

async initialiseBot() {
this.botMessages = [];
let textMsg = `WELCOME_TO_${this.config.type.toUpperCase()}_SAKHI`;
Expand Down Expand Up @@ -137,6 +194,7 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
})
console.log("botMessages ", this.botMessages);
});
this.botMessageEvent.emit({msg: this.botMessages})
if(this.config.notif) {
this.textMessage = this.config.notif.body;
this.handleMessage();
Expand All @@ -153,6 +211,7 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
this.chat.timeStamp = Date.now()
this.botMessages.push(this.chat);
this.saveChatMessage(this.chat);
this.botMessageEvent.emit({msg: this.botMessages})
this.content.scrollToBottom(300).then(() => {
this.content.scrollToBottom(300)
})
Expand Down Expand Up @@ -240,6 +299,7 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
this.disabled = false;
}
})
this.botMessageEvent.emit({msg: this.botMessages})
}).catch(e => {
this.disabled = false;
console.log('catch error ', e);
Expand All @@ -254,6 +314,7 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
}
}
this.saveChatMessage(this.botMessages[index-1]);
this.botMessageEvent.emit({msg: this.botMessages})
})
}

Expand Down Expand Up @@ -317,31 +378,6 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
this.audioRef.onended = () => {audio.play = false; this.audioRef.pause();}
}

handleBackNavigation() {
let botDuration = Date.now() - this.botStartTimeStamp;
if (this.botMessages.length > 0) {
let result = { audio: 0, text: 0 };
this.botMessages.forEach(msg => {
if (msg.messageType == 'text') {
result.text++;
} else if (msg.messageType == 'audio') {
result.audio++;
if(this.audioRef) {
if(msg.audio) {
msg.audio.play = false;
}
this.audioRef.pause();
}
}
});
console.log('result count ', result);
this.botMessageEvent.emit({ audio: result.audio, text: result.text, duration: botDuration/1000 })
} else {
this.botMessageEvent.emit({ audio: 0, text: 0, duration: botDuration/1000 })
}
this.botMessages = [];
}

async cancelRecording() {
console.log('cancel recording');
await this.record.stopRecognition('audio').then(res => {
Expand Down Expand Up @@ -380,7 +416,7 @@ export class BotMessagesComponent implements OnInit, AfterViewInit {
console.log('long press end');
await this.record.stopRecognition('audio').then(async result => {
console.log('result on recorded data ', result);
if(result.value && result.value.recordDataBase64) {
if(result?.value?.recordDataBase64) {
this.chat = {identifier: "", message: '', messageType: '', displayMsg: "", audio: { file: '', duration: '', play: false }, type: 'sent', time: new Date().toLocaleTimeString('en', { hour: '2-digit', minute: '2-digit' }), timeStamp: '', readMore: false, likeMsg: false, dislikeMsg: false, requestId: "" }
const recordData = result.value.recordDataBase64;
console.log('..................', result, this.durationDisplay);
Expand Down
11 changes: 11 additions & 0 deletions src/app/components/bot-permission/bot-permission.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="inner-content">
<ion-toolbar>
<ion-item lines="none">
<ion-label>{{'DISCLAIMER_BOT_MSG' | translate}}</ion-label>
</ion-item>
</ion-toolbar>
<ion-toolbar class="buttons">
<ion-button class="btn-info decline" slot="end" shape="round" fill="outline" (click)="handleClick('decline')">{{"Decline" | translate }}</ion-button>
<ion-button class="btn-info" slot="end" shape="round" (click)="handleClick('accept')">{{"Accept" | translate }}</ion-button>
</ion-toolbar>
</div>
42 changes: 42 additions & 0 deletions src/app/components/bot-permission/bot-permission.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.buttons {
padding: 0 1rem;
}

ion-button {
text-wrap: wrap;
}

ion-label {
text-align: center;
}

.btn-info{
width: 40%;
color: var(--ion-color-primary-contrast);
--background: var(--ion-color-tertiary);
font-size: 0.75rem;
font-family: Noto Sans;
font-weight: 700;
text-transform: uppercase;
line-height: 19.60px;
word-wrap: break-word;
padding: 5px;
text-wrap: wrap;
text-align: center;
}

.decline{
--color: var(--ion-color-tertiary);
--background: white;
}

ion-modal {
--height: 50%;
--border-radius: 1rem;
--box-shadow: 0 0.625rem 0.938rem -0.188rem rgb(0 0 0 / 0.1), 0 0.25rem 0.375rem -0.25rem rgb(0 0 0 / 0.1);
}

ion-modal::part(backdrop) {
background: rgba(209, 213, 219);
opacity: 1;
}
24 changes: 24 additions & 0 deletions src/app/components/bot-permission/bot-permission.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';

import { BotPermissionComponent } from './bot-permission.component';

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

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ BotPermissionComponent ],
imports: [IonicModule.forRoot()]
}).compileComponents();

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
31 changes: 31 additions & 0 deletions src/app/components/bot-permission/bot-permission.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ModalController, NavParams } from '@ionic/angular';
import { StorageService } from 'src/app/services';

@Component({
selector: 'app-bot-permission',
templateUrl: './bot-permission.component.html',
styleUrls: ['./bot-permission.component.scss'],
})
export class BotPermissionComponent implements OnInit {
botType = '';
botPremission: any = false;
constructor(
private router: Router,
private modal: ModalController,
private storage: StorageService,
private navParams: NavParams
) { }

async ngOnInit() {
this.botType = this.navParams.get('type')
}

async handleClick(type: string) {
if(type == 'accept') {
await this.storage.setData(this.botType, 'true')
}
this.modal.dismiss({type});
}
}
7 changes: 5 additions & 2 deletions src/app/components/components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RecordingAlertComponent } from './recording-alert/recording-alert.compo
import { QrcodePopupComponent } from './qrcode-popup/qrcode-popup.component';
import { UploadLocalComponent } from './upload-local/upload-local.component';
import { AppUpdateComponent } from './app-update/app-update.component';
import { BotPermissionComponent } from './bot-permission/bot-permission.component';

@NgModule({
declarations: [
Expand All @@ -32,7 +33,8 @@ import { AppUpdateComponent } from './app-update/app-update.component';
RecordingAlertComponent,
QrcodePopupComponent,
UploadLocalComponent,
AppUpdateComponent
AppUpdateComponent,
BotPermissionComponent
],
imports: [
CommonModule,
Expand All @@ -55,7 +57,8 @@ import { AppUpdateComponent } from './app-update/app-update.component';
RecordingAlertComponent,
QrcodePopupComponent,
UploadLocalComponent,
AppUpdateComponent
AppUpdateComponent,
BotPermissionComponent
],
providers: [UtilService, TelemetryService, StorageService],
schemas: [
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/parent-sakhi/parent-sakhi.page.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<ion-content [fullscreen]="true">
<app-bot-messages [config]="config" (botMessageEvent)="handleBotEvent($event)"></app-bot-messages>
<app-bot-messages *ngIf="parentBot" [config]="config" (botMessageEvent)="handleBotEvent($event)"></app-bot-messages>
</ion-content>
Loading

0 comments on commit ed1e0b6

Please sign in to comment.