|
@ -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 IHeaderProps from 'src/app/models/header'; |
|
|
|
|
|
|
|
|
import { logOutButton, login, home } from 'src/app/constants/constants'; |
|
|
import { logOutButton, login, home } from 'src/app/constants/constants'; |
|
@ -18,6 +18,8 @@ import { HomeService } from './home.service'; |
|
|
styleUrls: ['./home.component.scss'], |
|
|
styleUrls: ['./home.component.scss'], |
|
|
}) |
|
|
}) |
|
|
export class HomeComponent { |
|
|
export class HomeComponent { |
|
|
|
|
|
@ViewChild('fileUploader') fileUploader: ElementRef; |
|
|
|
|
|
|
|
|
headerProps: IHeaderProps = { |
|
|
headerProps: IHeaderProps = { |
|
|
rightIcon: logOutButton, |
|
|
rightIcon: logOutButton, |
|
|
rightIconRoute: 'logout', |
|
|
rightIconRoute: 'logout', |
|
@ -26,13 +28,14 @@ export class HomeComponent { |
|
|
|
|
|
|
|
|
fileUploadForm: FormGroup; |
|
|
fileUploadForm: FormGroup; |
|
|
isLoading = false; |
|
|
isLoading = false; |
|
|
|
|
|
submitButton = false; |
|
|
error = ''; |
|
|
error = ''; |
|
|
isSalesForm = true; |
|
|
isSalesForm = true; |
|
|
|
|
|
submitted = false; |
|
|
|
|
|
|
|
|
file: any; |
|
|
file: any; |
|
|
arrayBuffer: any; |
|
|
arrayBuffer: any; |
|
|
filelist: any = []; |
|
|
filelist: any = []; |
|
|
arrayToBeSend: any = []; |
|
|
|
|
|
customerPhonenumbers: string[] = []; |
|
|
customerPhonenumbers: string[] = []; |
|
|
|
|
|
|
|
|
constructor( |
|
|
constructor( |
|
@ -57,29 +60,54 @@ export class HomeComponent { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
switchSalesServiceTab() { |
|
|
switchSalesServiceTab() { |
|
|
this.arrayToBeSend = []; |
|
|
|
|
|
|
|
|
this.submitButton = false; |
|
|
|
|
|
this.removeSelectedFile(); |
|
|
this.isSalesForm = !this.isSalesForm; |
|
|
this.isSalesForm = !this.isSalesForm; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
triggerWhatsappMessages(messages: object[]) { |
|
|
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) => { |
|
|
(res) => { |
|
|
console.log('success', res); |
|
|
console.log('success', res); |
|
|
this.isLoading = false; |
|
|
this.isLoading = false; |
|
|
|
|
|
// this.submitButton = true;
|
|
|
|
|
|
this.submitted = true; |
|
|
|
|
|
this.removeSelectedFile(); |
|
|
}, |
|
|
}, |
|
|
(err) => { |
|
|
(err) => { |
|
|
console.log('failed', err); |
|
|
console.log('failed', err); |
|
|
this.isLoading = false; |
|
|
this.isLoading = false; |
|
|
|
|
|
// this.submitButton = true;
|
|
|
} |
|
|
} |
|
|
) |
|
|
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
readExcelFile() { |
|
|
readExcelFile() { |
|
|
this.isLoading = true; |
|
|
this.isLoading = true; |
|
|
|
|
|
this.submitButton = false; |
|
|
let fileReader = new FileReader(); |
|
|
let fileReader = new FileReader(); |
|
|
fileReader.readAsArrayBuffer(this.file); |
|
|
fileReader.readAsArrayBuffer(this.file); |
|
|
|
|
|
|
|
@ -103,18 +131,9 @@ export class HomeComponent { |
|
|
if (this.isSalesForm) { |
|
|
if (this.isSalesForm) { |
|
|
for (let i = 0; i < this.filelist.length; i++) { |
|
|
for (let i = 0; i < this.filelist.length; i++) { |
|
|
let data = { |
|
|
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); |
|
|
phoneNumber.push(data); |
|
@ -122,31 +141,28 @@ export class HomeComponent { |
|
|
} else { |
|
|
} else { |
|
|
for (let i = 0; i < this.filelist.length; i++) { |
|
|
for (let i = 0; i < this.filelist.length; i++) { |
|
|
let data = { |
|
|
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.push(data); |
|
|
} |
|
|
} |
|
|
|
|
|
phoneNumber.shift(); |
|
|
} |
|
|
} |
|
|
// after reading file and storing all phonenumbers in an array
|
|
|
// after reading file and storing all phonenumbers in an array
|
|
|
// call whatsapp sending api function here
|
|
|
// call whatsapp sending api function here
|
|
|
|
|
|
|
|
|
this.triggerWhatsappMessages(phoneNumber); |
|
|
this.triggerWhatsappMessages(phoneNumber); |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
addfile(event: any) { |
|
|
addfile(event: any) { |
|
|
|
|
|
this.submitButton = true; |
|
|
this.file = event.target.files[0]; |
|
|
this.file = event.target.files[0]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeSelectedFile() { |
|
|
|
|
|
this.fileUploader.nativeElement.value = null; |
|
|
|
|
|
} |
|
|
} |
|
|
} |