2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 05:17:41 +00:00

Add Buffer support to _formatSendData

This commit is contained in:
Vítor Augusto da Silva Vasconcellos 2016-01-03 00:19:06 -02:00
parent 2b94493eb5
commit 9e2a8321e9

View File

@ -9,6 +9,7 @@ var request = require('request');
var stream = require('stream');
var util = require('util');
var mime = require('mime');
var fileType = require('file-type');
var path = require('path');
var URL = require('url');
var fs = require('fs');
@ -236,6 +237,16 @@ TelegramBot.prototype._formatSendData = function (type, data) {
contentType: mime.lookup(fileName)
}
};
} else if(util.isBuffer(data)){
var filetype = fileType(data);
formData = {};
formData[type] = {
value: data,
options: {
filename: 'data.' + filetype.ext,
contentType: filetype.mime
}
};
} else if (fs.existsSync(data)) {
fileName = path.basename(data);
formData = {};