diff --git a/src/app/pages/home/home.component.html b/src/app/pages/home/home.component.html index f64fbf3..be79c26 100644 --- a/src/app/pages/home/home.component.html +++ b/src/app/pages/home/home.component.html @@ -21,17 +21,31 @@ class="user-input font-body-small-bold file-input" placeholder="Upload sales file" (change)="addfile($event)" + #fileUploader /> - + +

+ File Uploaded Successfully +

+
+ +
+

{{ error }}

diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 3bf554b..c18def3 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import IHeaderProps from 'src/app/models/header'; import { logOutButton, login, home } from 'src/app/constants/constants'; @@ -18,6 +18,8 @@ import { HomeService } from './home.service'; styleUrls: ['./home.component.scss'], }) export class HomeComponent { + @ViewChild('fileUploader') fileUploader: ElementRef; + headerProps: IHeaderProps = { rightIcon: logOutButton, rightIconRoute: 'logout', @@ -26,13 +28,14 @@ export class HomeComponent { fileUploadForm: FormGroup; isLoading = false; + submitButton = false; error = ''; isSalesForm = true; + submitted = false; file: any; arrayBuffer: any; filelist: any = []; - arrayToBeSend: any = []; customerPhonenumbers: string[] = []; constructor( @@ -57,29 +60,54 @@ export class HomeComponent { } switchSalesServiceTab() { - this.arrayToBeSend = []; + this.submitButton = false; + this.removeSelectedFile(); this.isSalesForm = !this.isSalesForm; } triggerWhatsappMessages(messages: object[]) { - const httpBody = { - messages + let feedbackURL = 'https://be18n8dnwum.typeform.com/to/OBJbe7fB'; + if (!this.isSalesForm) { + feedbackURL = 'https://be18n8dnwum.typeform.com/to/OBJbe7fB'; + } + const omniBody = { + scenarioKey: '0A9B6D3A044E5EF5D38E688900202DD8', + destinations: messages, + sms: { + text: 'Hi, Thank you. Bajaj Auto Test Message.', + regional: { + indiaDlt: { + contentTemplateId: '1107161477011893589', + principalEntityId: '1101635620000025441', + }, + }, + }, + whatsApp: { + templateName: 'infobip_kz_test_hsm_2', + templateData: ['feedback URL: ' + feedbackURL], + language: 'en_GB', + }, }; - this.homeService.sendWhatsApp(httpBody).subscribe( + this.homeService.sendOmni(omniBody).subscribe( (res) => { console.log('success', res); this.isLoading = false; + // this.submitButton = true; + this.submitted = true; + this.removeSelectedFile(); }, (err) => { console.log('failed', err); this.isLoading = false; + // this.submitButton = true; } - ) + ); } readExcelFile() { this.isLoading = true; + this.submitButton = false; let fileReader = new FileReader(); fileReader.readAsArrayBuffer(this.file); @@ -103,18 +131,9 @@ export class HomeComponent { if (this.isSalesForm) { for (let i = 0; i < this.filelist.length; i++) { let data = { - from: '447491163530', - to: this.filelist[i]['PHONE NUMBER'], - content: { - templateName: 'infobip_kz_test_hsm_2', - templateData: { - body: { - placeholders: [this.filelist[i]['CUSTOMER NAME']], - }, - }, - language: 'en_GB', + to: { + phoneNumber: '91' + this.filelist[i]['PHONE NUMBER'], }, - callbackData: 'Callback data', }; phoneNumber.push(data); @@ -122,31 +141,28 @@ export class HomeComponent { } else { for (let i = 0; i < this.filelist.length; i++) { let data = { - from: '447491163530', - to: this.filelist[i]['Mobile No'], - content: { - templateName: 'infobip_kz_test_hsm_2', - templateData: { - body: { - placeholders: [this.filelist[i]['Customer']], - }, - }, - language: 'en_GB', + to: { + phoneNumber: '91' + this.filelist[i]['Mobile No'], }, - callbackData: 'Callback data', }; phoneNumber.push(data); } + phoneNumber.shift(); } // after reading file and storing all phonenumbers in an array // call whatsapp sending api function here + this.triggerWhatsappMessages(phoneNumber); }; } addfile(event: any) { + this.submitButton = true; this.file = event.target.files[0]; } + removeSelectedFile() { + this.fileUploader.nativeElement.value = null; + } } diff --git a/src/app/pages/home/home.service.ts b/src/app/pages/home/home.service.ts index 39cfd35..4dd9780 100644 --- a/src/app/pages/home/home.service.ts +++ b/src/app/pages/home/home.service.ts @@ -7,7 +7,7 @@ import { IHomeRequest, IHomeResponse } from '../../../app/model/home'; const httpOptions = { headers: new HttpHeaders({ - 'authorization': + authorization: 'App 2b8cba9008e1da2f2733ff8300cf1973-dc928670-56f9-4a29-8725-69239d669e74', }), }; @@ -15,14 +15,18 @@ const httpOptions = { const whatsAppUrl = 'https://mpwyr4.api.infobip.com/whatsapp/1/message/template'; +const omniUrl = 'https://mpwyr4.api.infobip.com/omni/1/advanced'; @Injectable({ providedIn: 'root', }) export class HomeService { - constructor(private http: HttpClient) {} sendWhatsApp(body: any): Observable { return this.http.post(whatsAppUrl, body, httpOptions); } + + sendOmni(body: any): Observable { + return this.http.post(omniUrl, body, httpOptions); + } } diff --git a/tsconfig.json b/tsconfig.json index 6df8283..da08591 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "baseUrl": "./", "outDir": "./dist/out-tsc", "forceConsistentCasingInFileNames": true, + "strictPropertyInitialization": false, "strict": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, @@ -16,10 +17,7 @@ "importHelpers": true, "target": "es2017", "module": "es2020", - "lib": [ - "es2018", - "dom" - ] + "lib": ["es2018", "dom"] }, "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false,