diff --git a/lib/Client.js b/lib/Client.js index 6d6e62870..7d2c96445 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -551,7 +551,20 @@ var Client = (function () { self.resolveDestination(destination).then(send)["catch"](error); function send(destination) { - request.post(Endpoints.CHANNELS + "/" + destination + "/messages"); + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", fstream, fileName).end(function (err, res) { + + if (err) { + error(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + callback(null, msg); + resolve(msg); + } + } + }); } function error(err) { diff --git a/src/Client.js b/src/Client.js index ad7084d90..e2e99d0b9 100644 --- a/src/Client.js +++ b/src/Client.js @@ -558,15 +558,34 @@ class Client { } else { fstream = file; } - + self.resolveDestination(destination).then(send).catch(error); function send(destination) { request .post(`${Endpoints.CHANNELS}/${destination}/messages`) + .set("authorization", self.token) + .attach("file", fstream, fileName) + .end(function (err, res) { + + if (err) { + error(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + callback(null, msg); + resolve(msg); + } + + + } + + }); } - - function error(err){ + + function error(err) { callback(err); reject(err); } @@ -585,7 +604,7 @@ class Client { var mentions = resolveMentions(); self.resolveDestination(destination).then(send).catch(error); - function error(err){ + function error(err) { callback(err); reject(err); } diff --git a/test/bot.js b/test/bot.js index e0c2eb940..b04c7ac29 100644 --- a/test/bot.js +++ b/test/bot.js @@ -79,11 +79,18 @@ function success12(_server){ function success13(){ console.log("test 12 successful"); - mybot.leaveServer(server).then(success14).catch(error); + mybot.sendFile(server, "./test/image.png").then(function(msg){ + mybot.deleteMessage(msg).then(success14).catch(error); + }).catch(error); } -function success14(){ +function success14(msg){ console.log("test 13 successful"); + mybot.leaveServer(server).then(success15).catch(error); +} + +function success15(){ + console.log("test 14 successful"); mybot.logout().then(done).catch(error); } diff --git a/test/image.png b/test/image.png new file mode 100644 index 000000000..253ecefb0 Binary files /dev/null and b/test/image.png differ