Buh
This commit is contained in:
parent
b1d8f88e97
commit
be9aef5950
16
index.js
16
index.js
|
@ -46,10 +46,18 @@ const pool = mariadb.createPool(config.mariadb);
|
||||||
const cdrPool = mariadb.createPool(config.cdrdb);
|
const cdrPool = mariadb.createPool(config.cdrdb);
|
||||||
|
|
||||||
|
|
||||||
const json2csv = (obj) => {
|
const json2csv = (obj) => { // Specifically for CDR
|
||||||
let csv = "";
|
let csv = "call_date,src,dst,caller_id,duration,context\n";
|
||||||
for (let key in obj) {
|
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;
|
return csv;
|
||||||
}
|
}
|
||||||
|
@ -1332,8 +1340,6 @@ dcClient.on('interactionCreate', async interaction => {
|
||||||
} else {
|
} else {
|
||||||
// Generate the CSV
|
// Generate the CSV
|
||||||
const fields = ["calldate", "src", "dst", "duration", "disposition", "recordingfile"];
|
const fields = ["calldate", "src", "dst", "duration", "disposition", "recordingfile"];
|
||||||
// put fields at the top of the csv
|
|
||||||
result.unshift(fields);
|
|
||||||
const csv = json2csv(result);
|
const csv = json2csv(result);
|
||||||
console.log(JSON.stringify(result)) // debug
|
console.log(JSON.stringify(result)) // debug
|
||||||
const buffer = Buffer.from(csv, 'utf-8');
|
const buffer = Buffer.from(csv, 'utf-8');
|
||||||
|
|
Loading…
Reference in a new issue