From be9aef5950df20aa37fc0a3273fb77dc86489dfa Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 11 Jun 2024 15:25:40 -0600 Subject: [PATCH] Buh --- index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 72326a3..21945a7 100644 --- a/index.js +++ b/index.js @@ -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');