From 206f8cfe1fb413793cdf3110692fe57bf4e619ad Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 26 Aug 2015 13:12:51 +0100 Subject: [PATCH] Added error resolving --- lib/Client.js | 11 +++++++++++ src/Client.js | 28 +++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 21b4ce745..e5133c518 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -545,6 +545,17 @@ var Client = (function () { } else { fstream = file; } + + self.resolveDestination(destination).then(send)["catch"](error); + + function send(destination) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages"); + } + + function error(err) { + callback(err); + reject(err); + } }); } }, { diff --git a/src/Client.js b/src/Client.js index c350381b8..6d96c4401 100644 --- a/src/Client.js +++ b/src/Client.js @@ -545,23 +545,33 @@ class Client { } sendFile(destination, file, callback = function (err, msg) { }) { - + var self = this; - - return new Promise(function(resolve, reject){ - + + return new Promise(function (resolve, reject) { + var fstream; - - if(typeof file === "string" || file instanceof String){ + + if (typeof file === "string" || file instanceof String) { fstream = fs.createReadStream(file); - }else{ + } else { fstream = file; } + self.resolveDestination(destination).then(send).catch(error); + + function send(destination) { + request + .post(`${Endpoints.CHANNELS}/${destination}/messages`) + } - + function error(err){ + callback(err); + reject(err); + } + }); - + } sendMessage(destination, message, callback = function (err, msg) { }, premessage = "") {