@zero-bot.net/tg-bot-api 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/telegram.js CHANGED
@@ -23,7 +23,31 @@ const fs = require('fs');
23
23
  const pump = require('pump');
24
24
  const deprecate = require('./utils').deprecate;
25
25
 
26
- const _messageTypes = ['text', 'animation', 'audio', 'channel_chat_created', 'contact', 'delete_chat_photo', 'dice', 'document', 'game', 'group_chat_created', 'invoice', 'left_chat_member', 'location', 'migrate_from_chat_id', 'migrate_to_chat_id', 'new_chat_members', 'new_chat_photo', 'new_chat_title', 'passport_data', 'photo', 'pinned_message', 'poll', 'sticker', 'successful_payment', 'supergroup_chat_created', 'video', 'video_note', 'voice', 'video_chat_started', 'video_chat_ended', 'video_chat_participants_invited', 'video_chat_scheduled', 'message_auto_delete_timer_changed', 'chat_invite_link', 'chat_member_updated', 'web_app_data', 'message_reaction'];
26
+ const _messageTypes = ['text', 'animation', 'audio', 'channel_chat_created', 'contact', 'delete_chat_photo', 'dice', 'document', 'game', 'group_chat_created', 'invoice', 'left_chat_member', 'location', 'migrate_from_chat_id', 'migrate_to_chat_id', 'new_chat_members', 'new_chat_photo', 'new_chat_title', 'passport_data', 'photo', 'pinned_message', 'poll', 'sticker', 'successful_payment', 'supergroup_chat_created', 'video', 'video_note', 'voice', 'video_chat_started', 'video_chat_ended', 'video_chat_participants_invited', 'video_chat_scheduled', 'message_auto_delete_timer_changed', 'chat_invite_link', 'chat_member_updated', 'web_app_data', 'message_reaction',
27
+ // Bot API 7.7
28
+ 'refunded_payment',
29
+ // Bot API 9.0
30
+ 'gift', 'unique_gift', 'paid_message_price_changed', 'paid_star_count',
31
+ // Bot API 9.1
32
+ 'checklist', 'checklist_tasks_done', 'checklist_tasks_added', 'direct_message_price_changed',
33
+ // Bot API 9.2
34
+ 'direct_messages_topic', 'suggested_post_info', 'suggested_post_approved', 'suggested_post_approval_failed', 'suggested_post_declined', 'suggested_post_paid', 'suggested_post_refunded',
35
+ // Bot API 9.3
36
+ 'gift_upgrade_sent',
37
+ // Bot API 9.4
38
+ 'chat_owner_left', 'chat_owner_changed',
39
+ // Bot API 9.5
40
+ 'sender_tag',
41
+ // Bot API 9.6
42
+ 'managed_bot_created', 'poll_option_added', 'poll_option_deleted',
43
+ // Bot API 10.0
44
+ 'guest_bot_caller_user', 'guest_bot_caller_chat', 'guest_query_id', 'live_photo',
45
+ // Bot API 10.1
46
+ 'rich_message',
47
+ // Bot API 10.2
48
+ 'ephemeral_message_id', 'receiver_user', 'community_chat_added', 'community_chat_removed',
49
+ // Bot API 10.3
50
+ 'stopped_message_generation', 'community_chat_joined'];
27
51
 
28
52
  const _deprecatedMessageTypes = ['new_chat_participant', 'left_chat_participant'];
29
53
 
@@ -232,6 +256,21 @@ class TelegramBot extends EventEmitter {
232
256
  }
233
257
  }
234
258
 
259
+ /**
260
+ * Fix JSON-serialized object fields by making them JSON strings if they are still objects.
261
+ * Covers new Bot API 7.4-10.3 fields that accept JSON-serialized objects.
262
+ * @param {Object} obj Object; either 'form' or 'qs'
263
+ * @private
264
+ */
265
+ _fixJsonFields(obj) {
266
+ const jsonFields = ['rich_message', 'content', 'result', 'button', 'web_app', 'photo', 'tasks', 'reaction_type', 'restricted_channels', 'target_business_connection_ids', 'accepted_gift_types', 'link_preview_options'];
267
+ for (const field of jsonFields) {
268
+ if (obj.hasOwnProperty(field) && typeof obj[field] !== 'string') {
269
+ obj[field] = stringify(obj[field]);
270
+ }
271
+ }
272
+ }
273
+
235
274
  /**
236
275
  * Make request against the API
237
276
  * @param {String} _path API endpoint
@@ -252,10 +291,12 @@ class TelegramBot extends EventEmitter {
252
291
  this._fixReplyMarkup(options.form);
253
292
  this._fixEntitiesField(options.form);
254
293
  this._fixReplyParameters(options.form);
294
+ this._fixJsonFields(options.form);
255
295
  }
256
296
  if (options.qs) {
257
297
  this._fixReplyMarkup(options.qs);
258
298
  this._fixReplyParameters(options.qs);
299
+ this._fixJsonFields(options.qs);
259
300
  }
260
301
 
261
302
  options.method = 'POST';
@@ -3052,6 +3093,1050 @@ class TelegramBot extends EventEmitter {
3052
3093
  return this._request('deleteMessages', { form });
3053
3094
  }
3054
3095
 
3096
+ // ==========================================
3097
+ // Bot API 7.4
3098
+ // ==========================================
3099
+
3100
+ /**
3101
+ * Use this method to issue a refund for a payment made via Telegram Stars.
3102
+ *
3103
+ * @param {Number} userId Identifier of the user whose payment will be refunded
3104
+ * @param {String} telegramPaymentChargeId Telegram payment identifier of the payment to refund
3105
+ * @param {Object} [options] Additional Telegram query options
3106
+ * @return {Promise} On success, True is returned
3107
+ * @see https://core.telegram.org/bots/api#refundstarpayment
3108
+ */
3109
+ refundStarPayment(userId, telegramPaymentChargeId, form = {}) {
3110
+ form.user_id = userId;
3111
+ form.telegram_payment_charge_id = telegramPaymentChargeId;
3112
+ return this._request('refundStarPayment', { form });
3113
+ }
3114
+
3115
+ // ==========================================
3116
+ // Bot API 7.5
3117
+ // ==========================================
3118
+
3119
+ /**
3120
+ * Use this method to get the current status of the balance of Telegram Stars
3121
+ * that can be withdrawn by the bot or transferred to another business account.
3122
+ *
3123
+ * @param {Object} [options] Additional Telegram query options
3124
+ * @return {Promise} On success, returns a StarTransactions object
3125
+ * @see https://core.telegram.org/bots/api#getstartransactions
3126
+ */
3127
+ getStarTransactions(form = {}) {
3128
+ return this._request('getStarTransactions', { form });
3129
+ }
3130
+
3131
+ // ==========================================
3132
+ // Bot API 7.6
3133
+ // ==========================================
3134
+
3135
+ /**
3136
+ * Use this method to send paid media.
3137
+ *
3138
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3139
+ * @param {Number} starCount The number of Telegram Stars that must be paid to buy access to the media
3140
+ * @param {Array} media A JSON-serialized array describing the media to be sent; currently supports photos and videos
3141
+ * @param {Object} [options] Additional Telegram query options
3142
+ * @return {Promise} On success, the sent Message object is returned
3143
+ * @see https://core.telegram.org/bots/api#sendpaidmedia
3144
+ */
3145
+ sendPaidMedia(chatId, starCount, media, form = {}) {
3146
+ form.chat_id = chatId;
3147
+ form.star_count = starCount;
3148
+ form.media = stringify(media);
3149
+ return this._request('sendPaidMedia', { form });
3150
+ }
3151
+
3152
+ // ==========================================
3153
+ // Bot API 7.9
3154
+ // ==========================================
3155
+
3156
+ /**
3157
+ * Use this method to create a subscription invite link for a channel chat.
3158
+ *
3159
+ * @param {Number|String} chatId Unique identifier for the target channel chat or username of the target channel (in the format `@channelusername`)
3160
+ * @param {Object} [options] Additional Telegram query options
3161
+ * @return {Promise} On success, the new invite link as a ChatInviteLink object is returned
3162
+ * @see https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
3163
+ */
3164
+ createChatSubscriptionInviteLink(chatId, form = {}) {
3165
+ form.chat_id = chatId;
3166
+ return this._request('createChatSubscriptionInviteLink', { form });
3167
+ }
3168
+
3169
+ /**
3170
+ * Use this method to edit a subscription invite link created by the bot.
3171
+ *
3172
+ * @param {Number|String} chatId Unique identifier for the target channel chat or username of the target channel (in the format `@channelusername`)
3173
+ * @param {String} inviteLink The invite link to edit
3174
+ * @param {Object} [options] Additional Telegram query options
3175
+ * @return {Promise} On success, the edited invite link as a ChatInviteLink object is returned
3176
+ * @see https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
3177
+ */
3178
+ editChatSubscriptionInviteLink(chatId, inviteLink, form = {}) {
3179
+ form.chat_id = chatId;
3180
+ form.invite_link = inviteLink;
3181
+ return this._request('editChatSubscriptionInviteLink', { form });
3182
+ }
3183
+
3184
+ // ==========================================
3185
+ // Bot API 8.0
3186
+ // ==========================================
3187
+
3188
+ /**
3189
+ * Use this method to get the list of gifts that can be sent by the bot.
3190
+ *
3191
+ * @param {Object} [options] Additional Telegram query options
3192
+ * @return {Promise} On success, returns a Gifts object
3193
+ * @see https://core.telegram.org/bots/api#getavailablegifts
3194
+ */
3195
+ getAvailableGifts(form = {}) {
3196
+ return this._request('getAvailableGifts', { form });
3197
+ }
3198
+
3199
+ /**
3200
+ * Use this method to send a gift to a user.
3201
+ *
3202
+ * @param {Number} userId Unique identifier of the target user that will receive the gift
3203
+ * @param {String} giftId Identifier of the gift
3204
+ * @param {Object} [options] Additional Telegram query options
3205
+ * @return {Promise} On success, True is returned
3206
+ * @see https://core.telegram.org/bots/api#sendgift
3207
+ */
3208
+ sendGift(userId, giftId, form = {}) {
3209
+ form.user_id = userId;
3210
+ form.gift_id = giftId;
3211
+ return this._request('sendGift', { form });
3212
+ }
3213
+
3214
+ /**
3215
+ * Use this method to edit a subscription paid through Telegram Stars.
3216
+ *
3217
+ * @param {Number} userId Identifier of the user whose subscription will be edited
3218
+ * @param {String} telegramPaymentChargeId Telegram payment identifier of the subscription payment
3219
+ * @param {Boolean} isCanceled Pass True to cancel the user's subscription
3220
+ * @param {Object} [options] Additional Telegram query options
3221
+ * @return {Promise} On success, True is returned
3222
+ * @see https://core.telegram.org/bots/api#edituserstarsubscription
3223
+ */
3224
+ editUserStarSubscription(userId, telegramPaymentChargeId, isCanceled, form = {}) {
3225
+ form.user_id = userId;
3226
+ form.telegram_payment_charge_id = telegramPaymentChargeId;
3227
+ form.is_canceled = isCanceled;
3228
+ return this._request('editUserStarSubscription', { form });
3229
+ }
3230
+
3231
+ /**
3232
+ * Use this method to store an inline message that can be sent on behalf of a user.
3233
+ *
3234
+ * @param {Number} userId Unique identifier of the target user
3235
+ * @param {Object} result An object describing the message to be sent
3236
+ * @param {Object} [options] Additional Telegram query options
3237
+ * @return {Promise} On success, returns a PreparedInlineMessage object
3238
+ * @see https://core.telegram.org/bots/api#savepreparedinlinemessage
3239
+ */
3240
+ savePreparedInlineMessage(userId, result, form = {}) {
3241
+ form.user_id = userId;
3242
+ form.result = stringify(result);
3243
+ return this._request('savePreparedInlineMessage', { form });
3244
+ }
3245
+
3246
+ // ==========================================
3247
+ // Bot API 8.2
3248
+ // ==========================================
3249
+
3250
+ /**
3251
+ * Use this method to verify a user that is managed by the bot.
3252
+ *
3253
+ * @param {Number} userId Unique identifier of the target user
3254
+ * @param {Object} [options] Additional Telegram query options
3255
+ * @return {Promise} On success, True is returned
3256
+ * @see https://core.telegram.org/bots/api#verifyuser
3257
+ */
3258
+ verifyUser(userId, form = {}) {
3259
+ form.user_id = userId;
3260
+ return this._request('verifyUser', { form });
3261
+ }
3262
+
3263
+ /**
3264
+ * Use this method to verify a chat that is managed by the bot.
3265
+ *
3266
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3267
+ * @param {Object} [options] Additional Telegram query options
3268
+ * @return {Promise} On success, True is returned
3269
+ * @see https://core.telegram.org/bots/api#verifychat
3270
+ */
3271
+ verifyChat(chatId, form = {}) {
3272
+ form.chat_id = chatId;
3273
+ return this._request('verifyChat', { form });
3274
+ }
3275
+
3276
+ /**
3277
+ * Use this method to remove verification for a user that is managed by the bot.
3278
+ *
3279
+ * @param {Number} userId Unique identifier of the target user
3280
+ * @param {Object} [options] Additional Telegram query options
3281
+ * @return {Promise} On success, True is returned
3282
+ * @see https://core.telegram.org/bots/api#removeuserverification
3283
+ */
3284
+ removeUserVerification(userId, form = {}) {
3285
+ form.user_id = userId;
3286
+ return this._request('removeUserVerification', { form });
3287
+ }
3288
+
3289
+ /**
3290
+ * Use this method to remove verification for a chat that is managed by the bot.
3291
+ *
3292
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3293
+ * @param {Object} [options] Additional Telegram query options
3294
+ * @return {Promise} On success, True is returned
3295
+ * @see https://core.telegram.org/bots/api#removechatverification
3296
+ */
3297
+ removeChatVerification(chatId, form = {}) {
3298
+ form.chat_id = chatId;
3299
+ return this._request('removeChatVerification', { form });
3300
+ }
3301
+
3302
+ // ==========================================
3303
+ // Bot API 9.0: Business Accounts + Gifts
3304
+ // ==========================================
3305
+
3306
+ /**
3307
+ * Use this method to mark incoming messages as read on behalf of a business account.
3308
+ *
3309
+ * @param {String} businessConnectionId Unique identifier of the business connection
3310
+ * @param {Number} messageId Unique identifier of the message to mark as read
3311
+ * @param {Object} [options] Additional Telegram query options
3312
+ * @return {Promise} True on success
3313
+ * @see https://core.telegram.org/bots/api#readbusinessmessage
3314
+ */
3315
+ readBusinessMessage(businessConnectionId, messageId, form = {}) {
3316
+ form.business_connection_id = businessConnectionId;
3317
+ form.message_id = messageId;
3318
+ return this._request('readBusinessMessage', { form });
3319
+ }
3320
+
3321
+ /**
3322
+ * Use this method to delete messages on behalf of a business account.
3323
+ *
3324
+ * @param {String} businessConnectionId Unique identifier of the business connection
3325
+ * @param {Array<Number>} messageIds Unique identifiers of 1-100 messages to delete
3326
+ * @param {Object} [options] Additional Telegram query options
3327
+ * @return {Promise} True on success
3328
+ * @see https://core.telegram.org/bots/api#deletebusinessmessages
3329
+ */
3330
+ deleteBusinessMessages(businessConnectionId, messageIds, form = {}) {
3331
+ form.business_connection_id = businessConnectionId;
3332
+ form.message_ids = stringify(messageIds);
3333
+ return this._request('deleteBusinessMessages', { form });
3334
+ }
3335
+
3336
+ /**
3337
+ * Use this method to change the first and last name of a managed business account.
3338
+ *
3339
+ * @param {String} businessConnectionId Unique identifier of the business connection
3340
+ * @param {Object} [options] Additional Telegram query options
3341
+ * @return {Promise} True on success
3342
+ * @see https://core.telegram.org/bots/api#setbusinessaccountname
3343
+ */
3344
+ setBusinessAccountName(businessConnectionId, form = {}) {
3345
+ form.business_connection_id = businessConnectionId;
3346
+ return this._request('setBusinessAccountName', { form });
3347
+ }
3348
+
3349
+ /**
3350
+ * Use this method to change the username of a managed business account.
3351
+ *
3352
+ * @param {String} businessConnectionId Unique identifier of the business connection
3353
+ * @param {Object} [options] Additional Telegram query options
3354
+ * @return {Promise} True on success
3355
+ * @see https://core.telegram.org/bots/api#setbusinessaccountusername
3356
+ */
3357
+ setBusinessAccountUsername(businessConnectionId, form = {}) {
3358
+ form.business_connection_id = businessConnectionId;
3359
+ return this._request('setBusinessAccountUsername', { form });
3360
+ }
3361
+
3362
+ /**
3363
+ * Use this method to change the bio of a managed business account.
3364
+ *
3365
+ * @param {String} businessConnectionId Unique identifier of the business connection
3366
+ * @param {Object} [options] Additional Telegram query options
3367
+ * @return {Promise} True on success
3368
+ * @see https://core.telegram.org/bots/api#setbusinessaccountbio
3369
+ */
3370
+ setBusinessAccountBio(businessConnectionId, form = {}) {
3371
+ form.business_connection_id = businessConnectionId;
3372
+ return this._request('setBusinessAccountBio', { form });
3373
+ }
3374
+
3375
+ /**
3376
+ * Use this method to change the profile photo of a managed business account.
3377
+ *
3378
+ * @param {String} businessConnectionId Unique identifier of the business connection
3379
+ * @param {Object} photo InputProfilePhoto object
3380
+ * @param {Object} [options] Additional Telegram query options
3381
+ * @return {Promise} True on success
3382
+ * @see https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
3383
+ */
3384
+ setBusinessAccountProfilePhoto(businessConnectionId, photo, form = {}) {
3385
+ form.business_connection_id = businessConnectionId;
3386
+ form.photo = stringify(photo);
3387
+ return this._request('setBusinessAccountProfilePhoto', { form });
3388
+ }
3389
+
3390
+ /**
3391
+ * Use this method to remove the profile photo of a managed business account.
3392
+ *
3393
+ * @param {String} businessConnectionId Unique identifier of the business connection
3394
+ * @param {Object} [options] Additional Telegram query options
3395
+ * @return {Promise} True on success
3396
+ * @see https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
3397
+ */
3398
+ removeBusinessAccountProfilePhoto(businessConnectionId, form = {}) {
3399
+ form.business_connection_id = businessConnectionId;
3400
+ return this._request('removeBusinessAccountProfilePhoto', { form });
3401
+ }
3402
+
3403
+ /**
3404
+ * Use this method to change the gift settings of a managed business account.
3405
+ *
3406
+ * @param {String} businessConnectionId Unique identifier of the business connection
3407
+ * @param {Object} [options] Additional Telegram query options
3408
+ * @return {Promise} True on success
3409
+ * @see https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
3410
+ */
3411
+ setBusinessAccountGiftSettings(businessConnectionId, form = {}) {
3412
+ form.business_connection_id = businessConnectionId;
3413
+ if (form.accepted_gift_types) {
3414
+ form.accepted_gift_types = stringify(form.accepted_gift_types);
3415
+ }
3416
+ return this._request('setBusinessAccountGiftSettings', { form });
3417
+ }
3418
+
3419
+ /**
3420
+ * Use this method to get the current Star balance of a managed business account.
3421
+ *
3422
+ * @param {String} businessConnectionId Unique identifier of the business connection
3423
+ * @param {Object} [options] Additional Telegram query options
3424
+ * @return {Promise} Returns a StarAmount object
3425
+ * @see https://core.telegram.org/bots/api#getbusinessaccountstarbalance
3426
+ */
3427
+ getBusinessAccountStarBalance(businessConnectionId, form = {}) {
3428
+ form.business_connection_id = businessConnectionId;
3429
+ return this._request('getBusinessAccountStarBalance', { form });
3430
+ }
3431
+
3432
+ /**
3433
+ * Use this method to transfer Stars from the business account balance to the bot owner's balance.
3434
+ *
3435
+ * @param {String} businessConnectionId Unique identifier of the business connection
3436
+ * @param {Number} starCount Number of Telegram Stars to transfer, 1-10000
3437
+ * @param {Object} [options] Additional Telegram query options
3438
+ * @return {Promise} Returns a StarAmount object
3439
+ * @see https://core.telegram.org/bots/api#transferbusinessaccountstars
3440
+ */
3441
+ transferBusinessAccountStars(businessConnectionId, starCount, form = {}) {
3442
+ form.business_connection_id = businessConnectionId;
3443
+ form.star_count = starCount;
3444
+ return this._request('transferBusinessAccountStars', { form });
3445
+ }
3446
+
3447
+ /**
3448
+ * Use this method to get the list of gifts received by a managed business account.
3449
+ *
3450
+ * @param {String} businessConnectionId Unique identifier of the business connection
3451
+ * @param {Object} [options] Additional Telegram query options
3452
+ * @return {Promise} Returns an Array of OwnedGift objects
3453
+ * @see https://core.telegram.org/bots/api#getbusinessaccountgifts
3454
+ */
3455
+ getBusinessAccountGifts(businessConnectionId, form = {}) {
3456
+ form.business_connection_id = businessConnectionId;
3457
+ return this._request('getBusinessAccountGifts', { form });
3458
+ }
3459
+
3460
+ /**
3461
+ * Use this method to convert a given regular gift to Telegram Stars.
3462
+ *
3463
+ * @param {String} businessConnectionId Unique identifier of the business connection
3464
+ * @param {String} ownedGiftId Identifier of the regular gift
3465
+ * @param {Object} [options] Additional Telegram query options
3466
+ * @return {Promise} Returns a StarAmount object
3467
+ * @see https://core.telegram.org/bots/api#convertgifttostars
3468
+ */
3469
+ convertGiftToStars(businessConnectionId, ownedGiftId, form = {}) {
3470
+ form.business_connection_id = businessConnectionId;
3471
+ form.owned_gift_id = ownedGiftId;
3472
+ return this._request('convertGiftToStars', { form });
3473
+ }
3474
+
3475
+ /**
3476
+ * Use this method to upgrade a regular gift to a unique or upgrade a unique gift to an upgraded collectible gift.
3477
+ *
3478
+ * @param {String} businessConnectionId Unique identifier of the business connection
3479
+ * @param {String} ownedGiftId Identifier of the regular gift to upgrade
3480
+ * @param {Object} [options] Additional Telegram query options
3481
+ * @return {Promise} Returns the updated OwnedGift object
3482
+ * @see https://core.telegram.org/bots/api#upgradegift
3483
+ */
3484
+ upgradeGift(businessConnectionId, ownedGiftId, form = {}) {
3485
+ form.business_connection_id = businessConnectionId;
3486
+ form.owned_gift_id = ownedGiftId;
3487
+ return this._request('upgradeGift', { form });
3488
+ }
3489
+
3490
+ /**
3491
+ * Use this method to transfer a regular gift to another user.
3492
+ *
3493
+ * @param {String} businessConnectionId Unique identifier of the business connection
3494
+ * @param {String} ownedGiftId Identifier of the gift to transfer
3495
+ * @param {Number|String} newOwnerChatId Unique identifier of the new owner of the gift
3496
+ * @param {Object} [options] Additional Telegram query options
3497
+ * @return {Promise} True on success
3498
+ * @see https://core.telegram.org/bots/api#transfergift
3499
+ */
3500
+ transferGift(businessConnectionId, ownedGiftId, newOwnerChatId, form = {}) {
3501
+ form.business_connection_id = businessConnectionId;
3502
+ form.owned_gift_id = ownedGiftId;
3503
+ form.new_owner_chat_id = newOwnerChatId;
3504
+ return this._request('transferGift', { form });
3505
+ }
3506
+
3507
+ /**
3508
+ * Use this method to post a story on behalf of a managed business account.
3509
+ *
3510
+ * @param {String} businessConnectionId Unique identifier of the business connection
3511
+ * @param {Object} content InputStoryContent object
3512
+ * @param {Object} [options] Additional Telegram query options
3513
+ * @return {Promise} Returns a Story object
3514
+ * @see https://core.telegram.org/bots/api#poststory
3515
+ */
3516
+ postStory(businessConnectionId, content, form = {}) {
3517
+ form.business_connection_id = businessConnectionId;
3518
+ form.content = stringify(content);
3519
+ return this._request('postStory', { form });
3520
+ }
3521
+
3522
+ /**
3523
+ * Use this method to edit a story previously posted on behalf of a managed business account.
3524
+ *
3525
+ * @param {String} businessConnectionId Unique identifier of the business connection
3526
+ * @param {Number} storyId Identifier of the story to edit
3527
+ * @param {Object} [options] Additional Telegram query options
3528
+ * @return {Promise} Returns the edited Story object
3529
+ * @see https://core.telegram.org/bots/api#editstory
3530
+ */
3531
+ editStory(businessConnectionId, storyId, form = {}) {
3532
+ form.business_connection_id = businessConnectionId;
3533
+ form.story_id = storyId;
3534
+ if (form.content) {
3535
+ form.content = stringify(form.content);
3536
+ }
3537
+ return this._request('editStory', { form });
3538
+ }
3539
+
3540
+ /**
3541
+ * Use this method to delete a story previously posted on behalf of a managed business account.
3542
+ *
3543
+ * @param {String} businessConnectionId Unique identifier of the business connection
3544
+ * @param {Number} storyId Identifier of the story to delete
3545
+ * @param {Object} [options] Additional Telegram query options
3546
+ * @return {Promise} True on success
3547
+ * @see https://core.telegram.org/bots/api#deletestory
3548
+ */
3549
+ deleteStory(businessConnectionId, storyId, form = {}) {
3550
+ form.business_connection_id = businessConnectionId;
3551
+ form.story_id = storyId;
3552
+ return this._request('deleteStory', { form });
3553
+ }
3554
+
3555
+ /**
3556
+ * Use this method to gift a Telegram Premium subscription to a user.
3557
+ *
3558
+ * @param {Number|String} userId Unique identifier of the target user
3559
+ * @param {Number} monthCount Number of months the subscription will be active for, 1-36
3560
+ * @param {Number} starCount Number of Telegram Stars that will be paid for the subscription, 1-10000
3561
+ * @param {Object} [options] Additional Telegram query options
3562
+ * @return {Promise} Returns the Gift object that was paid for
3563
+ * @see https://core.telegram.org/bots/api#giftpremiumsubscription
3564
+ */
3565
+ giftPremiumSubscription(userId, monthCount, starCount, form = {}) {
3566
+ form.user_id = userId;
3567
+ form.month_count = monthCount;
3568
+ form.star_count = starCount;
3569
+ return this._request('giftPremiumSubscription', { form });
3570
+ }
3571
+
3572
+ /**
3573
+ * Use this method to set the emoji status of a user.
3574
+ *
3575
+ * @param {Number|String} userId Unique identifier of the target user
3576
+ * @param {Object} [options] Additional Telegram query options
3577
+ * @return {Promise} True on success
3578
+ * @see https://core.telegram.org/bots/api#setuseremojistatus
3579
+ */
3580
+ setUserEmojiStatus(userId, form = {}) {
3581
+ form.user_id = userId;
3582
+ return this._request('setUserEmojiStatus', { form });
3583
+ }
3584
+
3585
+ // ==========================================
3586
+ // Bot API 9.1: Checklists
3587
+ // ==========================================
3588
+
3589
+ /**
3590
+ * Use this method to send a checklist on behalf of a managed business account.
3591
+ *
3592
+ * @param {String} businessConnectionId Unique identifier of the business connection
3593
+ * @param {String} title Title of the checklist, 1-255 characters after entities parsing
3594
+ * @param {Array} tasks List of 1-100 tasks in the checklist
3595
+ * @param {Object} [options] Additional Telegram query options
3596
+ * @return {Promise} On success, the sent Message is returned
3597
+ * @see https://core.telegram.org/bots/api#sendchecklist
3598
+ */
3599
+ sendChecklist(businessConnectionId, title, tasks, form = {}) {
3600
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3601
+ if (!title) return Promise.reject(new Error('title is required'));
3602
+ form.business_connection_id = businessConnectionId;
3603
+ form.title = title;
3604
+ form.tasks = stringify(tasks);
3605
+ return this._request('sendChecklist', { form });
3606
+ }
3607
+
3608
+ /**
3609
+ * Use this method to edit a checklist message on behalf of a managed business account.
3610
+ *
3611
+ * @param {String} businessConnectionId Unique identifier of the business connection
3612
+ * @param {Number} messageId Unique identifier of the message to edit
3613
+ * @param {Object} [options] Additional Telegram query options
3614
+ * @return {Promise} On success, the edited Message is returned
3615
+ * @see https://core.telegram.org/bots/api#editmessagechecklist
3616
+ */
3617
+ editMessageChecklist(businessConnectionId, messageId, form = {}) {
3618
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3619
+ if (!messageId) return Promise.reject(new Error('messageId is required'));
3620
+ form.business_connection_id = businessConnectionId;
3621
+ form.message_id = messageId;
3622
+ if (form.tasks) {
3623
+ form.tasks = stringify(form.tasks);
3624
+ }
3625
+ return this._request('editMessageChecklist', { form });
3626
+ }
3627
+
3628
+ /**
3629
+ * Use this method to get the current number of Telegram Stars owned by the bot.
3630
+ *
3631
+ * @param {Object} [options] Additional Telegram query options
3632
+ * @return {Promise} Returns a StarAmount object
3633
+ * @see https://core.telegram.org/bots/api#getmystarbalance
3634
+ */
3635
+ getMyStarBalance(form = {}) {
3636
+ return this._request('getMyStarBalance', { form });
3637
+ }
3638
+
3639
+ // ==========================================
3640
+ // Bot API 9.2: Suggested Posts
3641
+ // ==========================================
3642
+
3643
+ /**
3644
+ * Use this method to approve a suggested post in a channel chat.
3645
+ *
3646
+ * @param {String} businessConnectionId Unique identifier of the business connection
3647
+ * @param {Number} messageId Unique identifier of the suggested post message
3648
+ * @param {Object} [options] Additional Telegram query options
3649
+ * @return {Promise} True on success
3650
+ * @see https://core.telegram.org/bots/api#approvesuggestedpost
3651
+ */
3652
+ approveSuggestedPost(businessConnectionId, messageId, form = {}) {
3653
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3654
+ if (!messageId) return Promise.reject(new Error('messageId is required'));
3655
+ form.business_connection_id = businessConnectionId;
3656
+ form.message_id = messageId;
3657
+ return this._request('approveSuggestedPost', { form });
3658
+ }
3659
+
3660
+ /**
3661
+ * Use this method to decline a suggested post in a channel chat.
3662
+ *
3663
+ * @param {String} businessConnectionId Unique identifier of the business connection
3664
+ * @param {Number} messageId Unique identifier of the suggested post message
3665
+ * @param {Object} [options] Additional Telegram query options
3666
+ * @return {Promise} True on success
3667
+ * @see https://core.telegram.org/bots/api#declinesuggestedpost
3668
+ */
3669
+ declineSuggestedPost(businessConnectionId, messageId, form = {}) {
3670
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3671
+ if (!messageId) return Promise.reject(new Error('messageId is required'));
3672
+ form.business_connection_id = businessConnectionId;
3673
+ form.message_id = messageId;
3674
+ return this._request('declineSuggestedPost', { form });
3675
+ }
3676
+
3677
+ // ==========================================
3678
+ // Bot API 9.3: Draft Messages, Gifts, Stories
3679
+ // ==========================================
3680
+
3681
+ /**
3682
+ * Use this method to send a draft message to the bot's user in private chat.
3683
+ *
3684
+ * @param {Number|String} chatId Unique identifier of the target private chat
3685
+ * @param {String} text Text of the message, 1-4096 characters after entities parsing
3686
+ * @param {Object} [options] Additional Telegram query options
3687
+ * @return {Promise} On success, the sent Message is returned
3688
+ * @see https://core.telegram.org/bots/api#sendmessagedraft
3689
+ */
3690
+ sendMessageDraft(chatId, text, form = {}) {
3691
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
3692
+ if (!text) return Promise.reject(new Error('text is required'));
3693
+ form.chat_id = chatId;
3694
+ form.text = text;
3695
+ if (form.entities) {
3696
+ form.entities = stringify(form.entities);
3697
+ }
3698
+ if (form.link_preview_options) {
3699
+ form.link_preview_options = stringify(form.link_preview_options);
3700
+ }
3701
+ return this._request('sendMessageDraft', { form });
3702
+ }
3703
+
3704
+ /**
3705
+ * Use this method to get gifts received by a user in a private chat.
3706
+ *
3707
+ * @param {Number|String} userId Unique identifier of the target user
3708
+ * @param {Object} [options] Additional Telegram query options
3709
+ * @return {Promise} Array of OwnedGift objects
3710
+ * @see https://core.telegram.org/bots/api#getusergifts
3711
+ */
3712
+ getUserGifts(userId, form = {}) {
3713
+ form.user_id = userId;
3714
+ return this._request('getUserGifts', { form });
3715
+ }
3716
+
3717
+ /**
3718
+ * Use this method to get gifts received by a chat.
3719
+ *
3720
+ * @param {Number|String} chatId Unique identifier of the target chat
3721
+ * @param {Object} [options] Additional Telegram query options
3722
+ * @return {Promise} Array of OwnedGift objects
3723
+ * @see https://core.telegram.org/bots/api#getchatgifts
3724
+ */
3725
+ getChatGifts(chatId, form = {}) {
3726
+ form.chat_id = chatId;
3727
+ return this._request('getChatGifts', { form });
3728
+ }
3729
+
3730
+ /**
3731
+ * Use this method to repost a story on behalf of a managed business account.
3732
+ *
3733
+ * @param {String} businessConnectionId Unique identifier of the business connection
3734
+ * @param {Number} storyId Identifier of the story to repost
3735
+ * @param {Array<Number|String>} targetBusinessConnectionIds Identifiers of the business connections to post the story to
3736
+ * @param {Object} [options] Additional Telegram query options
3737
+ * @return {Promise} Array of Story objects
3738
+ * @see https://core.telegram.org/bots/api#repoststory
3739
+ */
3740
+ repostStory(businessConnectionId, storyId, targetBusinessConnectionIds, form = {}) {
3741
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3742
+ if (!storyId) return Promise.reject(new Error('storyId is required'));
3743
+ form.business_connection_id = businessConnectionId;
3744
+ form.story_id = storyId;
3745
+ form.target_business_connection_ids = stringify(targetBusinessConnectionIds);
3746
+ return this._request('repostStory', { form });
3747
+ }
3748
+
3749
+ // ==========================================
3750
+ // Bot API 9.4: Profile Photos, Audio Stories
3751
+ // ==========================================
3752
+
3753
+ /**
3754
+ * Use this method to set the profile photo of the bot.
3755
+ *
3756
+ * @param {Object} photo InputProfilePhoto object
3757
+ * @param {Object} [options] Additional Telegram query options
3758
+ * @return {Promise} True on success
3759
+ * @see https://core.telegram.org/bots/api#setmyprofilephoto
3760
+ */
3761
+ setMyProfilePhoto(photo, form = {}) {
3762
+ form.photo = stringify(photo);
3763
+ return this._request('setMyProfilePhoto', { form });
3764
+ }
3765
+
3766
+ /**
3767
+ * Use this method to remove the profile photo of the bot.
3768
+ *
3769
+ * @param {Object} [options] Additional Telegram query options
3770
+ * @return {Promise} True on success
3771
+ * @see https://core.telegram.org/bots/api#removemyprofilephoto
3772
+ */
3773
+ removeMyProfilePhoto(form = {}) {
3774
+ return this._request('removeMyProfilePhoto', { form });
3775
+ }
3776
+
3777
+ /**
3778
+ * Use this method to get the profile audios of a user.
3779
+ *
3780
+ * @param {Number|String} userId Unique identifier of the target user
3781
+ * @param {Object} [options] Additional Telegram query options
3782
+ * @return {Promise} Array of Audio objects
3783
+ * @see https://core.telegram.org/bots/api#getuserprofileaudios
3784
+ */
3785
+ getUserProfileAudios(userId, form = {}) {
3786
+ form.user_id = userId;
3787
+ return this._request('getUserProfileAudios', { form });
3788
+ }
3789
+
3790
+ // ==========================================
3791
+ // Bot API 9.5: Chat Member Tags
3792
+ // ==========================================
3793
+
3794
+ /**
3795
+ * Use this method to set the tag that is applied to a specific user in a specific group chat.
3796
+ *
3797
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target group
3798
+ * @param {Number|String} userId Unique identifier of the target user
3799
+ * @param {Object} [options] Additional Telegram query options
3800
+ * @return {Promise} True on success
3801
+ * @see https://core.telegram.org/bots/api#setchatmembertag
3802
+ */
3803
+ setChatMemberTag(chatId, userId, form = {}) {
3804
+ form.chat_id = chatId;
3805
+ form.user_id = userId;
3806
+ return this._request('setChatMemberTag', { form });
3807
+ }
3808
+
3809
+ // ==========================================
3810
+ // Bot API 9.6: Managed Bot Tokens
3811
+ // ==========================================
3812
+
3813
+ /**
3814
+ * Use this method to get the current managable bot token for the bot.
3815
+ *
3816
+ * @param {Number} botId Identifier of the bot to get the token for
3817
+ * @param {Object} [options] Additional Telegram query options
3818
+ * @return {Promise} Returns a ManagedBotToken object
3819
+ * @see https://core.telegram.org/bots/api#getmanagedbottoken
3820
+ */
3821
+ getManagedBotToken(botId, form = {}) {
3822
+ form.bot_id = botId;
3823
+ return this._request('getManagedBotToken', { form });
3824
+ }
3825
+
3826
+ /**
3827
+ * Use this method to replace the managable bot token for the bot with a new one.
3828
+ *
3829
+ * @param {Number} botId Identifier of the bot whose token will be replaced
3830
+ * @param {Object} [options] Additional Telegram query options
3831
+ * @return {Promise} Returns a ManagedBotToken object
3832
+ * @see https://core.telegram.org/bots/api#replacemanagedbottoken
3833
+ */
3834
+ replaceManagedBotToken(botId, form = {}) {
3835
+ form.bot_id = botId;
3836
+ return this._request('replaceManagedBotToken', { form });
3837
+ }
3838
+
3839
+ /**
3840
+ * Use this method to save a prepared keyboard button for later use.
3841
+ *
3842
+ * @param {Object} button KeyboardButton object to save
3843
+ * @param {Object} [options] Additional Telegram query options
3844
+ * @return {Promise} Returns a PreparedKeyboardButton object
3845
+ * @see https://core.telegram.org/bots/api#savepreparedkeyboardbutton
3846
+ */
3847
+ savePreparedKeyboardButton(button, form = {}) {
3848
+ form.button = stringify(button);
3849
+ return this._request('savePreparedKeyboardButton', { form });
3850
+ }
3851
+
3852
+ // ==========================================
3853
+ // Bot API 10.0: Guest Mode, Live Photos, Reactions
3854
+ // ==========================================
3855
+
3856
+ /**
3857
+ * Use this method to answer a guest query in a Telegram Web App.
3858
+ *
3859
+ * @param {String} guestQueryId Unique identifier for the query to be answered
3860
+ * @param {String} text Text of the message
3861
+ * @param {Object} [options] Additional Telegram query options
3862
+ * @return {Promise} True on success
3863
+ * @see https://core.telegram.org/bots/api#answerguestquery
3864
+ */
3865
+ answerGuestQuery(guestQueryId, text, form = {}) {
3866
+ if (!guestQueryId) return Promise.reject(new Error('guestQueryId is required'));
3867
+ if (!text) return Promise.reject(new Error('text is required'));
3868
+ form.guest_query_id = guestQueryId;
3869
+ form.text = text;
3870
+ return this._request('answerGuestQuery', { form });
3871
+ }
3872
+
3873
+ /**
3874
+ * Use this method to remove multiple reactions from a message.
3875
+ *
3876
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3877
+ * @param {Number} messageId Unique identifier of the target message
3878
+ * @param {Object} [options] Additional Telegram query options
3879
+ * @return {Promise} True on success
3880
+ * @see https://core.telegram.org/bots/api#deletemessagereactions
3881
+ */
3882
+ deleteAllMessageReactions(chatId, messageId, form = {}) {
3883
+ form.chat_id = chatId;
3884
+ form.message_id = messageId;
3885
+ return this._request('deleteAllMessageReactions', { form });
3886
+ }
3887
+
3888
+ /**
3889
+ * Use this method to remove a reaction from a message.
3890
+ *
3891
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3892
+ * @param {Number} messageId Unique identifier of the target message
3893
+ * @param {Object} [options] Additional Telegram query options
3894
+ * @return {Promise} True on success
3895
+ * @see https://core.telegram.org/bots/api#deletemessagereaction
3896
+ */
3897
+ deleteMessageReaction(chatId, messageId, form = {}) {
3898
+ form.chat_id = chatId;
3899
+ form.message_id = messageId;
3900
+ if (form.reaction_type) {
3901
+ form.reaction_type = stringify(form.reaction_type);
3902
+ }
3903
+ return this._request('deleteMessageReaction', { form });
3904
+ }
3905
+
3906
+ /**
3907
+ * Use this method to send a live photo.
3908
+ *
3909
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3910
+ * @param {String|stream.Stream|Buffer} photo A file path, Stream, Buffer, or file_id
3911
+ * @param {String|stream.Stream|Buffer} video A file path, Stream, Buffer, or file_id
3912
+ * @param {Object} [options] Additional Telegram query options
3913
+ * @param {Object} [fileOptions] Optional file related meta-data
3914
+ * @return {Promise} On success, the sent Message object is returned
3915
+ * @see https://core.telegram.org/bots/api#sendlivephoto
3916
+ */
3917
+ sendLivePhoto(chatId, photo, video, form = {}, fileOptions = {}) {
3918
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
3919
+ const opts = {
3920
+ qs: form
3921
+ };
3922
+ opts.qs.chat_id = chatId;
3923
+ try {
3924
+ const sendDataPhoto = this._formatSendData('photo', photo, fileOptions);
3925
+ const sendDataVideo = this._formatSendData('video', video, fileOptions);
3926
+ opts.formData = Object.assign({}, sendDataPhoto[0], sendDataVideo[0]);
3927
+ opts.qs.photo = sendDataPhoto[1];
3928
+ opts.qs.video = sendDataVideo[1];
3929
+ } catch (ex) {
3930
+ return Promise.reject(ex);
3931
+ }
3932
+ return this._request('sendLivePhoto', opts);
3933
+ }
3934
+
3935
+ /**
3936
+ * Use this method to get the current access settings of the bot for managed bots.
3937
+ *
3938
+ * @param {Object} [options] Additional Telegram query options
3939
+ * @return {Promise} Returns a ManagedBotAccessSettings object
3940
+ * @see https://core.telegram.org/bots/api#getmanagedbotaccesssettings
3941
+ */
3942
+ getManagedBotAccessSettings(form = {}) {
3943
+ return this._request('getManagedBotAccessSettings', { form });
3944
+ }
3945
+
3946
+ /**
3947
+ * Use this method to change the access settings of the bot for managed bots.
3948
+ *
3949
+ * @param {Object} [options] Additional Telegram query options
3950
+ * @return {Promise} True on success
3951
+ * @see https://core.telegram.org/bots/api#setmanagedbotaccesssettings
3952
+ */
3953
+ setManagedBotAccessSettings(form = {}) {
3954
+ if (form.restricted_channels) {
3955
+ form.restricted_channels = stringify(form.restricted_channels);
3956
+ }
3957
+ return this._request('setManagedBotAccessSettings', { form });
3958
+ }
3959
+
3960
+ /**
3961
+ * Use this method to get messages from a user's personal chat with the bot.
3962
+ *
3963
+ * @param {Number} userId Unique identifier of the target user
3964
+ * @param {Object} [options] Additional Telegram query options
3965
+ * @return {Promise} Array of Message objects
3966
+ * @see https://core.telegram.org/bots/api#getuserpersonalchatmessages
3967
+ */
3968
+ getUserPersonalChatMessages(userId, form = {}) {
3969
+ form.user_id = userId;
3970
+ return this._request('getUserPersonalChatMessages', { form });
3971
+ }
3972
+
3973
+ // ==========================================
3974
+ // Bot API 10.1: Rich Messages, Join Request Queries
3975
+ // ==========================================
3976
+
3977
+ /**
3978
+ * Use this method to send a rich message.
3979
+ *
3980
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3981
+ * @param {Object} content An InputRichMessageContent object
3982
+ * @param {Object} [options] Additional Telegram query options
3983
+ * @return {Promise} On success, the sent Message object is returned
3984
+ * @see https://core.telegram.org/bots/api#sendrichmessage
3985
+ */
3986
+ sendRichMessage(chatId, content, form = {}) {
3987
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
3988
+ if (!content) return Promise.reject(new Error('content is required'));
3989
+ form.chat_id = chatId;
3990
+ form.content = stringify(content);
3991
+ return this._request('sendRichMessage', { form });
3992
+ }
3993
+
3994
+ /**
3995
+ * Use this method to send a rich message draft.
3996
+ *
3997
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3998
+ * @param {Object} content An InputRichMessageContent object
3999
+ * @param {Object} [options] Additional Telegram query options
4000
+ * @return {Promise} On success, a Message object is returned
4001
+ * @see https://core.telegram.org/bots/api#sendrichmessagedraft
4002
+ */
4003
+ sendRichMessageDraft(chatId, content, form = {}) {
4004
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4005
+ if (!content) return Promise.reject(new Error('content is required'));
4006
+ form.chat_id = chatId;
4007
+ form.content = stringify(content);
4008
+ return this._request('sendRichMessageDraft', { form });
4009
+ }
4010
+
4011
+ /**
4012
+ * Use this method to answer a chat join request query.
4013
+ *
4014
+ * @param {Number} chatJoinRequestId Unique identifier of the chat join request
4015
+ * @param {String} queryId Unique identifier for the query to be answered
4016
+ * @param {Object} [options] Additional Telegram query options
4017
+ * @return {Promise} True on success
4018
+ * @see https://core.telegram.org/bots/api#answerchatjoinrequestquery
4019
+ */
4020
+ answerChatJoinRequestQuery(chatJoinRequestId, queryId, form = {}) {
4021
+ if (!chatJoinRequestId) return Promise.reject(new Error('chatJoinRequestId is required'));
4022
+ if (!queryId) return Promise.reject(new Error('queryId is required'));
4023
+ form.chat_join_request_id = chatJoinRequestId;
4024
+ form.query_id = queryId;
4025
+ return this._request('answerChatJoinRequestQuery', { form });
4026
+ }
4027
+
4028
+ /**
4029
+ * Use this method to send a Web App message to a chat join request.
4030
+ *
4031
+ * @param {Number} chatJoinRequestId Unique identifier of the chat join request
4032
+ * @param {Object} webApp A SentWebAppMessage object
4033
+ * @param {Object} [options] Additional Telegram query options
4034
+ * @return {Promise} True on success
4035
+ * @see https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
4036
+ */
4037
+ sendChatJoinRequestWebApp(chatJoinRequestId, webApp, form = {}) {
4038
+ if (!chatJoinRequestId) return Promise.reject(new Error('chatJoinRequestId is required'));
4039
+ if (!webApp) return Promise.reject(new Error('webApp is required'));
4040
+ form.chat_join_request_id = chatJoinRequestId;
4041
+ form.web_app = stringify(webApp);
4042
+ return this._request('sendChatJoinRequestWebApp', { form });
4043
+ }
4044
+
4045
+ // ==========================================
4046
+ // Bot API 10.2: Ephemeral Messages
4047
+ // ==========================================
4048
+
4049
+ /**
4050
+ * Use this method to edit the text of an ephemeral message.
4051
+ *
4052
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4053
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4054
+ * @param {String} text New text of the message
4055
+ * @param {Object} [options] Additional Telegram query options
4056
+ * @return {Promise} On success, the edited Message object is returned
4057
+ * @see https://core.telegram.org/bots/api#editephemeralmessagetext
4058
+ */
4059
+ editEphemeralMessageText(chatId, ephemeralMessageId, text, form = {}) {
4060
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4061
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4062
+ form.chat_id = chatId;
4063
+ form.ephemeral_message_id = ephemeralMessageId;
4064
+ form.text = text;
4065
+ return this._request('editEphemeralMessageText', { form });
4066
+ }
4067
+
4068
+ /**
4069
+ * Use this method to edit the media of an ephemeral message.
4070
+ *
4071
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4072
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4073
+ * @param {Object} media An InputMedia object
4074
+ * @param {Object} [options] Additional Telegram query options
4075
+ * @param {Object} [fileOptions] Optional file related meta-data
4076
+ * @return {Promise} On success, the edited Message object is returned
4077
+ * @see https://core.telegram.org/bots/api#editephemeralmessagemedia
4078
+ */
4079
+ editEphemeralMessageMedia(chatId, ephemeralMessageId, media, form = {}, fileOptions = {}) {
4080
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4081
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4082
+ form.chat_id = chatId;
4083
+ form.ephemeral_message_id = ephemeralMessageId;
4084
+ form.media = stringify(media);
4085
+ return this._request('editEphemeralMessageMedia', { form });
4086
+ }
4087
+
4088
+ /**
4089
+ * Use this method to edit the caption of an ephemeral message.
4090
+ *
4091
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4092
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4093
+ * @param {Object} [options] Additional Telegram query options
4094
+ * @return {Promise} On success, the edited Message object is returned
4095
+ * @see https://core.telegram.org/bots/api#editephemeralmessagecaption
4096
+ */
4097
+ editEphemeralMessageCaption(chatId, ephemeralMessageId, form = {}) {
4098
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4099
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4100
+ form.chat_id = chatId;
4101
+ form.ephemeral_message_id = ephemeralMessageId;
4102
+ this._fixEntitiesField(form);
4103
+ return this._request('editEphemeralMessageCaption', { form });
4104
+ }
4105
+
4106
+ /**
4107
+ * Use this method to edit the reply markup of an ephemeral message.
4108
+ *
4109
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4110
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4111
+ * @param {Object} [options] Additional Telegram query options
4112
+ * @return {Promise} On success, the edited Message object is returned
4113
+ * @see https://core.telegram.org/bots/api#editephemeralmessagereplymarkup
4114
+ */
4115
+ editEphemeralMessageReplyMarkup(chatId, ephemeralMessageId, form = {}) {
4116
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4117
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4118
+ form.chat_id = chatId;
4119
+ form.ephemeral_message_id = ephemeralMessageId;
4120
+ return this._request('editEphemeralMessageReplyMarkup', { form });
4121
+ }
4122
+
4123
+ /**
4124
+ * Use this method to delete an ephemeral message.
4125
+ *
4126
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4127
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4128
+ * @param {Object} [options] Additional Telegram query options
4129
+ * @return {Promise} True on success
4130
+ * @see https://core.telegram.org/bots/api#deleteephemeralmessage
4131
+ */
4132
+ deleteEphemeralMessage(chatId, ephemeralMessageId, form = {}) {
4133
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4134
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4135
+ form.chat_id = chatId;
4136
+ form.ephemeral_message_id = ephemeralMessageId;
4137
+ return this._request('deleteEphemeralMessage', { form });
4138
+ }
4139
+
3055
4140
  }
3056
4141
 
3057
4142
  module.exports = TelegramBot;