2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

Added the ability to specify the filename and the content type by sendDocument

This commit is contained in:
evolun 2016-05-02 17:13:05 +02:00
parent 2498e44ed7
commit 763f717a04

View File

@ -359,10 +359,11 @@ class TelegramBot extends EventEmitter {
* @param {String|stream.Stream|Buffer} doc A file path, Stream or Buffer. * @param {String|stream.Stream|Buffer} doc A file path, Stream or Buffer.
* Can also be a `file_id` previously uploaded. * Can also be a `file_id` previously uploaded.
* @param {Object} [options] Additional Telegram query options * @param {Object} [options] Additional Telegram query options
* @param {Object} [fileOpts] Optional file related meta-data
* @return {Promise} * @return {Promise}
* @see https://core.telegram.org/bots/api#sendDocument * @see https://core.telegram.org/bots/api#sendDocument
*/ */
sendDocument(chatId, doc, options = {}) { sendDocument(chatId, doc, options = {}, fileOpts = {}) {
const opts = { const opts = {
qs: options qs: options
}; };
@ -370,6 +371,9 @@ class TelegramBot extends EventEmitter {
const content = this._formatSendData('document', doc); const content = this._formatSendData('document', doc);
opts.formData = content[0]; opts.formData = content[0];
opts.qs.document = content[1]; opts.qs.document = content[1];
if (opts.formData && Object.keys(fileOpts).length) {
opts.formData['document'].options = fileOpts;
}
return this._request('sendDocument', opts); return this._request('sendDocument', opts);
} }