@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/src/telegram.js CHANGED
@@ -61,7 +61,53 @@ const _messageTypes = [
61
61
  'chat_invite_link',
62
62
  'chat_member_updated',
63
63
  'web_app_data',
64
- 'message_reaction'
64
+ 'message_reaction',
65
+ // Bot API 7.7
66
+ 'refunded_payment',
67
+ // Bot API 9.0
68
+ 'gift',
69
+ 'unique_gift',
70
+ 'paid_message_price_changed',
71
+ 'paid_star_count',
72
+ // Bot API 9.1
73
+ 'checklist',
74
+ 'checklist_tasks_done',
75
+ 'checklist_tasks_added',
76
+ 'direct_message_price_changed',
77
+ // Bot API 9.2
78
+ 'direct_messages_topic',
79
+ 'suggested_post_info',
80
+ 'suggested_post_approved',
81
+ 'suggested_post_approval_failed',
82
+ 'suggested_post_declined',
83
+ 'suggested_post_paid',
84
+ 'suggested_post_refunded',
85
+ // Bot API 9.3
86
+ 'gift_upgrade_sent',
87
+ // Bot API 9.4
88
+ 'chat_owner_left',
89
+ 'chat_owner_changed',
90
+ // Bot API 9.5
91
+ 'sender_tag',
92
+ // Bot API 9.6
93
+ 'managed_bot_created',
94
+ 'poll_option_added',
95
+ 'poll_option_deleted',
96
+ // Bot API 10.0
97
+ 'guest_bot_caller_user',
98
+ 'guest_bot_caller_chat',
99
+ 'guest_query_id',
100
+ 'live_photo',
101
+ // Bot API 10.1
102
+ 'rich_message',
103
+ // Bot API 10.2
104
+ 'ephemeral_message_id',
105
+ 'receiver_user',
106
+ 'community_chat_added',
107
+ 'community_chat_removed',
108
+ // Bot API 10.3
109
+ 'stopped_message_generation',
110
+ 'community_chat_joined',
65
111
  ];
66
112
 
67
113
  const _deprecatedMessageTypes = [
@@ -274,6 +320,34 @@ class TelegramBot extends EventEmitter {
274
320
  }
275
321
  }
276
322
 
323
+ /**
324
+ * Fix JSON-serialized object fields by making them JSON strings if they are still objects.
325
+ * Covers new Bot API 7.4-10.3 fields that accept JSON-serialized objects.
326
+ * @param {Object} obj Object; either 'form' or 'qs'
327
+ * @private
328
+ */
329
+ _fixJsonFields(obj) {
330
+ const jsonFields = [
331
+ 'rich_message',
332
+ 'content',
333
+ 'result',
334
+ 'button',
335
+ 'web_app',
336
+ 'photo',
337
+ 'tasks',
338
+ 'reaction_type',
339
+ 'restricted_channels',
340
+ 'target_business_connection_ids',
341
+ 'accepted_gift_types',
342
+ 'link_preview_options',
343
+ ];
344
+ for (const field of jsonFields) {
345
+ if (obj.hasOwnProperty(field) && typeof obj[field] !== 'string') {
346
+ obj[field] = stringify(obj[field]);
347
+ }
348
+ }
349
+ }
350
+
277
351
  /**
278
352
  * Make request against the API
279
353
  * @param {String} _path API endpoint
@@ -294,10 +368,12 @@ class TelegramBot extends EventEmitter {
294
368
  this._fixReplyMarkup(options.form);
295
369
  this._fixEntitiesField(options.form);
296
370
  this._fixReplyParameters(options.form);
371
+ this._fixJsonFields(options.form);
297
372
  }
298
373
  if (options.qs) {
299
374
  this._fixReplyMarkup(options.qs);
300
375
  this._fixReplyParameters(options.qs);
376
+ this._fixJsonFields(options.qs);
301
377
  }
302
378
 
303
379
  options.method = 'POST';
@@ -3114,6 +3190,1050 @@ class TelegramBot extends EventEmitter {
3114
3190
  return this._request('deleteMessages', { form });
3115
3191
  }
3116
3192
 
3193
+ // ==========================================
3194
+ // Bot API 7.4
3195
+ // ==========================================
3196
+
3197
+ /**
3198
+ * Use this method to issue a refund for a payment made via Telegram Stars.
3199
+ *
3200
+ * @param {Number} userId Identifier of the user whose payment will be refunded
3201
+ * @param {String} telegramPaymentChargeId Telegram payment identifier of the payment to refund
3202
+ * @param {Object} [options] Additional Telegram query options
3203
+ * @return {Promise} On success, True is returned
3204
+ * @see https://core.telegram.org/bots/api#refundstarpayment
3205
+ */
3206
+ refundStarPayment(userId, telegramPaymentChargeId, form = {}) {
3207
+ form.user_id = userId;
3208
+ form.telegram_payment_charge_id = telegramPaymentChargeId;
3209
+ return this._request('refundStarPayment', { form });
3210
+ }
3211
+
3212
+ // ==========================================
3213
+ // Bot API 7.5
3214
+ // ==========================================
3215
+
3216
+ /**
3217
+ * Use this method to get the current status of the balance of Telegram Stars
3218
+ * that can be withdrawn by the bot or transferred to another business account.
3219
+ *
3220
+ * @param {Object} [options] Additional Telegram query options
3221
+ * @return {Promise} On success, returns a StarTransactions object
3222
+ * @see https://core.telegram.org/bots/api#getstartransactions
3223
+ */
3224
+ getStarTransactions(form = {}) {
3225
+ return this._request('getStarTransactions', { form });
3226
+ }
3227
+
3228
+ // ==========================================
3229
+ // Bot API 7.6
3230
+ // ==========================================
3231
+
3232
+ /**
3233
+ * Use this method to send paid media.
3234
+ *
3235
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3236
+ * @param {Number} starCount The number of Telegram Stars that must be paid to buy access to the media
3237
+ * @param {Array} media A JSON-serialized array describing the media to be sent; currently supports photos and videos
3238
+ * @param {Object} [options] Additional Telegram query options
3239
+ * @return {Promise} On success, the sent Message object is returned
3240
+ * @see https://core.telegram.org/bots/api#sendpaidmedia
3241
+ */
3242
+ sendPaidMedia(chatId, starCount, media, form = {}) {
3243
+ form.chat_id = chatId;
3244
+ form.star_count = starCount;
3245
+ form.media = stringify(media);
3246
+ return this._request('sendPaidMedia', { form });
3247
+ }
3248
+
3249
+ // ==========================================
3250
+ // Bot API 7.9
3251
+ // ==========================================
3252
+
3253
+ /**
3254
+ * Use this method to create a subscription invite link for a channel chat.
3255
+ *
3256
+ * @param {Number|String} chatId Unique identifier for the target channel chat or username of the target channel (in the format `@channelusername`)
3257
+ * @param {Object} [options] Additional Telegram query options
3258
+ * @return {Promise} On success, the new invite link as a ChatInviteLink object is returned
3259
+ * @see https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
3260
+ */
3261
+ createChatSubscriptionInviteLink(chatId, form = {}) {
3262
+ form.chat_id = chatId;
3263
+ return this._request('createChatSubscriptionInviteLink', { form });
3264
+ }
3265
+
3266
+ /**
3267
+ * Use this method to edit a subscription invite link created by the bot.
3268
+ *
3269
+ * @param {Number|String} chatId Unique identifier for the target channel chat or username of the target channel (in the format `@channelusername`)
3270
+ * @param {String} inviteLink The invite link to edit
3271
+ * @param {Object} [options] Additional Telegram query options
3272
+ * @return {Promise} On success, the edited invite link as a ChatInviteLink object is returned
3273
+ * @see https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
3274
+ */
3275
+ editChatSubscriptionInviteLink(chatId, inviteLink, form = {}) {
3276
+ form.chat_id = chatId;
3277
+ form.invite_link = inviteLink;
3278
+ return this._request('editChatSubscriptionInviteLink', { form });
3279
+ }
3280
+
3281
+ // ==========================================
3282
+ // Bot API 8.0
3283
+ // ==========================================
3284
+
3285
+ /**
3286
+ * Use this method to get the list of gifts that can be sent by the bot.
3287
+ *
3288
+ * @param {Object} [options] Additional Telegram query options
3289
+ * @return {Promise} On success, returns a Gifts object
3290
+ * @see https://core.telegram.org/bots/api#getavailablegifts
3291
+ */
3292
+ getAvailableGifts(form = {}) {
3293
+ return this._request('getAvailableGifts', { form });
3294
+ }
3295
+
3296
+ /**
3297
+ * Use this method to send a gift to a user.
3298
+ *
3299
+ * @param {Number} userId Unique identifier of the target user that will receive the gift
3300
+ * @param {String} giftId Identifier of the gift
3301
+ * @param {Object} [options] Additional Telegram query options
3302
+ * @return {Promise} On success, True is returned
3303
+ * @see https://core.telegram.org/bots/api#sendgift
3304
+ */
3305
+ sendGift(userId, giftId, form = {}) {
3306
+ form.user_id = userId;
3307
+ form.gift_id = giftId;
3308
+ return this._request('sendGift', { form });
3309
+ }
3310
+
3311
+ /**
3312
+ * Use this method to edit a subscription paid through Telegram Stars.
3313
+ *
3314
+ * @param {Number} userId Identifier of the user whose subscription will be edited
3315
+ * @param {String} telegramPaymentChargeId Telegram payment identifier of the subscription payment
3316
+ * @param {Boolean} isCanceled Pass True to cancel the user's subscription
3317
+ * @param {Object} [options] Additional Telegram query options
3318
+ * @return {Promise} On success, True is returned
3319
+ * @see https://core.telegram.org/bots/api#edituserstarsubscription
3320
+ */
3321
+ editUserStarSubscription(userId, telegramPaymentChargeId, isCanceled, form = {}) {
3322
+ form.user_id = userId;
3323
+ form.telegram_payment_charge_id = telegramPaymentChargeId;
3324
+ form.is_canceled = isCanceled;
3325
+ return this._request('editUserStarSubscription', { form });
3326
+ }
3327
+
3328
+ /**
3329
+ * Use this method to store an inline message that can be sent on behalf of a user.
3330
+ *
3331
+ * @param {Number} userId Unique identifier of the target user
3332
+ * @param {Object} result An object describing the message to be sent
3333
+ * @param {Object} [options] Additional Telegram query options
3334
+ * @return {Promise} On success, returns a PreparedInlineMessage object
3335
+ * @see https://core.telegram.org/bots/api#savepreparedinlinemessage
3336
+ */
3337
+ savePreparedInlineMessage(userId, result, form = {}) {
3338
+ form.user_id = userId;
3339
+ form.result = stringify(result);
3340
+ return this._request('savePreparedInlineMessage', { form });
3341
+ }
3342
+
3343
+ // ==========================================
3344
+ // Bot API 8.2
3345
+ // ==========================================
3346
+
3347
+ /**
3348
+ * Use this method to verify a user that is managed by the bot.
3349
+ *
3350
+ * @param {Number} userId Unique identifier of the target user
3351
+ * @param {Object} [options] Additional Telegram query options
3352
+ * @return {Promise} On success, True is returned
3353
+ * @see https://core.telegram.org/bots/api#verifyuser
3354
+ */
3355
+ verifyUser(userId, form = {}) {
3356
+ form.user_id = userId;
3357
+ return this._request('verifyUser', { form });
3358
+ }
3359
+
3360
+ /**
3361
+ * Use this method to verify a chat that is managed by the bot.
3362
+ *
3363
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3364
+ * @param {Object} [options] Additional Telegram query options
3365
+ * @return {Promise} On success, True is returned
3366
+ * @see https://core.telegram.org/bots/api#verifychat
3367
+ */
3368
+ verifyChat(chatId, form = {}) {
3369
+ form.chat_id = chatId;
3370
+ return this._request('verifyChat', { form });
3371
+ }
3372
+
3373
+ /**
3374
+ * Use this method to remove verification for a user that is managed by the bot.
3375
+ *
3376
+ * @param {Number} userId Unique identifier of the target user
3377
+ * @param {Object} [options] Additional Telegram query options
3378
+ * @return {Promise} On success, True is returned
3379
+ * @see https://core.telegram.org/bots/api#removeuserverification
3380
+ */
3381
+ removeUserVerification(userId, form = {}) {
3382
+ form.user_id = userId;
3383
+ return this._request('removeUserVerification', { form });
3384
+ }
3385
+
3386
+ /**
3387
+ * Use this method to remove verification for a chat that is managed by the bot.
3388
+ *
3389
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3390
+ * @param {Object} [options] Additional Telegram query options
3391
+ * @return {Promise} On success, True is returned
3392
+ * @see https://core.telegram.org/bots/api#removechatverification
3393
+ */
3394
+ removeChatVerification(chatId, form = {}) {
3395
+ form.chat_id = chatId;
3396
+ return this._request('removeChatVerification', { form });
3397
+ }
3398
+
3399
+ // ==========================================
3400
+ // Bot API 9.0: Business Accounts + Gifts
3401
+ // ==========================================
3402
+
3403
+ /**
3404
+ * Use this method to mark incoming messages as read on behalf of a business account.
3405
+ *
3406
+ * @param {String} businessConnectionId Unique identifier of the business connection
3407
+ * @param {Number} messageId Unique identifier of the message to mark as read
3408
+ * @param {Object} [options] Additional Telegram query options
3409
+ * @return {Promise} True on success
3410
+ * @see https://core.telegram.org/bots/api#readbusinessmessage
3411
+ */
3412
+ readBusinessMessage(businessConnectionId, messageId, form = {}) {
3413
+ form.business_connection_id = businessConnectionId;
3414
+ form.message_id = messageId;
3415
+ return this._request('readBusinessMessage', { form });
3416
+ }
3417
+
3418
+ /**
3419
+ * Use this method to delete messages on behalf of a business account.
3420
+ *
3421
+ * @param {String} businessConnectionId Unique identifier of the business connection
3422
+ * @param {Array<Number>} messageIds Unique identifiers of 1-100 messages to delete
3423
+ * @param {Object} [options] Additional Telegram query options
3424
+ * @return {Promise} True on success
3425
+ * @see https://core.telegram.org/bots/api#deletebusinessmessages
3426
+ */
3427
+ deleteBusinessMessages(businessConnectionId, messageIds, form = {}) {
3428
+ form.business_connection_id = businessConnectionId;
3429
+ form.message_ids = stringify(messageIds);
3430
+ return this._request('deleteBusinessMessages', { form });
3431
+ }
3432
+
3433
+ /**
3434
+ * Use this method to change the first and last name of a managed business account.
3435
+ *
3436
+ * @param {String} businessConnectionId Unique identifier of the business connection
3437
+ * @param {Object} [options] Additional Telegram query options
3438
+ * @return {Promise} True on success
3439
+ * @see https://core.telegram.org/bots/api#setbusinessaccountname
3440
+ */
3441
+ setBusinessAccountName(businessConnectionId, form = {}) {
3442
+ form.business_connection_id = businessConnectionId;
3443
+ return this._request('setBusinessAccountName', { form });
3444
+ }
3445
+
3446
+ /**
3447
+ * Use this method to change the username of a managed business account.
3448
+ *
3449
+ * @param {String} businessConnectionId Unique identifier of the business connection
3450
+ * @param {Object} [options] Additional Telegram query options
3451
+ * @return {Promise} True on success
3452
+ * @see https://core.telegram.org/bots/api#setbusinessaccountusername
3453
+ */
3454
+ setBusinessAccountUsername(businessConnectionId, form = {}) {
3455
+ form.business_connection_id = businessConnectionId;
3456
+ return this._request('setBusinessAccountUsername', { form });
3457
+ }
3458
+
3459
+ /**
3460
+ * Use this method to change the bio of a managed business account.
3461
+ *
3462
+ * @param {String} businessConnectionId Unique identifier of the business connection
3463
+ * @param {Object} [options] Additional Telegram query options
3464
+ * @return {Promise} True on success
3465
+ * @see https://core.telegram.org/bots/api#setbusinessaccountbio
3466
+ */
3467
+ setBusinessAccountBio(businessConnectionId, form = {}) {
3468
+ form.business_connection_id = businessConnectionId;
3469
+ return this._request('setBusinessAccountBio', { form });
3470
+ }
3471
+
3472
+ /**
3473
+ * Use this method to change the profile photo of a managed business account.
3474
+ *
3475
+ * @param {String} businessConnectionId Unique identifier of the business connection
3476
+ * @param {Object} photo InputProfilePhoto object
3477
+ * @param {Object} [options] Additional Telegram query options
3478
+ * @return {Promise} True on success
3479
+ * @see https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
3480
+ */
3481
+ setBusinessAccountProfilePhoto(businessConnectionId, photo, form = {}) {
3482
+ form.business_connection_id = businessConnectionId;
3483
+ form.photo = stringify(photo);
3484
+ return this._request('setBusinessAccountProfilePhoto', { form });
3485
+ }
3486
+
3487
+ /**
3488
+ * Use this method to remove the profile photo of a managed business account.
3489
+ *
3490
+ * @param {String} businessConnectionId Unique identifier of the business connection
3491
+ * @param {Object} [options] Additional Telegram query options
3492
+ * @return {Promise} True on success
3493
+ * @see https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
3494
+ */
3495
+ removeBusinessAccountProfilePhoto(businessConnectionId, form = {}) {
3496
+ form.business_connection_id = businessConnectionId;
3497
+ return this._request('removeBusinessAccountProfilePhoto', { form });
3498
+ }
3499
+
3500
+ /**
3501
+ * Use this method to change the gift settings of a managed business account.
3502
+ *
3503
+ * @param {String} businessConnectionId Unique identifier of the business connection
3504
+ * @param {Object} [options] Additional Telegram query options
3505
+ * @return {Promise} True on success
3506
+ * @see https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
3507
+ */
3508
+ setBusinessAccountGiftSettings(businessConnectionId, form = {}) {
3509
+ form.business_connection_id = businessConnectionId;
3510
+ if (form.accepted_gift_types) {
3511
+ form.accepted_gift_types = stringify(form.accepted_gift_types);
3512
+ }
3513
+ return this._request('setBusinessAccountGiftSettings', { form });
3514
+ }
3515
+
3516
+ /**
3517
+ * Use this method to get the current Star balance of a managed business account.
3518
+ *
3519
+ * @param {String} businessConnectionId Unique identifier of the business connection
3520
+ * @param {Object} [options] Additional Telegram query options
3521
+ * @return {Promise} Returns a StarAmount object
3522
+ * @see https://core.telegram.org/bots/api#getbusinessaccountstarbalance
3523
+ */
3524
+ getBusinessAccountStarBalance(businessConnectionId, form = {}) {
3525
+ form.business_connection_id = businessConnectionId;
3526
+ return this._request('getBusinessAccountStarBalance', { form });
3527
+ }
3528
+
3529
+ /**
3530
+ * Use this method to transfer Stars from the business account balance to the bot owner's balance.
3531
+ *
3532
+ * @param {String} businessConnectionId Unique identifier of the business connection
3533
+ * @param {Number} starCount Number of Telegram Stars to transfer, 1-10000
3534
+ * @param {Object} [options] Additional Telegram query options
3535
+ * @return {Promise} Returns a StarAmount object
3536
+ * @see https://core.telegram.org/bots/api#transferbusinessaccountstars
3537
+ */
3538
+ transferBusinessAccountStars(businessConnectionId, starCount, form = {}) {
3539
+ form.business_connection_id = businessConnectionId;
3540
+ form.star_count = starCount;
3541
+ return this._request('transferBusinessAccountStars', { form });
3542
+ }
3543
+
3544
+ /**
3545
+ * Use this method to get the list of gifts received by a managed business account.
3546
+ *
3547
+ * @param {String} businessConnectionId Unique identifier of the business connection
3548
+ * @param {Object} [options] Additional Telegram query options
3549
+ * @return {Promise} Returns an Array of OwnedGift objects
3550
+ * @see https://core.telegram.org/bots/api#getbusinessaccountgifts
3551
+ */
3552
+ getBusinessAccountGifts(businessConnectionId, form = {}) {
3553
+ form.business_connection_id = businessConnectionId;
3554
+ return this._request('getBusinessAccountGifts', { form });
3555
+ }
3556
+
3557
+ /**
3558
+ * Use this method to convert a given regular gift to Telegram Stars.
3559
+ *
3560
+ * @param {String} businessConnectionId Unique identifier of the business connection
3561
+ * @param {String} ownedGiftId Identifier of the regular gift
3562
+ * @param {Object} [options] Additional Telegram query options
3563
+ * @return {Promise} Returns a StarAmount object
3564
+ * @see https://core.telegram.org/bots/api#convertgifttostars
3565
+ */
3566
+ convertGiftToStars(businessConnectionId, ownedGiftId, form = {}) {
3567
+ form.business_connection_id = businessConnectionId;
3568
+ form.owned_gift_id = ownedGiftId;
3569
+ return this._request('convertGiftToStars', { form });
3570
+ }
3571
+
3572
+ /**
3573
+ * Use this method to upgrade a regular gift to a unique or upgrade a unique gift to an upgraded collectible gift.
3574
+ *
3575
+ * @param {String} businessConnectionId Unique identifier of the business connection
3576
+ * @param {String} ownedGiftId Identifier of the regular gift to upgrade
3577
+ * @param {Object} [options] Additional Telegram query options
3578
+ * @return {Promise} Returns the updated OwnedGift object
3579
+ * @see https://core.telegram.org/bots/api#upgradegift
3580
+ */
3581
+ upgradeGift(businessConnectionId, ownedGiftId, form = {}) {
3582
+ form.business_connection_id = businessConnectionId;
3583
+ form.owned_gift_id = ownedGiftId;
3584
+ return this._request('upgradeGift', { form });
3585
+ }
3586
+
3587
+ /**
3588
+ * Use this method to transfer a regular gift to another user.
3589
+ *
3590
+ * @param {String} businessConnectionId Unique identifier of the business connection
3591
+ * @param {String} ownedGiftId Identifier of the gift to transfer
3592
+ * @param {Number|String} newOwnerChatId Unique identifier of the new owner of the gift
3593
+ * @param {Object} [options] Additional Telegram query options
3594
+ * @return {Promise} True on success
3595
+ * @see https://core.telegram.org/bots/api#transfergift
3596
+ */
3597
+ transferGift(businessConnectionId, ownedGiftId, newOwnerChatId, form = {}) {
3598
+ form.business_connection_id = businessConnectionId;
3599
+ form.owned_gift_id = ownedGiftId;
3600
+ form.new_owner_chat_id = newOwnerChatId;
3601
+ return this._request('transferGift', { form });
3602
+ }
3603
+
3604
+ /**
3605
+ * Use this method to post a story on behalf of a managed business account.
3606
+ *
3607
+ * @param {String} businessConnectionId Unique identifier of the business connection
3608
+ * @param {Object} content InputStoryContent object
3609
+ * @param {Object} [options] Additional Telegram query options
3610
+ * @return {Promise} Returns a Story object
3611
+ * @see https://core.telegram.org/bots/api#poststory
3612
+ */
3613
+ postStory(businessConnectionId, content, form = {}) {
3614
+ form.business_connection_id = businessConnectionId;
3615
+ form.content = stringify(content);
3616
+ return this._request('postStory', { form });
3617
+ }
3618
+
3619
+ /**
3620
+ * Use this method to edit a story previously posted on behalf of a managed business account.
3621
+ *
3622
+ * @param {String} businessConnectionId Unique identifier of the business connection
3623
+ * @param {Number} storyId Identifier of the story to edit
3624
+ * @param {Object} [options] Additional Telegram query options
3625
+ * @return {Promise} Returns the edited Story object
3626
+ * @see https://core.telegram.org/bots/api#editstory
3627
+ */
3628
+ editStory(businessConnectionId, storyId, form = {}) {
3629
+ form.business_connection_id = businessConnectionId;
3630
+ form.story_id = storyId;
3631
+ if (form.content) {
3632
+ form.content = stringify(form.content);
3633
+ }
3634
+ return this._request('editStory', { form });
3635
+ }
3636
+
3637
+ /**
3638
+ * Use this method to delete a story previously posted on behalf of a managed business account.
3639
+ *
3640
+ * @param {String} businessConnectionId Unique identifier of the business connection
3641
+ * @param {Number} storyId Identifier of the story to delete
3642
+ * @param {Object} [options] Additional Telegram query options
3643
+ * @return {Promise} True on success
3644
+ * @see https://core.telegram.org/bots/api#deletestory
3645
+ */
3646
+ deleteStory(businessConnectionId, storyId, form = {}) {
3647
+ form.business_connection_id = businessConnectionId;
3648
+ form.story_id = storyId;
3649
+ return this._request('deleteStory', { form });
3650
+ }
3651
+
3652
+ /**
3653
+ * Use this method to gift a Telegram Premium subscription to a user.
3654
+ *
3655
+ * @param {Number|String} userId Unique identifier of the target user
3656
+ * @param {Number} monthCount Number of months the subscription will be active for, 1-36
3657
+ * @param {Number} starCount Number of Telegram Stars that will be paid for the subscription, 1-10000
3658
+ * @param {Object} [options] Additional Telegram query options
3659
+ * @return {Promise} Returns the Gift object that was paid for
3660
+ * @see https://core.telegram.org/bots/api#giftpremiumsubscription
3661
+ */
3662
+ giftPremiumSubscription(userId, monthCount, starCount, form = {}) {
3663
+ form.user_id = userId;
3664
+ form.month_count = monthCount;
3665
+ form.star_count = starCount;
3666
+ return this._request('giftPremiumSubscription', { form });
3667
+ }
3668
+
3669
+ /**
3670
+ * Use this method to set the emoji status of a user.
3671
+ *
3672
+ * @param {Number|String} userId Unique identifier of the target user
3673
+ * @param {Object} [options] Additional Telegram query options
3674
+ * @return {Promise} True on success
3675
+ * @see https://core.telegram.org/bots/api#setuseremojistatus
3676
+ */
3677
+ setUserEmojiStatus(userId, form = {}) {
3678
+ form.user_id = userId;
3679
+ return this._request('setUserEmojiStatus', { form });
3680
+ }
3681
+
3682
+ // ==========================================
3683
+ // Bot API 9.1: Checklists
3684
+ // ==========================================
3685
+
3686
+ /**
3687
+ * Use this method to send a checklist on behalf of a managed business account.
3688
+ *
3689
+ * @param {String} businessConnectionId Unique identifier of the business connection
3690
+ * @param {String} title Title of the checklist, 1-255 characters after entities parsing
3691
+ * @param {Array} tasks List of 1-100 tasks in the checklist
3692
+ * @param {Object} [options] Additional Telegram query options
3693
+ * @return {Promise} On success, the sent Message is returned
3694
+ * @see https://core.telegram.org/bots/api#sendchecklist
3695
+ */
3696
+ sendChecklist(businessConnectionId, title, tasks, form = {}) {
3697
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3698
+ if (!title) return Promise.reject(new Error('title is required'));
3699
+ form.business_connection_id = businessConnectionId;
3700
+ form.title = title;
3701
+ form.tasks = stringify(tasks);
3702
+ return this._request('sendChecklist', { form });
3703
+ }
3704
+
3705
+ /**
3706
+ * Use this method to edit a checklist message on behalf of a managed business account.
3707
+ *
3708
+ * @param {String} businessConnectionId Unique identifier of the business connection
3709
+ * @param {Number} messageId Unique identifier of the message to edit
3710
+ * @param {Object} [options] Additional Telegram query options
3711
+ * @return {Promise} On success, the edited Message is returned
3712
+ * @see https://core.telegram.org/bots/api#editmessagechecklist
3713
+ */
3714
+ editMessageChecklist(businessConnectionId, messageId, form = {}) {
3715
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3716
+ if (!messageId) return Promise.reject(new Error('messageId is required'));
3717
+ form.business_connection_id = businessConnectionId;
3718
+ form.message_id = messageId;
3719
+ if (form.tasks) {
3720
+ form.tasks = stringify(form.tasks);
3721
+ }
3722
+ return this._request('editMessageChecklist', { form });
3723
+ }
3724
+
3725
+ /**
3726
+ * Use this method to get the current number of Telegram Stars owned by the bot.
3727
+ *
3728
+ * @param {Object} [options] Additional Telegram query options
3729
+ * @return {Promise} Returns a StarAmount object
3730
+ * @see https://core.telegram.org/bots/api#getmystarbalance
3731
+ */
3732
+ getMyStarBalance(form = {}) {
3733
+ return this._request('getMyStarBalance', { form });
3734
+ }
3735
+
3736
+ // ==========================================
3737
+ // Bot API 9.2: Suggested Posts
3738
+ // ==========================================
3739
+
3740
+ /**
3741
+ * Use this method to approve a suggested post in a channel chat.
3742
+ *
3743
+ * @param {String} businessConnectionId Unique identifier of the business connection
3744
+ * @param {Number} messageId Unique identifier of the suggested post message
3745
+ * @param {Object} [options] Additional Telegram query options
3746
+ * @return {Promise} True on success
3747
+ * @see https://core.telegram.org/bots/api#approvesuggestedpost
3748
+ */
3749
+ approveSuggestedPost(businessConnectionId, messageId, form = {}) {
3750
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3751
+ if (!messageId) return Promise.reject(new Error('messageId is required'));
3752
+ form.business_connection_id = businessConnectionId;
3753
+ form.message_id = messageId;
3754
+ return this._request('approveSuggestedPost', { form });
3755
+ }
3756
+
3757
+ /**
3758
+ * Use this method to decline a suggested post in a channel chat.
3759
+ *
3760
+ * @param {String} businessConnectionId Unique identifier of the business connection
3761
+ * @param {Number} messageId Unique identifier of the suggested post message
3762
+ * @param {Object} [options] Additional Telegram query options
3763
+ * @return {Promise} True on success
3764
+ * @see https://core.telegram.org/bots/api#declinesuggestedpost
3765
+ */
3766
+ declineSuggestedPost(businessConnectionId, messageId, form = {}) {
3767
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3768
+ if (!messageId) return Promise.reject(new Error('messageId is required'));
3769
+ form.business_connection_id = businessConnectionId;
3770
+ form.message_id = messageId;
3771
+ return this._request('declineSuggestedPost', { form });
3772
+ }
3773
+
3774
+ // ==========================================
3775
+ // Bot API 9.3: Draft Messages, Gifts, Stories
3776
+ // ==========================================
3777
+
3778
+ /**
3779
+ * Use this method to send a draft message to the bot's user in private chat.
3780
+ *
3781
+ * @param {Number|String} chatId Unique identifier of the target private chat
3782
+ * @param {String} text Text of the message, 1-4096 characters after entities parsing
3783
+ * @param {Object} [options] Additional Telegram query options
3784
+ * @return {Promise} On success, the sent Message is returned
3785
+ * @see https://core.telegram.org/bots/api#sendmessagedraft
3786
+ */
3787
+ sendMessageDraft(chatId, text, form = {}) {
3788
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
3789
+ if (!text) return Promise.reject(new Error('text is required'));
3790
+ form.chat_id = chatId;
3791
+ form.text = text;
3792
+ if (form.entities) {
3793
+ form.entities = stringify(form.entities);
3794
+ }
3795
+ if (form.link_preview_options) {
3796
+ form.link_preview_options = stringify(form.link_preview_options);
3797
+ }
3798
+ return this._request('sendMessageDraft', { form });
3799
+ }
3800
+
3801
+ /**
3802
+ * Use this method to get gifts received by a user in a private chat.
3803
+ *
3804
+ * @param {Number|String} userId Unique identifier of the target user
3805
+ * @param {Object} [options] Additional Telegram query options
3806
+ * @return {Promise} Array of OwnedGift objects
3807
+ * @see https://core.telegram.org/bots/api#getusergifts
3808
+ */
3809
+ getUserGifts(userId, form = {}) {
3810
+ form.user_id = userId;
3811
+ return this._request('getUserGifts', { form });
3812
+ }
3813
+
3814
+ /**
3815
+ * Use this method to get gifts received by a chat.
3816
+ *
3817
+ * @param {Number|String} chatId Unique identifier of the target chat
3818
+ * @param {Object} [options] Additional Telegram query options
3819
+ * @return {Promise} Array of OwnedGift objects
3820
+ * @see https://core.telegram.org/bots/api#getchatgifts
3821
+ */
3822
+ getChatGifts(chatId, form = {}) {
3823
+ form.chat_id = chatId;
3824
+ return this._request('getChatGifts', { form });
3825
+ }
3826
+
3827
+ /**
3828
+ * Use this method to repost a story on behalf of a managed business account.
3829
+ *
3830
+ * @param {String} businessConnectionId Unique identifier of the business connection
3831
+ * @param {Number} storyId Identifier of the story to repost
3832
+ * @param {Array<Number|String>} targetBusinessConnectionIds Identifiers of the business connections to post the story to
3833
+ * @param {Object} [options] Additional Telegram query options
3834
+ * @return {Promise} Array of Story objects
3835
+ * @see https://core.telegram.org/bots/api#repoststory
3836
+ */
3837
+ repostStory(businessConnectionId, storyId, targetBusinessConnectionIds, form = {}) {
3838
+ if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3839
+ if (!storyId) return Promise.reject(new Error('storyId is required'));
3840
+ form.business_connection_id = businessConnectionId;
3841
+ form.story_id = storyId;
3842
+ form.target_business_connection_ids = stringify(targetBusinessConnectionIds);
3843
+ return this._request('repostStory', { form });
3844
+ }
3845
+
3846
+ // ==========================================
3847
+ // Bot API 9.4: Profile Photos, Audio Stories
3848
+ // ==========================================
3849
+
3850
+ /**
3851
+ * Use this method to set the profile photo of the bot.
3852
+ *
3853
+ * @param {Object} photo InputProfilePhoto object
3854
+ * @param {Object} [options] Additional Telegram query options
3855
+ * @return {Promise} True on success
3856
+ * @see https://core.telegram.org/bots/api#setmyprofilephoto
3857
+ */
3858
+ setMyProfilePhoto(photo, form = {}) {
3859
+ form.photo = stringify(photo);
3860
+ return this._request('setMyProfilePhoto', { form });
3861
+ }
3862
+
3863
+ /**
3864
+ * Use this method to remove the profile photo of the bot.
3865
+ *
3866
+ * @param {Object} [options] Additional Telegram query options
3867
+ * @return {Promise} True on success
3868
+ * @see https://core.telegram.org/bots/api#removemyprofilephoto
3869
+ */
3870
+ removeMyProfilePhoto(form = {}) {
3871
+ return this._request('removeMyProfilePhoto', { form });
3872
+ }
3873
+
3874
+ /**
3875
+ * Use this method to get the profile audios of a user.
3876
+ *
3877
+ * @param {Number|String} userId Unique identifier of the target user
3878
+ * @param {Object} [options] Additional Telegram query options
3879
+ * @return {Promise} Array of Audio objects
3880
+ * @see https://core.telegram.org/bots/api#getuserprofileaudios
3881
+ */
3882
+ getUserProfileAudios(userId, form = {}) {
3883
+ form.user_id = userId;
3884
+ return this._request('getUserProfileAudios', { form });
3885
+ }
3886
+
3887
+ // ==========================================
3888
+ // Bot API 9.5: Chat Member Tags
3889
+ // ==========================================
3890
+
3891
+ /**
3892
+ * Use this method to set the tag that is applied to a specific user in a specific group chat.
3893
+ *
3894
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target group
3895
+ * @param {Number|String} userId Unique identifier of the target user
3896
+ * @param {Object} [options] Additional Telegram query options
3897
+ * @return {Promise} True on success
3898
+ * @see https://core.telegram.org/bots/api#setchatmembertag
3899
+ */
3900
+ setChatMemberTag(chatId, userId, form = {}) {
3901
+ form.chat_id = chatId;
3902
+ form.user_id = userId;
3903
+ return this._request('setChatMemberTag', { form });
3904
+ }
3905
+
3906
+ // ==========================================
3907
+ // Bot API 9.6: Managed Bot Tokens
3908
+ // ==========================================
3909
+
3910
+ /**
3911
+ * Use this method to get the current managable bot token for the bot.
3912
+ *
3913
+ * @param {Number} botId Identifier of the bot to get the token for
3914
+ * @param {Object} [options] Additional Telegram query options
3915
+ * @return {Promise} Returns a ManagedBotToken object
3916
+ * @see https://core.telegram.org/bots/api#getmanagedbottoken
3917
+ */
3918
+ getManagedBotToken(botId, form = {}) {
3919
+ form.bot_id = botId;
3920
+ return this._request('getManagedBotToken', { form });
3921
+ }
3922
+
3923
+ /**
3924
+ * Use this method to replace the managable bot token for the bot with a new one.
3925
+ *
3926
+ * @param {Number} botId Identifier of the bot whose token will be replaced
3927
+ * @param {Object} [options] Additional Telegram query options
3928
+ * @return {Promise} Returns a ManagedBotToken object
3929
+ * @see https://core.telegram.org/bots/api#replacemanagedbottoken
3930
+ */
3931
+ replaceManagedBotToken(botId, form = {}) {
3932
+ form.bot_id = botId;
3933
+ return this._request('replaceManagedBotToken', { form });
3934
+ }
3935
+
3936
+ /**
3937
+ * Use this method to save a prepared keyboard button for later use.
3938
+ *
3939
+ * @param {Object} button KeyboardButton object to save
3940
+ * @param {Object} [options] Additional Telegram query options
3941
+ * @return {Promise} Returns a PreparedKeyboardButton object
3942
+ * @see https://core.telegram.org/bots/api#savepreparedkeyboardbutton
3943
+ */
3944
+ savePreparedKeyboardButton(button, form = {}) {
3945
+ form.button = stringify(button);
3946
+ return this._request('savePreparedKeyboardButton', { form });
3947
+ }
3948
+
3949
+ // ==========================================
3950
+ // Bot API 10.0: Guest Mode, Live Photos, Reactions
3951
+ // ==========================================
3952
+
3953
+ /**
3954
+ * Use this method to answer a guest query in a Telegram Web App.
3955
+ *
3956
+ * @param {String} guestQueryId Unique identifier for the query to be answered
3957
+ * @param {String} text Text of the message
3958
+ * @param {Object} [options] Additional Telegram query options
3959
+ * @return {Promise} True on success
3960
+ * @see https://core.telegram.org/bots/api#answerguestquery
3961
+ */
3962
+ answerGuestQuery(guestQueryId, text, form = {}) {
3963
+ if (!guestQueryId) return Promise.reject(new Error('guestQueryId is required'));
3964
+ if (!text) return Promise.reject(new Error('text is required'));
3965
+ form.guest_query_id = guestQueryId;
3966
+ form.text = text;
3967
+ return this._request('answerGuestQuery', { form });
3968
+ }
3969
+
3970
+ /**
3971
+ * Use this method to remove multiple reactions from a message.
3972
+ *
3973
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3974
+ * @param {Number} messageId Unique identifier of the target message
3975
+ * @param {Object} [options] Additional Telegram query options
3976
+ * @return {Promise} True on success
3977
+ * @see https://core.telegram.org/bots/api#deletemessagereactions
3978
+ */
3979
+ deleteAllMessageReactions(chatId, messageId, form = {}) {
3980
+ form.chat_id = chatId;
3981
+ form.message_id = messageId;
3982
+ return this._request('deleteAllMessageReactions', { form });
3983
+ }
3984
+
3985
+ /**
3986
+ * Use this method to remove a reaction from a message.
3987
+ *
3988
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3989
+ * @param {Number} messageId Unique identifier of the target message
3990
+ * @param {Object} [options] Additional Telegram query options
3991
+ * @return {Promise} True on success
3992
+ * @see https://core.telegram.org/bots/api#deletemessagereaction
3993
+ */
3994
+ deleteMessageReaction(chatId, messageId, form = {}) {
3995
+ form.chat_id = chatId;
3996
+ form.message_id = messageId;
3997
+ if (form.reaction_type) {
3998
+ form.reaction_type = stringify(form.reaction_type);
3999
+ }
4000
+ return this._request('deleteMessageReaction', { form });
4001
+ }
4002
+
4003
+ /**
4004
+ * Use this method to send a live photo.
4005
+ *
4006
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4007
+ * @param {String|stream.Stream|Buffer} photo A file path, Stream, Buffer, or file_id
4008
+ * @param {String|stream.Stream|Buffer} video A file path, Stream, Buffer, or file_id
4009
+ * @param {Object} [options] Additional Telegram query options
4010
+ * @param {Object} [fileOptions] Optional file related meta-data
4011
+ * @return {Promise} On success, the sent Message object is returned
4012
+ * @see https://core.telegram.org/bots/api#sendlivephoto
4013
+ */
4014
+ sendLivePhoto(chatId, photo, video, form = {}, fileOptions = {}) {
4015
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4016
+ const opts = {
4017
+ qs: form,
4018
+ };
4019
+ opts.qs.chat_id = chatId;
4020
+ try {
4021
+ const sendDataPhoto = this._formatSendData('photo', photo, fileOptions);
4022
+ const sendDataVideo = this._formatSendData('video', video, fileOptions);
4023
+ opts.formData = Object.assign({}, sendDataPhoto[0], sendDataVideo[0]);
4024
+ opts.qs.photo = sendDataPhoto[1];
4025
+ opts.qs.video = sendDataVideo[1];
4026
+ } catch (ex) {
4027
+ return Promise.reject(ex);
4028
+ }
4029
+ return this._request('sendLivePhoto', opts);
4030
+ }
4031
+
4032
+ /**
4033
+ * Use this method to get the current access settings of the bot for managed bots.
4034
+ *
4035
+ * @param {Object} [options] Additional Telegram query options
4036
+ * @return {Promise} Returns a ManagedBotAccessSettings object
4037
+ * @see https://core.telegram.org/bots/api#getmanagedbotaccesssettings
4038
+ */
4039
+ getManagedBotAccessSettings(form = {}) {
4040
+ return this._request('getManagedBotAccessSettings', { form });
4041
+ }
4042
+
4043
+ /**
4044
+ * Use this method to change the access settings of the bot for managed bots.
4045
+ *
4046
+ * @param {Object} [options] Additional Telegram query options
4047
+ * @return {Promise} True on success
4048
+ * @see https://core.telegram.org/bots/api#setmanagedbotaccesssettings
4049
+ */
4050
+ setManagedBotAccessSettings(form = {}) {
4051
+ if (form.restricted_channels) {
4052
+ form.restricted_channels = stringify(form.restricted_channels);
4053
+ }
4054
+ return this._request('setManagedBotAccessSettings', { form });
4055
+ }
4056
+
4057
+ /**
4058
+ * Use this method to get messages from a user's personal chat with the bot.
4059
+ *
4060
+ * @param {Number} userId Unique identifier of the target user
4061
+ * @param {Object} [options] Additional Telegram query options
4062
+ * @return {Promise} Array of Message objects
4063
+ * @see https://core.telegram.org/bots/api#getuserpersonalchatmessages
4064
+ */
4065
+ getUserPersonalChatMessages(userId, form = {}) {
4066
+ form.user_id = userId;
4067
+ return this._request('getUserPersonalChatMessages', { form });
4068
+ }
4069
+
4070
+ // ==========================================
4071
+ // Bot API 10.1: Rich Messages, Join Request Queries
4072
+ // ==========================================
4073
+
4074
+ /**
4075
+ * Use this method to send a rich message.
4076
+ *
4077
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4078
+ * @param {Object} content An InputRichMessageContent object
4079
+ * @param {Object} [options] Additional Telegram query options
4080
+ * @return {Promise} On success, the sent Message object is returned
4081
+ * @see https://core.telegram.org/bots/api#sendrichmessage
4082
+ */
4083
+ sendRichMessage(chatId, content, form = {}) {
4084
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4085
+ if (!content) return Promise.reject(new Error('content is required'));
4086
+ form.chat_id = chatId;
4087
+ form.content = stringify(content);
4088
+ return this._request('sendRichMessage', { form });
4089
+ }
4090
+
4091
+ /**
4092
+ * Use this method to send a rich message draft.
4093
+ *
4094
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4095
+ * @param {Object} content An InputRichMessageContent object
4096
+ * @param {Object} [options] Additional Telegram query options
4097
+ * @return {Promise} On success, a Message object is returned
4098
+ * @see https://core.telegram.org/bots/api#sendrichmessagedraft
4099
+ */
4100
+ sendRichMessageDraft(chatId, content, form = {}) {
4101
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4102
+ if (!content) return Promise.reject(new Error('content is required'));
4103
+ form.chat_id = chatId;
4104
+ form.content = stringify(content);
4105
+ return this._request('sendRichMessageDraft', { form });
4106
+ }
4107
+
4108
+ /**
4109
+ * Use this method to answer a chat join request query.
4110
+ *
4111
+ * @param {Number} chatJoinRequestId Unique identifier of the chat join request
4112
+ * @param {String} queryId Unique identifier for the query to be answered
4113
+ * @param {Object} [options] Additional Telegram query options
4114
+ * @return {Promise} True on success
4115
+ * @see https://core.telegram.org/bots/api#answerchatjoinrequestquery
4116
+ */
4117
+ answerChatJoinRequestQuery(chatJoinRequestId, queryId, form = {}) {
4118
+ if (!chatJoinRequestId) return Promise.reject(new Error('chatJoinRequestId is required'));
4119
+ if (!queryId) return Promise.reject(new Error('queryId is required'));
4120
+ form.chat_join_request_id = chatJoinRequestId;
4121
+ form.query_id = queryId;
4122
+ return this._request('answerChatJoinRequestQuery', { form });
4123
+ }
4124
+
4125
+ /**
4126
+ * Use this method to send a Web App message to a chat join request.
4127
+ *
4128
+ * @param {Number} chatJoinRequestId Unique identifier of the chat join request
4129
+ * @param {Object} webApp A SentWebAppMessage object
4130
+ * @param {Object} [options] Additional Telegram query options
4131
+ * @return {Promise} True on success
4132
+ * @see https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
4133
+ */
4134
+ sendChatJoinRequestWebApp(chatJoinRequestId, webApp, form = {}) {
4135
+ if (!chatJoinRequestId) return Promise.reject(new Error('chatJoinRequestId is required'));
4136
+ if (!webApp) return Promise.reject(new Error('webApp is required'));
4137
+ form.chat_join_request_id = chatJoinRequestId;
4138
+ form.web_app = stringify(webApp);
4139
+ return this._request('sendChatJoinRequestWebApp', { form });
4140
+ }
4141
+
4142
+ // ==========================================
4143
+ // Bot API 10.2: Ephemeral Messages
4144
+ // ==========================================
4145
+
4146
+ /**
4147
+ * Use this method to edit the text of an ephemeral message.
4148
+ *
4149
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4150
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4151
+ * @param {String} text New text of the message
4152
+ * @param {Object} [options] Additional Telegram query options
4153
+ * @return {Promise} On success, the edited Message object is returned
4154
+ * @see https://core.telegram.org/bots/api#editephemeralmessagetext
4155
+ */
4156
+ editEphemeralMessageText(chatId, ephemeralMessageId, text, form = {}) {
4157
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4158
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4159
+ form.chat_id = chatId;
4160
+ form.ephemeral_message_id = ephemeralMessageId;
4161
+ form.text = text;
4162
+ return this._request('editEphemeralMessageText', { form });
4163
+ }
4164
+
4165
+ /**
4166
+ * Use this method to edit the media of an ephemeral message.
4167
+ *
4168
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4169
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4170
+ * @param {Object} media An InputMedia object
4171
+ * @param {Object} [options] Additional Telegram query options
4172
+ * @param {Object} [fileOptions] Optional file related meta-data
4173
+ * @return {Promise} On success, the edited Message object is returned
4174
+ * @see https://core.telegram.org/bots/api#editephemeralmessagemedia
4175
+ */
4176
+ editEphemeralMessageMedia(chatId, ephemeralMessageId, media, form = {}, fileOptions = {}) {
4177
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4178
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4179
+ form.chat_id = chatId;
4180
+ form.ephemeral_message_id = ephemeralMessageId;
4181
+ form.media = stringify(media);
4182
+ return this._request('editEphemeralMessageMedia', { form });
4183
+ }
4184
+
4185
+ /**
4186
+ * Use this method to edit the caption of an ephemeral message.
4187
+ *
4188
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4189
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4190
+ * @param {Object} [options] Additional Telegram query options
4191
+ * @return {Promise} On success, the edited Message object is returned
4192
+ * @see https://core.telegram.org/bots/api#editephemeralmessagecaption
4193
+ */
4194
+ editEphemeralMessageCaption(chatId, ephemeralMessageId, form = {}) {
4195
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4196
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4197
+ form.chat_id = chatId;
4198
+ form.ephemeral_message_id = ephemeralMessageId;
4199
+ this._fixEntitiesField(form);
4200
+ return this._request('editEphemeralMessageCaption', { form });
4201
+ }
4202
+
4203
+ /**
4204
+ * Use this method to edit the reply markup of an ephemeral message.
4205
+ *
4206
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4207
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4208
+ * @param {Object} [options] Additional Telegram query options
4209
+ * @return {Promise} On success, the edited Message object is returned
4210
+ * @see https://core.telegram.org/bots/api#editephemeralmessagereplymarkup
4211
+ */
4212
+ editEphemeralMessageReplyMarkup(chatId, ephemeralMessageId, form = {}) {
4213
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4214
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4215
+ form.chat_id = chatId;
4216
+ form.ephemeral_message_id = ephemeralMessageId;
4217
+ return this._request('editEphemeralMessageReplyMarkup', { form });
4218
+ }
4219
+
4220
+ /**
4221
+ * Use this method to delete an ephemeral message.
4222
+ *
4223
+ * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4224
+ * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4225
+ * @param {Object} [options] Additional Telegram query options
4226
+ * @return {Promise} True on success
4227
+ * @see https://core.telegram.org/bots/api#deleteephemeralmessage
4228
+ */
4229
+ deleteEphemeralMessage(chatId, ephemeralMessageId, form = {}) {
4230
+ if (!chatId) return Promise.reject(new Error('chatId is required'));
4231
+ if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4232
+ form.chat_id = chatId;
4233
+ form.ephemeral_message_id = ephemeralMessageId;
4234
+ return this._request('deleteEphemeralMessage', { form });
4235
+ }
4236
+
3117
4237
  }
3118
4238
 
3119
4239
  module.exports = TelegramBot;