diff --git a/src/telegram.js b/src/telegram.js index 7359306..df0105c 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -294,7 +294,7 @@ class TelegramBot extends EventEmitter { let fileName; let fileId; if (data instanceof stream.Stream) { - fileName = URL.parse(path.basename(data.path)).pathname; + fileName = URL.parse(path.basename(data.path.toString())).pathname; formData = {}; formData[type] = { value: data, diff --git a/test/index.js b/test/index.js index f7ebb01..803dc43 100644 --- a/test/index.js +++ b/test/index.js @@ -162,6 +162,16 @@ describe('Telegram', function telegramSuite() { }); }); + describe('#_formatSendData', function _formatSendData() { + it('should handle buffer path from fs.readStream', function test() { + const bot = new Telegram(TOKEN); + const photo = fs.createReadStream(Buffer.from(`${__dirname}/bot.gif`)); + return bot.sendPhoto(USERID, photo).then(resp => { + assert.ok(is.object(resp)); + }); + }); + }); + describe('#sendPhoto', function sendPhotoSuite() { let photoId; it('should send a photo from file', function test() {