From a3ba286cda42ad4439f7896d9a17f42e20276fc4 Mon Sep 17 00:00:00 2001 From: Joao Graca Date: Tue, 26 Aug 2025 12:37:31 +0100 Subject: [PATCH] ticket attachments implemented --- lib/client.js | 2 ++ lib/ticketattachment.js | 51 ++++++++++++++++++++++++++++++++++++++++ lib/ticketattachments.js | 14 +++++++++++ 3 files changed, 67 insertions(+) create mode 100644 lib/ticketattachment.js create mode 100644 lib/ticketattachments.js diff --git a/lib/client.js b/lib/client.js index dce48c0..924f31a 100644 --- a/lib/client.js +++ b/lib/client.js @@ -186,6 +186,8 @@ var client = function(config) { var kayako = function(config) { this.client = new client(config); this.ticket = new(require('./ticket'))(this.client); + this.ticketattachment = new(require('./ticketattachment'))(this.client); + this.ticketattachments = new(require('./ticketattachments'))(this.client); this.ticketpost = new(require('./ticketpost'))(this.client); this.ticketcount = new(require('./ticketcount'))(this.client); this.tickets = new(require('./tickets'))(this.client); diff --git a/lib/ticketattachment.js b/lib/ticketattachment.js new file mode 100644 index 0000000..12d7a7c --- /dev/null +++ b/lib/ticketattachment.js @@ -0,0 +1,51 @@ +var utils = require('node-kayako/lib/utils'); +var querystring = require('querystring'); +var crypto = require('crypto'); + +var ticketattachment = function (client, xml) { + this.client = client; + if (xml) { + utils.parse_xml(this, xml); + } +}; + +ticketattachment.prototype.post = function (optionsp, callback) { + var client = this.client; + var salt = crypto.randomBytes(20).toString('base64'); + var options = { + e: '/Tickets/TicketAttachment', + apikey: this.client.get_apikey(), + salt: salt, + signature: this.client.generate_signature(salt) + }; + + options.ticketid = optionsp.ticketid; + options.ticketpostid = optionsp.ticketpostid; + options.filename = optionsp.filename; + options.contents = optionsp.contents; + + var postdata = querystring.stringify(options); + + var opts = { + path: '/api/index.php', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': postdata.length + } + }; + + this.client.request(opts, postdata, function (err, res) { + if (err) { + callback(err); + } else { + client.parse_items(res.data, client, ticketattachment, callback); + } + }); +}; + +ticketattachment.prototype.get = function (ticketid, id, callback) { + this.client.get_item('/Tickets/TicketAttachment/' + ticketid + '/' + id, ticketattachment, callback); +}; + +module.exports = ticketattachment; diff --git a/lib/ticketattachments.js b/lib/ticketattachments.js new file mode 100644 index 0000000..ad0dfae --- /dev/null +++ b/lib/ticketattachments.js @@ -0,0 +1,14 @@ +var utils = require('node-kayako/lib/utils'); + +var ticketattachments = function (client, xml) { + this.client = client; + if (xml) { + utils.parse_xml(this, xml); + } +}; + +ticketattachments.prototype.get = function (ticketid, callback) { + this.client.get_items('/Tickets/TicketAttachment/ListAll/' + ticketid, require('./ticketattachment'), callback); +}; + +module.exports = ticketattachments;