Skip to content

Commit 6d7adc3

Browse files
feat: Support Telegram Bot API 9.0
1 parent 8fe6f04 commit 6d7adc3

File tree

4 files changed

+163
-17
lines changed

4 files changed

+163
-17
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2424
* removeUserVerification
2525
* removeChatVerification
2626

27+
5. Support Telegram Bot API 9.0 (@danielperez9430)
28+
* readBusinessMessage
29+
* deleteBusinessMessages
30+
* setBusinessAccountName
31+
* setBusinessAccountUsername
32+
* setBusinessAccountBio
33+
* setBusinessAccountProfilePhoto
34+
* removeBusinessAccountProfilePhoto
35+
* setBusinessAccountGiftSettings
36+
* getBusinessAccountStarBalance
37+
* transferBusinessAccountStars
38+
* getBusinessAccountGifts
39+
* convertGiftToStars
40+
* upgradeGift
41+
* transferGift
42+
* postStory
43+
* editStory
44+
* deleteStory
45+
* giftPremiumSubscription
46+
2747
## [0.67.0][0.67.0] - 2024-05-30
2848

2949
1. Support Telegram Bot API 7.4 (@danielperez9430)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api).
66

77

8-
[![Bot API](https://img.shields.io/badge/Bot%20API-v.8.3-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
8+
[![Bot API](https://img.shields.io/badge/Bot%20API-v.9.0-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
99
[![npm package](https://img.shields.io/npm/v/node-telegram-bot-api?logo=npm&style=flat-square)](https://www.npmjs.org/package/node-telegram-bot-api)
1010
[![Coverage Status](https://img.shields.io/codecov/c/github/yagop/node-telegram-bot-api?style=flat-square&logo=codecov)](https://codecov.io/gh/yagop/node-telegram-bot-api)
1111

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
"jsdoc-to-markdown": "^3.0.3",
6262
"mocha": "^3.5.3",
6363
"mocha-lcov-reporter": "^1.3.0",
64-
"node-static": "^0.7.10",
65-
"request": "^2.88.2"
64+
"node-static": "^0.7.10"
6665
},
6766
"repository": {
6867
"type": "git",

src/telegram.js

Lines changed: 141 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class TelegramBot extends EventEmitter {
425425
const fileIds = {};
426426

427427
files.forEach((file, index) => {
428-
let filedata = file.media || file.data;
428+
let filedata = file.media || file.data || file[type];
429429
let filename = file.filename || fileOptions.filename;
430430
let contentType = file.contentType || fileOptions.contentType;
431431

@@ -1328,7 +1328,7 @@ class TelegramBot extends EventEmitter {
13281328
* Use this method to send paid media.
13291329
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
13301330
* @param {Number} starCount The number of Telegram Stars that must be paid to buy access to the media; 1-10000
1331-
* @param {String|stream.Stream|Buffer} media A file path or Stream.
1331+
* @param {Array} media Array of [InputPaidMedia](https://core.telegram.org/bots/api#inputpaidmedia). The media property can bea String, Stream or Buffer.
13321332
* @param {Object} [options] Additional Telegram query options
13331333
* @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
13341334
* @see https://core.telegram.org/bots/api#sendpaidmedia
@@ -3338,7 +3338,7 @@ class TelegramBot extends EventEmitter {
33383338
/**
33393339
* Use this method to returns the list of gifts that can be sent by the bot to users and channel chats.
33403340
*
3341-
* @param {Object} [options] Additional Telegram query options
3341+
* @param {Object} [options] Additional Telegram query options.
33423342
* @return {Promise} On success, returns a [Gifts](https://core.telegram.org/bots/api#gifts) objects.
33433343
* @see https://core.telegram.org/bots/api#getavailablegifts
33443344
*/
@@ -3350,7 +3350,7 @@ class TelegramBot extends EventEmitter {
33503350
* Use this method to sends a gift to the given user or channel chat.
33513351
*
33523352
* @param {String} giftId Unique identifier of the gift
3353-
* @param {Object} [options] Additional Telegram query options
3353+
* @param {Object} [options] Additional Telegram query options.
33543354
* @return {Promise} On success, returns true.
33553355
* @see https://core.telegram.org/bots/api#getavailablegifts
33563356
*/
@@ -3359,11 +3359,28 @@ class TelegramBot extends EventEmitter {
33593359
return this._request('sendGift', { form });
33603360
}
33613361

3362+
/**
3363+
* Use this method to sends a gift to the given user or channel chat.
3364+
*
3365+
* @param {Number} userId Unique identifier of the target user who will receive a Telegram Premium subscription.
3366+
* @param {Number} monthCount Number of months the Telegram Premium subscription will be active for the user; must be one of 3, 6, or 12.
3367+
* @param {String} starCount Number of Telegram Stars to pay for the Telegram Premium subscription; must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months.
3368+
* @param {Object} [options] Additional Telegram query options.
3369+
* @return {Promise} On success, returns true.
3370+
* @see https://core.telegram.org/bots/api#getavailablegifts
3371+
*/
3372+
giftPremiumSubscription(userId, monthCount, starCount, form = {}) {
3373+
form.user_id = userId;
3374+
form.month_count = monthCount;
3375+
form.star_count = starCount;
3376+
return this._request('giftPremiumSubscription', { form });
3377+
}
3378+
33623379
/**
33633380
* This method verifies a user [on behalf of the organization](https://telegram.org/verify#third-party-verification) which is represented by the bot.
33643381
*
3365-
* @param {Number} userId Unique identifier of the target user
3366-
* @param {Object} [options] Additional Telegram query options
3382+
* @param {Number} userId Unique identifier of the target user.
3383+
* @param {Object} [options] Additional Telegram query options.
33673384
* @return {Promise} On success, returns true.
33683385
* @see https://core.telegram.org/bots/api#verifyuser
33693386
*/
@@ -3375,9 +3392,9 @@ class TelegramBot extends EventEmitter {
33753392
/**
33763393
* This method verifies a chat [on behalf of the organization](https://telegram.org/verify#third-party-verification) which is represented by the bot.
33773394
*
3378-
* @param {Number} chatId Unique identifier of the target chat
3395+
* @param {Number} chatId Unique identifier of the target chat.
33793396
* @return {Promise} On success, returns true.
3380-
* @param {Object} [options] Additional Telegram query options
3397+
* @param {Object} [options] Additional Telegram query options.
33813398
* @see https://core.telegram.org/bots/api#verifychat
33823399
*/
33833400
verifyChat(chatId, form = {}) {
@@ -3401,8 +3418,8 @@ class TelegramBot extends EventEmitter {
34013418
/**
34023419
* This method removes verification from a chat who is currently verified [on behalf of the organization](https://telegram.org/verify#third-party-verification) which is represented by the bot.
34033420
*
3404-
* @param {Number} chatId Unique identifier of the target chat
3405-
* @param {Object} [options] Additional Telegram query options
3421+
* @param {Number} chatId Unique identifier of the target chat.
3422+
* @param {Object} [options] Additional Telegram query options.
34063423
* @return {Promise} On success, returns true.
34073424
* @see https://core.telegram.org/bots/api#removechatverification
34083425
*/
@@ -3437,7 +3454,7 @@ class TelegramBot extends EventEmitter {
34373454
*
34383455
* @param {String} businessConnectionId Unique identifier of the business connection on behalf of which to delete the message.
34393456
* @param {Number[]} messageIds List of 1-100 identifiers of messages to delete. All messages **must be from the same chat**.
3440-
* @param {Object} [options] Additional Telegram query options
3457+
* @param {Object} [options] Additional Telegram query options.
34413458
* @return {Promise} On success, returns true.
34423459
* @see https://core.telegram.org/bots/api#deletebusinessmessages
34433460
*/
@@ -3505,9 +3522,9 @@ class TelegramBot extends EventEmitter {
35053522
* @return {Promise} On success, returns true.
35063523
* @see https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
35073524
*/
3508-
setBusinessAccountProfilePhoto(businessConnectionId, photo, form = {}) {
3525+
setBusinessAccountProfilePhoto(businessConnectionId, photo, options = {}) {
35093526
const opts = {
3510-
qs: {},
3527+
qs: options,
35113528
};
35123529

35133530
opts.qs.business_connection_id = businessConnectionId;
@@ -3520,7 +3537,7 @@ class TelegramBot extends EventEmitter {
35203537
return Promise.reject(ex);
35213538
}
35223539

3523-
return this._request('setBusinessAccountProfilePhoto', { form });
3540+
return this._request('setBusinessAccountProfilePhoto', opts);
35243541
}
35253542

35263543
/**
@@ -3659,6 +3676,116 @@ class TelegramBot extends EventEmitter {
36593676
return this._request('transferGift', { form });
36603677
}
36613678

3679+
/**
3680+
* This method posts a story on behalf of a managed business account.
3681+
*
3682+
* Requires the **can_manage_stories** business bot right.
3683+
*
3684+
* @param {String} businessConnectionId Unique identifier of the business connection.
3685+
* @param {Array} content [InputStoryContent](https://core.telegram.org/bots/api#inputpaidmedia). The photo/video property can be String, Stream or Buffer.
3686+
* @param {Number} activePeriod Unique identifier of the chat which will own the gift. The chat **must be active in the last 24 hours**.
3687+
* @param {Object} [options] Additional Telegram query options
3688+
* @return {Promise} On success, returns [Story](https://core.telegram.org/bots/api#story).
3689+
* @see https://core.telegram.org/bots/api#poststory
3690+
*/
3691+
postStory(businessConnectionId, content, activePeriod, options = {}) {
3692+
const opts = {
3693+
qs: options,
3694+
};
3695+
3696+
opts.qs.business_connection_id = businessConnectionId;
3697+
opts.qs.active_period = activePeriod;
3698+
3699+
try {
3700+
const inputHistoryContent = content;
3701+
opts.formData = {};
3702+
3703+
if (!content.type) {
3704+
return Promise.reject(new Error('content.type is required'));
3705+
}
3706+
3707+
const { formData, fileIds } = this._formatSendMultipleData(content.type, [content]);
3708+
3709+
opts.formData = formData;
3710+
3711+
if (fileIds[0]) {
3712+
inputHistoryContent[content.type] = fileIds[0];
3713+
} else {
3714+
inputHistoryContent[content.type] = `attach://${content.type}_0`;
3715+
}
3716+
3717+
opts.qs.content = stringify(inputHistoryContent);
3718+
} catch (ex) {
3719+
return Promise.reject(ex);
3720+
}
3721+
3722+
return this._request('postStory', opts);
3723+
}
3724+
3725+
/**
3726+
* This method edits a story previously posted by the bot on behalf of a managed business account.
3727+
*
3728+
* Requires the **can_manage_stories** business bot right.
3729+
*
3730+
* @param {String} businessConnectionId Unique identifier of the business connection.
3731+
* @param {Number} storyId Unique identifier of the story to edit.
3732+
* @param {Array} content [InputStoryContent](https://core.telegram.org/bots/api#inputpaidmedia). The photo/video property can be String, Stream or Buffer.
3733+
* @param {Object} [options] Additional Telegram query options
3734+
* @return {Promise} On success, returns [Story](https://core.telegram.org/bots/api#story).
3735+
* @see https://core.telegram.org/bots/api#editstory
3736+
*/
3737+
editStory(businessConnectionId, storyId, content, options = {}) {
3738+
const opts = {
3739+
qs: options,
3740+
};
3741+
3742+
opts.qs.business_connection_id = businessConnectionId;
3743+
opts.qs.story_id = storyId;
3744+
3745+
try {
3746+
const inputHistoryContent = content;
3747+
opts.formData = {};
3748+
3749+
if (!content.type) {
3750+
return Promise.reject(new Error('content.type is required'));
3751+
}
3752+
3753+
const { formData, fileIds } = this._formatSendMultipleData(content.type, [content]);
3754+
3755+
opts.formData = formData;
3756+
3757+
if (fileIds[0]) {
3758+
inputHistoryContent[content.type] = fileIds[0];
3759+
} else {
3760+
inputHistoryContent[content.type] = `attach://${content.type}_0`;
3761+
}
3762+
3763+
opts.qs.content = stringify(inputHistoryContent);
3764+
} catch (ex) {
3765+
return Promise.reject(ex);
3766+
}
3767+
3768+
return this._request('editStory', opts);
3769+
}
3770+
3771+
3772+
/**
3773+
* This method deletes a story previously posted by the bot on behalf of a managed business account.
3774+
*
3775+
* Requires the **can_manage_stories** business bot right.
3776+
*
3777+
* @param {String} businessConnectionId Unique identifier of the business connection.
3778+
* @param {Number} storyId Unique identifier of the story to delete.
3779+
* @param {Object} [options] Additional Telegram query options.
3780+
* @return {Promise} On success, returns True.
3781+
* @see https://core.telegram.org/bots/api#deletestory
3782+
*/
3783+
deleteStory(businessConnectionId, storyId, form = {}) {
3784+
form.business_connection_id = businessConnectionId;
3785+
form.story_id = storyId;
3786+
return this._request('deleteStory', { form });
3787+
}
3788+
36623789
}
36633790

36643791
module.exports = TelegramBot;

0 commit comments

Comments
 (0)