From fafff198cd5871ed7af258aa4ba8ffa9cef8024f Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Date: Wed, 24 Nov 2021 16:36:40 +0530 Subject: [PATCH] Updating api to send bulk numbers messages. --- src/app/pages/home/home.component.ts | 75 ++++++++++++++-------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 94eae49..3bf554b 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -61,26 +61,9 @@ export class HomeComponent { this.isSalesForm = !this.isSalesForm; } - triggerWhatsappMessages(phoneNumber: string[]) { + triggerWhatsappMessages(messages: object[]) { const httpBody = { - messages: [ - { - from: '447491163530', - // TODO: need check if we can send array here - to: phoneNumber[1], - messageId: 'a28dd97c-1ffb-4fcf-99f1-0b557ed381da', - content: { - templateName: 'infobip_kz_test_hsm_2', - templateData: { - body: { - placeholders: ['BFL Credit Card'], - }, - }, - language: 'en_GB', - }, - callbackData: 'Callback data', - }, - ], + messages }; this.homeService.sendWhatsApp(httpBody).subscribe( @@ -89,13 +72,13 @@ export class HomeComponent { this.isLoading = false; }, (err) => { - console.log('failed',err); + console.log('failed', err); this.isLoading = false; } ) } - readExcelFile(){ + readExcelFile() { this.isLoading = true; let fileReader = new FileReader(); fileReader.readAsArrayBuffer(this.file); @@ -104,9 +87,9 @@ export class HomeComponent { this.arrayBuffer = fileReader.result; let data = new Uint8Array(this.arrayBuffer); let arr = new Array(); - let phoneNumber: string[] = []; + let phoneNumber: object[] = []; - for (let i = 0; i != data.length; ++i){ + for (let i = 0; i != data.length; ++i) { arr[i] = String.fromCharCode(data[i]); } @@ -115,29 +98,45 @@ export class HomeComponent { let first_sheet_name = workbook.SheetNames[0]; let worksheet = workbook.Sheets[first_sheet_name]; this.filelist = XLSX.utils.sheet_to_json(worksheet, { raw: true }); - + // pull data according to upload file type if (this.isSalesForm) { for (let i = 0; i < this.filelist.length; i++) { - var details = { - 'CUSTOMER NAME': this.filelist[i]['CUSTOMER NAME'], - 'PHONE NUMBER': this.filelist[i]['PHONE NUMBER'], - 'LEAD ID': this.filelist[i]['LEAD ID'], - 'DATE OF ENQUIRY': this.filelist[i]['DATE OF ENQUIRY'], + 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', + }, + callbackData: 'Callback data', }; - this.arrayToBeSend.push(details); - phoneNumber.push(this.filelist[i]['PHONE NUMBER']); + + phoneNumber.push(data); } } else { for (let i = 0; i < this.filelist.length; i++) { - var details = { - 'CUSTOMER NAME': this.filelist[i]['Customer'], - 'PHONE NUMBER': this.filelist[i]['Mobile No'], - 'LEAD ID': this.filelist[i]['__EMPTY'], - 'DATE OF ENQUIRY': this.filelist[i]['Ready For Invoice Date Time'], + 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', + }, + callbackData: 'Callback data', }; - this.arrayToBeSend.push(details); - phoneNumber.push(this.filelist[i]['PHONE NUMBER']); + + phoneNumber.push(data); } } // after reading file and storing all phonenumbers in an array