@@ -211,6 +211,32 @@ class TelegramBot extends EventEmitter {
211
211
}
212
212
}
213
213
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
+
214
240
/**
215
241
* Make request against the API
216
242
* @param {String } _path API endpoint
@@ -229,6 +255,7 @@ class TelegramBot extends EventEmitter {
229
255
230
256
if ( options . form ) {
231
257
this . _fixReplyMarkup ( options . form ) ;
258
+ this . _fixEntitiesField ( options . form ) ;
232
259
}
233
260
if ( options . qs ) {
234
261
this . _fixReplyMarkup ( options . qs ) ;
0 commit comments