2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-22 18:07:16 +00:00

fix: Parse entities when sending request (#1013)

This commit is contained in:
Antonio Hernández 2022-11-06 00:15:24 +01:00 committed by GitHub
parent ccdd14670b
commit 0eb8b8032f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,6 +211,32 @@ class TelegramBot extends EventEmitter {
} }
} }
/**
* Fix 'entities' or 'caption_entities' or 'explanation_entities' parameter by making it JSON-serialized, as
* required by the Telegram Bot API
* @param {Object} obj Object;
* @private
* @see https://core.telegram.org/bots/api#sendmessage
* @see https://core.telegram.org/bots/api#copymessage
* @see https://core.telegram.org/bots/api#sendpoll
*/
_fixEntitiesField(obj) {
const entities = obj.entities;
const captionEntities = obj.caption_entities;
const explanationEntities = obj.explanation_entities;
if (entities && typeof entities !== 'string') {
obj.entities = stringify(entities);
}
if (captionEntities && typeof captionEntities !== 'string') {
obj.caption_entities = stringify(captionEntities);
}
if (explanationEntities && typeof explanationEntities !== 'string') {
obj.explanation_entities = stringify(explanationEntities);
}
}
/** /**
* Make request against the API * Make request against the API
* @param {String} _path API endpoint * @param {String} _path API endpoint
@ -229,6 +255,7 @@ class TelegramBot extends EventEmitter {
if (options.form) { if (options.form) {
this._fixReplyMarkup(options.form); this._fixReplyMarkup(options.form);
this._fixEntitiesField(options.form);
} }
if (options.qs) { if (options.qs) {
this._fixReplyMarkup(options.qs); this._fixReplyMarkup(options.qs);