Skip to content

Commit 37a8816

Browse files
committed
Update Bot API to 9.0.
Implement new types and methods for API 9.0
1 parent 0f50b4a commit 37a8816

36 files changed

+1263
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![npm](https://img.shields.io/npm/dt/typescript-telegram-bot-api)](https://www.npmjs.com/package/typescript-telegram-bot-api)
55
[![codecov](https://codecov.io/github/Borodin/typescript-telegram-bot-api/graph/badge.svg?token=509N5AZDTV)](https://codecov.io/github/Borodin/typescript-telegram-bot-api)
66
[![codesandbox](https://img.shields.io/badge/Open_in-sandbox-eaff96)](https://codesandbox.io/p/sandbox/interesting-wave-qgspfs)
7-
[![GitHub](https://img.shields.io/badge/Bot_API-v8.3-0088cc)](https://core.telegram.org/bots/api#february-12-2025)
7+
[![GitHub](https://img.shields.io/badge/Bot_API-v9.0-0088cc)](https://core.telegram.org/bots/api#april-11-2025)
88

99

1010
This is a TypeScript wrapper for the [Telegram Bot API](https://core.telegram.org/bots/api) Node.js and browsers. It allows you to easily interact with the Telegram Bot API using TypeScript.
@@ -76,15 +76,15 @@ await bot.sendPhoto({
7676
caption: 'stream',
7777
});
7878

79-
// or
79+
// or
8080

8181
await bot.sendPhoto({
8282
chat_id: chat_id,
8383
photo: await readFile('photo.jpg'),
8484
caption: 'buffer',
8585
});
8686

87-
// or
87+
// or
8888

8989
await bot.sendPhoto({
9090
chat_id: chat_id,

src/index.ts

Lines changed: 334 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
InputMediaPhoto,
2727
InputMediaVideo,
2828
InputPollOption,
29+
InputProfilePhoto,
2930
UserProfilePhotos,
3031
ChatPermissions,
3132
ChatInviteLink,
@@ -65,6 +66,12 @@ import {
6566
WebhookInfo,
6667
Currencies,
6768
Gifts,
69+
AcceptedGiftTypes,
70+
StarAmount,
71+
OwnedGifts,
72+
InputStoryContent,
73+
Story,
74+
StoryArea,
6875
} from './types/';
6976
import * as TelegramTypes from './types/';
7077
import { ExactlyOne } from './utils';
@@ -2663,6 +2670,333 @@ export class TelegramBot extends EventEmitter {
26632670
return await this.callApi('removeChatVerification', options);
26642671
}
26652672

2673+
/**
2674+
* ## readBusinessMessage
2675+
* Marks incoming message as read on behalf of a business account. Requires
2676+
* the can_read_messages business bot right.
2677+
* Returns True on success.
2678+
* @see https://core.telegram.org/bots/api#readbusinessmessage
2679+
* @returns {true}
2680+
*/
2681+
async readBusinessMessage(options: {
2682+
business_connection_id: string;
2683+
chat_id: number | string;
2684+
message_id: number;
2685+
}): Promise<true> {
2686+
return await this.callApi('readBusinessMessage', options);
2687+
}
2688+
2689+
/**
2690+
* ## deleteBusinessMessages
2691+
* Delete messages on behalf of a business account. Requires
2692+
* the can_delete_sent_messages business bot right to delete messages sent by
2693+
* the bot itself, or the can_delete_all_messages business bot right to delete
2694+
* any message. Returns True on success.
2695+
* @see https://core.telegram.org/bots/api#deletebusinessmessages
2696+
* @returns {true}
2697+
*/
2698+
async deleteBusinessMessages(options: {
2699+
business_connection_id: string;
2700+
message_ids: number[];
2701+
}): Promise<true> {
2702+
return await this.callApi('deleteBusinessMessages', options);
2703+
}
2704+
2705+
/**
2706+
* ## setBusinessAccountName
2707+
* Changes the first and last name of a managed business account. Requires the
2708+
* can_change_name business bot right.
2709+
* Returns True on success.
2710+
* @see https://core.telegram.org/bots/api#setbusinessaccountname
2711+
* @returns {true}
2712+
*/
2713+
async setBusinessAccountName(options: {
2714+
business_connection_id: string;
2715+
first_name: string;
2716+
last_name?: string;
2717+
}): Promise<true> {
2718+
return await this.callApi('setBusinessAccountName', options);
2719+
}
2720+
2721+
/**
2722+
* ## setBusinessAccountUsername
2723+
* Changes the username of a managed business account. Requires the
2724+
* can_change_username business bot right.
2725+
* Returns True on success.
2726+
* @see https://core.telegram.org/bots/api#setbusinessaccountusername
2727+
* @returns {true}
2728+
*/
2729+
async setBusinessAccountUsername(options: {
2730+
business_connection_id: string;
2731+
username: string;
2732+
}): Promise<true> {
2733+
return await this.callApi('setBusinessAccountUsername', options);
2734+
}
2735+
2736+
/**
2737+
* ## setBusinessAccountBio
2738+
* Changes the bio of a managed business account. Requires the
2739+
* can_change_bio business bot right.
2740+
* Returns True on success.
2741+
* @see https://core.telegram.org/bots/api#setbusinessaccountbio
2742+
* @returns {true}
2743+
*/
2744+
async setBusinessAccountBio(options: {
2745+
business_connection_id: string;
2746+
bio: string;
2747+
}): Promise<true> {
2748+
return await this.callApi('setBusinessAccountBio', options);
2749+
}
2750+
2751+
/**
2752+
* ## setBusinessAccountProfilePhoto
2753+
* Changes the profile photo of a managed business account. Requires the
2754+
* can_edit_profile_photo business bot right.
2755+
* Returns True on success.
2756+
* @see https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
2757+
* @returns {true}
2758+
*/
2759+
async setBusinessAccountProfilePhoto(options: {
2760+
business_connection_id: string;
2761+
photo: InputProfilePhoto;
2762+
is_public?: boolean;
2763+
}): Promise<true> {
2764+
return await this.callApi('setBusinessAccountProfilePhoto', {
2765+
...options,
2766+
photo: new JSONSerialized(options.photo),
2767+
});
2768+
}
2769+
2770+
/**
2771+
* ## removeBusinessAccountProfilePhoto
2772+
* Removes the current profile photo of a managed business account.
2773+
* Requires the can_edit_profile_photo business bot right.
2774+
* Returns True on success.
2775+
* @see https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
2776+
* @returns {true}
2777+
*/
2778+
async removeBusinessAccountProfilePhoto(options: {
2779+
business_connection_id: string;
2780+
is_public?: boolean;
2781+
}): Promise<true> {
2782+
return await this.callApi('removeBusinessAccountProfilePhoto', options);
2783+
}
2784+
2785+
/**
2786+
* ## setBusinessAccountGiftSettings
2787+
* Changes the privacy settings pertaining to incoming gifts in a managed
2788+
* business account. Requires the can_change_gift_settings business bot right.
2789+
* Returns True on success.
2790+
* @see https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
2791+
* @returns {true}
2792+
*/
2793+
async setBusinessAccountGiftSettings(options: {
2794+
business_connection_id: string;
2795+
show_gift_button: boolean;
2796+
accepted_gift_types: AcceptedGiftTypes;
2797+
}): Promise<true> {
2798+
return await this.callApi('setBusinessAccountGiftSettings', {
2799+
...options,
2800+
accepted_gift_types: new JSONSerialized(options.accepted_gift_types),
2801+
});
2802+
}
2803+
2804+
/**
2805+
* ## getBusinessAccountStarBalance
2806+
* Returns the amount of Telegram Stars owned by a managed business account.
2807+
* Requires the can_view_gifts_and_stars business bot right.
2808+
* Returns StarAmount on success.
2809+
* @see https://core.telegram.org/bots/api#getbusinessaccountstarbalance
2810+
* @returns {StarAmount}
2811+
*/
2812+
async getBusinessAccountStarBalance(options: {
2813+
business_connection_id: string;
2814+
}): Promise<StarAmount> {
2815+
return await this.callApi('getBusinessAccountStarBalance', options);
2816+
}
2817+
2818+
/**
2819+
* ## transferBusinessAccountStars
2820+
* Transfers Telegram Stars from the business account balance to the bot's
2821+
* balance. Requires the can_transfer_stars business bot right.
2822+
* Returns True on success.
2823+
* @see https://core.telegram.org/bots/api#transferbusinessaccountstars
2824+
* @returns {true}
2825+
*/
2826+
async transferBusinessAccountStars(options: {
2827+
business_connection_id: string;
2828+
star_count: number;
2829+
}): Promise<true> {
2830+
return await this.callApi('transferBusinessAccountStars', options);
2831+
}
2832+
2833+
/**
2834+
* ## getBusinessAccountGifts
2835+
* Returns the gifts received and owned by a managed business account.
2836+
* Requires the can_view_gifts_and_stars business bot right.
2837+
* Returns OwnedGifts on success.
2838+
* @see https://core.telegram.org/bots/api#getbusinessaccountgifts
2839+
* @returns {OwnedGifts}
2840+
*/
2841+
async getBusinessAccountGifts(options: {
2842+
business_connection_id: string;
2843+
exclude_unsaved?: boolean;
2844+
exclude_saved?: boolean;
2845+
exclude_unlimited?: boolean;
2846+
exclude_limited?: boolean;
2847+
exclude_unique?: boolean;
2848+
sort_by_price?: boolean;
2849+
offset?: string;
2850+
limit?: number;
2851+
}): Promise<OwnedGifts> {
2852+
return await this.callApi('getBusinessAccountGifts', {
2853+
...options,
2854+
});
2855+
}
2856+
2857+
/**
2858+
* ## convertGiftToStars
2859+
* Converts a given regular gift to Telegram Stars. Requires the
2860+
* can_convert_gifts_to_stars business bot right.
2861+
* Returns True on success.
2862+
* @see https://core.telegram.org/bots/api#convertgifttostars
2863+
* @returns {true}
2864+
*/
2865+
async convertGiftToStars(options: {
2866+
business_connection_id: string;
2867+
owned_gift_id: string;
2868+
}): Promise<true> {
2869+
return await this.callApi('convertGiftToStars', options);
2870+
}
2871+
2872+
/**
2873+
* ## upgradeGift
2874+
* Upgrades a given regular gift to a unique gift. Requires the
2875+
* can_transfer_and_upgrade_gifts business bot right. Additionally requires
2876+
* the can_transfer_stars business bot right if the upgrade is paid.
2877+
* Returns True on success.
2878+
* @see https://core.telegram.org/bots/api#upgradegift
2879+
* @returns {true}
2880+
*/
2881+
async upgradeGift(options: {
2882+
business_connection_id: string;
2883+
owned_gift_id: string;
2884+
keep_original_details?: boolean;
2885+
star_count?: number;
2886+
}): Promise<true> {
2887+
return await this.callApi('upgradeGift', {
2888+
...options,
2889+
});
2890+
}
2891+
2892+
/**
2893+
* ## transferGift
2894+
* Transfers an owned unique gift to another user. Requires the
2895+
* can_transfer_and_upgrade_gifts business bot right. Requires
2896+
* can_transfer_stars business bot right if the transfer is paid.
2897+
* Returns True on success.
2898+
* @see https://core.telegram.org/bots/api#transfertgift
2899+
* @returns {true}
2900+
*/
2901+
async transferGift(options: {
2902+
business_connection_id: string;
2903+
owned_gift_id: string;
2904+
new_owner_chat_id: number;
2905+
star_count?: number;
2906+
}): Promise<true> {
2907+
return await this.callApi('transferGift', {
2908+
...options,
2909+
});
2910+
}
2911+
2912+
/**
2913+
* ## postStory
2914+
* Posts a story on behalf of a managed business account. Requires the
2915+
* can_manage_stories business bot right.
2916+
* Returns Story on success.
2917+
* @see https://core.telegram.org/bots/api#poststory
2918+
* @returns {Story}
2919+
*/
2920+
async postStory(options: {
2921+
business_connection_id: string;
2922+
content: InputStoryContent;
2923+
active_period: number;
2924+
caption?: string;
2925+
parse_mode?: string;
2926+
caption_entities?: MessageEntity[];
2927+
areas?: StoryArea[];
2928+
post_to_chat_page?: boolean;
2929+
protect_content?: boolean;
2930+
}): Promise<Story> {
2931+
return await this.callApi('postStory', {
2932+
...options,
2933+
caption_entities: new JSONSerialized(options.caption_entities),
2934+
content: new JSONSerialized(options.content),
2935+
areas: new JSONSerialized(options.areas),
2936+
});
2937+
}
2938+
2939+
/**
2940+
* ## editStory
2941+
* Edits a story previously posted by the bot on behalf of a managed business
2942+
* account. Requires the can_manage_stories business bot right.
2943+
* Returns Story on success.
2944+
* @see https://core.telegram.org/bots/api#editstory
2945+
* @returns {Story}
2946+
*/
2947+
async editStory(options: {
2948+
business_connection_id: string;
2949+
story_id: string;
2950+
content?: InputStoryContent;
2951+
caption?: string;
2952+
parse_mode?: string;
2953+
caption_entities?: MessageEntity[];
2954+
areas?: StoryArea[];
2955+
}): Promise<Story> {
2956+
return await this.callApi('editStory', {
2957+
...options,
2958+
caption_entities: new JSONSerialized(options.caption_entities),
2959+
content: options.content ? new JSONSerialized(options.content) : undefined,
2960+
areas: options.areas ? new JSONSerialized(options.areas) : undefined,
2961+
});
2962+
}
2963+
2964+
/**
2965+
* ## deleteStory
2966+
* Deletes a story previously posted by the bot on behalf of a managed
2967+
* business account. Requires the can_manage_stories business bot right.
2968+
* Returns True on success.
2969+
* @see https://core.telegram.org/bots/api#deletestory
2970+
* @returns {true}
2971+
*/
2972+
async deleteStory(options: {
2973+
business_connection_id: string;
2974+
story_id: string;
2975+
}): Promise<true> {
2976+
return await this.callApi('deleteStory', options);
2977+
}
2978+
2979+
/**
2980+
* ## giftPremiumSubscription
2981+
* Gifts a Telegram Premium subscription to the given user.
2982+
* Returns True on success.
2983+
* @see https://core.telegram.org/bots/api#giftpremiumsubscription
2984+
* @returns {true}
2985+
*/
2986+
async giftPremiumSubscription(options: {
2987+
user_id: number;
2988+
month_count: number;
2989+
star_count: number;
2990+
text?: string;
2991+
text_parse_mode?: string;
2992+
text_entities?: MessageEntity[];
2993+
}): Promise<true> {
2994+
return await this.callApi('giftPremiumSubscription', {
2995+
...options,
2996+
text_entities: new JSONSerialized(options.text_entities),
2997+
});
2998+
}
2999+
26663000
on<U extends keyof allEmittedTypes>(event: U, listener: (eventData: NonNullable<allEmittedTypes[U]>) => void): this {
26673001
return super.on(event, listener) as this;
26683002
}

0 commit comments

Comments
 (0)