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

fix: Add Thumb

This commit is contained in:
Daniel
2022-12-30 20:02:34 +01:00
parent dfefcb7fee
commit d844bc0811
2 changed files with 26 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2. Minor changes: 2. Minor changes:
* The parameters `name` and `icon_custom_emoji_id` of the method `editForumTopic` are now optional. * The parameters `name` and `icon_custom_emoji_id` of the method `editForumTopic` are now optional.
* Fix add thumb in sendAudio, sendVideo and sendVideoNote
## [0.60.0][0.60.0] - 2022-10-06 ## [0.60.0][0.60.0] - 2022-10-06
1. Support Telegram Bot API v6.3 (@danielperez9430) 1. Support Telegram Bot API v6.3 (@danielperez9430)

View File

@@ -237,6 +237,26 @@ class TelegramBot extends EventEmitter {
} }
} }
_fixAddFileThumb(options, opts) {
if (options.thumb) {
if (opts.formData === null) {
opts.formData = {};
}
try {
const attachName = 'photo';
const [formData] = this._formatSendData(attachName, options.thumb.replace('attach://', ''));
if (formData) {
opts.formData[attachName] = formData[attachName];
opts.qs.thumb = `attach://${attachName}`;
}
} catch (ex) {
throw Promise.reject(ex);
}
}
}
/** /**
* Make request against the API * Make request against the API
* @param {String} _path API endpoint * @param {String} _path API endpoint
@@ -987,28 +1007,11 @@ class TelegramBot extends EventEmitter {
const sendData = this._formatSendData('audio', audio, fileOptions); const sendData = this._formatSendData('audio', audio, fileOptions);
opts.formData = sendData[0]; opts.formData = sendData[0];
opts.qs.audio = sendData[1]; opts.qs.audio = sendData[1];
this._fixAddFileThumb(options, opts);
} catch (ex) { } catch (ex) {
return Promise.reject(ex); return Promise.reject(ex);
} }
if (options.thumb) {
if (opts.formData === null) {
opts.formData = {};
}
try {
const attachName = 'photo';
const [formData] = this._formatSendData(attachName, options.thumb.replace('attach://', ''));
if (formData) {
opts.formData[attachName] = formData[attachName];
opts.qs.thumb = `attach://${attachName}`;
}
} catch (ex) {
return Promise.reject(ex);
}
}
return this._request('sendAudio', opts); return this._request('sendAudio', opts);
} }
@@ -1032,9 +1035,11 @@ class TelegramBot extends EventEmitter {
const sendData = this._formatSendData('document', doc, fileOptions); const sendData = this._formatSendData('document', doc, fileOptions);
opts.formData = sendData[0]; opts.formData = sendData[0];
opts.qs.document = sendData[1]; opts.qs.document = sendData[1];
this._fixAddFileThumb(options, opts);
} catch (ex) { } catch (ex) {
return Promise.reject(ex); return Promise.reject(ex);
} }
return this._request('sendDocument', opts); return this._request('sendDocument', opts);
} }
@@ -1059,6 +1064,7 @@ class TelegramBot extends EventEmitter {
const sendData = this._formatSendData('video', video, fileOptions); const sendData = this._formatSendData('video', video, fileOptions);
opts.formData = sendData[0]; opts.formData = sendData[0];
opts.qs.video = sendData[1]; opts.qs.video = sendData[1];
this._fixAddFileThumb(options, opts);
} catch (ex) { } catch (ex) {
return Promise.reject(ex); return Promise.reject(ex);
} }
@@ -1141,6 +1147,7 @@ class TelegramBot extends EventEmitter {
const sendData = this._formatSendData('video_note', videoNote, fileOptions); const sendData = this._formatSendData('video_note', videoNote, fileOptions);
opts.formData = sendData[0]; opts.formData = sendData[0];
opts.qs.video_note = sendData[1]; opts.qs.video_note = sendData[1];
this._fixAddFileThumb(options, opts);
} catch (ex) { } catch (ex) {
return Promise.reject(ex); return Promise.reject(ex);
} }