Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
alaminAppnap authored Sep 25, 2023
1 parent 86160fc commit 3e4c659
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions SMS/message-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const path = require('path');

async function smsHistoryCreate(message,phoneNumber,response,csmsId){
try {
let respoonseData = response?.data || {};

smsHistoryCreateOnFile(message,phoneNumber,response,csmsId);
smsHistoryCreateOnFile(message,phoneNumber,respoonseData,csmsId);

/** this code for mode */

Expand Down Expand Up @@ -35,18 +36,14 @@ async function smsHistoryCreateOnFile(message,phoneNumber,response,csmsId){

let existingData = [];

if (fs.existsSync(filePath)) {
if (fs.existsSync(filePath).size !=0) {
const fileData = fs.readFileSync(filePath, 'utf-8');
if (typeof fileData === 'object') {
existingData = fileData;
} else {
existingData = JSON.parse(fileData);
}
existingData = JSON.parse(fileData);
}

existingData.push(newJsonObject);

fs.writeFileSync(filePath, (existingData));
fs.writeFileSync(filePath, existingData);

return { success: true, message: 'Message history created successfully' };
} catch (error) {
Expand Down

0 comments on commit 3e4c659

Please sign in to comment.