Skip to content

Commit 0eb8b80

Browse files
authored
fix: Parse entities when sending request (yagop#1013)
1 parent ccdd146 commit 0eb8b80

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/telegram.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ class TelegramBot extends EventEmitter {
211211
}
212212
}
213213

214+
/**
215+
* Fix 'entities' or 'caption_entities' or 'explanation_entities' parameter by making it JSON-serialized, as
216+
* required by the Telegram Bot API
217+
* @param {Object} obj Object;
218+
* @private
219+
* @see https://core.telegram.org/bots/api#sendmessage
220+
* @see https://core.telegram.org/bots/api#copymessage
221+
* @see https://core.telegram.org/bots/api#sendpoll
222+
*/
223+
_fixEntitiesField(obj) {
224+
const entities = obj.entities;
225+
const captionEntities = obj.caption_entities;
226+
const explanationEntities = obj.explanation_entities;
227+
if (entities && typeof entities !== 'string') {
228+
obj.entities = stringify(entities);
229+
}
230+
231+
if (captionEntities && typeof captionEntities !== 'string') {
232+
obj.caption_entities = stringify(captionEntities);
233+
}
234+
235+
if (explanationEntities && typeof explanationEntities !== 'string') {
236+
obj.explanation_entities = stringify(explanationEntities);
237+
}
238+
}
239+
214240
/**
215241
* Make request against the API
216242
* @param {String} _path API endpoint
@@ -229,6 +255,7 @@ class TelegramBot extends EventEmitter {
229255

230256
if (options.form) {
231257
this._fixReplyMarkup(options.form);
258+
this._fixEntitiesField(options.form);
232259
}
233260
if (options.qs) {
234261
this._fixReplyMarkup(options.qs);

0 commit comments

Comments
 (0)