This commit is contained in:
Christopher Cookman 2024-06-11 15:25:40 -06:00
parent b1d8f88e97
commit be9aef5950
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -46,10 +46,18 @@ const pool = mariadb.createPool(config.mariadb);
const cdrPool = mariadb.createPool(config.cdrdb);
const json2csv = (obj) => {
let csv = "";
const json2csv = (obj) => { // Specifically for CDR
let csv = "call_date,src,dst,caller_id,duration,context\n";
for (let key in obj) {
csv += `${JSON.stringify(obj[key])}\n`;
data = [
obj[key].call_date,
obj[key].src,
obj[key].dst,
obj[key].clid,
obj[key].duration,
obj[key].dcontext
];
csv += data.join(",") + "\n";
}
return csv;
}
@ -1332,8 +1340,6 @@ dcClient.on('interactionCreate', async interaction => {
} else {
// Generate the CSV
const fields = ["calldate", "src", "dst", "duration", "disposition", "recordingfile"];
// put fields at the top of the csv
result.unshift(fields);
const csv = json2csv(result);
console.log(JSON.stringify(result)) // debug
const buffer = Buffer.from(csv, 'utf-8');