From 4e1fc895600495ae84d6fd7503b16c1b76a78d31 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 11 Jun 2024 15:05:00 -0600 Subject: [PATCH] Add json parser --- index.js | 6 ++---- package-lock.json | 20 ++++++++++++++++++++ package.json | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 1d89659..8fe4cdd 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const embeds = require("./embeds.json") const axios = require('axios'); const ping = require("ping") var commandsBase = require("./commands.json") +const json2csv = require("json2csv"); const ssh2 = require('ssh2') const sshConn = new ssh2.Client(); // find first file in .ssh local to the script @@ -1323,10 +1324,7 @@ dcClient.on('interactionCreate', async interaction => { } else { // Generate the CSV const fields = ["calldate", "src", "dst", "duration", "disposition", "recordingfile"]; - const json2csvParser = new Json2csvParser({ - fields - }); - const csv = json2csvParser.parse(result); + const csv = json2csv.parse(result); const buffer = Buffer.from(csv, 'utf-8'); const attachment = new MessageAttachment(buffer, 'cdr.csv'); interaction.editReply({ diff --git a/package-lock.json b/package-lock.json index de567f8..ea24f8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "colors": "^1.4.0", "discord.js": "^14.7.1", "freepbx-graphql-client": "^0.1.1", + "json2csv": "github:juanjoDiaz/json2csv", "mariadb": "^3.2.0", "ping": "^0.4.4", "sqlite3": "^5.1.4", @@ -828,6 +829,25 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "optional": true }, + "node_modules/json2csv": { + "version": "7.0.6", + "resolved": "git+ssh://git@github.com/juanjoDiaz/json2csv.git#8c7895c11321410968893519fe86a60d98269ed0", + "license": "MIT", + "workspaces": [ + "packages/cli", + "packages/formatters", + "packages/node", + "packages/plainjs", + "packages/test-helpers", + "packages/transforms", + "packages/whatwg", + "packages/test-performance" + ], + "engines": { + "node": ">=14.17.0", + "npm": ">=7.0.0" + } + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", diff --git a/package.json b/package.json index 715f7af..fa7bf75 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "colors": "^1.4.0", "discord.js": "^14.7.1", "freepbx-graphql-client": "^0.1.1", + "json2csv": "github:juanjoDiaz/json2csv", "mariadb": "^3.2.0", "ping": "^0.4.4", "sqlite3": "^5.1.4",