Skip to content

Commit 1f7e826

Browse files
committed
update Bot API to 8.0
1 parent 7ceef73 commit 1f7e826

File tree

9 files changed

+177
-3
lines changed

9 files changed

+177
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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-v7.11-0088cc)](https://core.telegram.org/bots/api#october-31-2024)
7+
[![GitHub](https://img.shields.io/badge/Bot_API-v8.0-0088cc)](https://core.telegram.org/bots/api#november-17-2024)
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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "commonjs",
33
"name": "typescript-telegram-bot-api",
4-
"version": "0.4.1",
4+
"version": "0.5.0",
55
"description": "Telegram Bot API wrapper for Node.js written in TypeScript",
66
"repository": "github:Borodin/typescript-telegram-bot-api",
77
"main": "dist/index.js",

src/index.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
InputPaidMedia,
6565
WebhookInfo,
6666
Currencies,
67+
Gifts,
6768
} from './types/';
6869
import * as TelegramTypes from './types/';
6970

@@ -1157,6 +1158,20 @@ export class TelegramBot extends EventEmitter {
11571158
return await this.callApi('getUserProfilePhotos', options);
11581159
}
11591160

1161+
/**
1162+
* ## setUserEmojiStatus
1163+
* Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the
1164+
* Mini App method requestEmojiStatusAccess. Returns True on success.
1165+
* @see https://core.telegram.org/bots/api#setuseremojistatus
1166+
*/
1167+
async setUserEmojiStatus(options: {
1168+
user_id: number;
1169+
emoji_status_custom_emoji_id?: string;
1170+
emoji_status_expiration_date?: number;
1171+
}): Promise<boolean> {
1172+
return await this.callApi('setUserEmojiStatus', options);
1173+
}
1174+
11601175
/**
11611176
* ## getFile
11621177
* Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can
@@ -2388,12 +2403,14 @@ export class TelegramBot extends EventEmitter {
23882403
* @see https://core.telegram.org/bots/api#createinvoicelink
23892404
*/
23902405
async createInvoiceLink<T extends Currencies | 'XTR'>(options: {
2406+
business_connection_id?: string;
23912407
title: string;
23922408
description: string;
23932409
payload: string;
23942410
provider_token?: string;
23952411
currency: T;
23962412
prices: T extends 'XTR' ? [LabeledPrice] : LabeledPrice[];
2413+
subscription_period?: T extends 'XTR' ? number : never;
23972414
max_tip_amount?: T extends 'XTR' ? never : number;
23982415
suggested_tip_amounts?: number[];
23992416
provider_data?: string;
@@ -2476,6 +2493,19 @@ export class TelegramBot extends EventEmitter {
24762493
return await this.callApi('refundStarPayment', options);
24772494
}
24782495

2496+
/**
2497+
* ## editUserStarSubscription
2498+
* Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. Returns True on success.
2499+
* @see https://core.telegram.org/bots/api#edituserstarsubscription
2500+
*/
2501+
async editUserStarSubscription(options: {
2502+
user_id: number;
2503+
telegram_payment_charge_id: string;
2504+
is_canceled: boolean;
2505+
}): Promise<true> {
2506+
return await this.callApi('editUserStarSubscription', options);
2507+
}
2508+
24792509
/**
24802510
* ## setPassportDataErrors
24812511
* Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able
@@ -2557,6 +2587,33 @@ export class TelegramBot extends EventEmitter {
25572587
return await this.callApi('getGameHighScores', options);
25582588
}
25592589

2590+
/**
2591+
* ## getAvailableGifts
2592+
* Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
2593+
* @see https://core.telegram.org/bots/api#getavailablegifts
2594+
*/
2595+
async getAvailableGifts(): Promise<Gifts> {
2596+
return await this.callApi('getAvailableGifts');
2597+
}
2598+
2599+
/**
2600+
* ## sendGift
2601+
* Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success.
2602+
* @see https://core.telegram.org/bots/api#sendgift
2603+
*/
2604+
async sendGift(options: {
2605+
user_id: number;
2606+
gift_id: string;
2607+
text?: string;
2608+
text_parse_mode?: ParseMode;
2609+
text_entities?: MessageEntity[];
2610+
}): Promise<true> {
2611+
return await this.callApi('sendGift', {
2612+
...options,
2613+
text_entities: new JSONSerialized(options.text_entities),
2614+
});
2615+
}
2616+
25602617
on<U extends keyof allEmittedTypes>(event: U, listener: (eventData: NonNullable<allEmittedTypes[U]>) => void): this {
25612618
return super.on(event, listener) as this;
25622619
}

src/types/Gift.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Sticker } from './';
2+
3+
/**
4+
* ## Gift
5+
* This object represents a gift that can be sent by the bot.
6+
* @see https://core.telegram.org/bots/api#gift
7+
*/
8+
export type Gift = {
9+
/**
10+
* Unique identifier of the gift
11+
*/
12+
id: string;
13+
14+
/**
15+
* The sticker that represents the gift
16+
*/
17+
sticker: Sticker;
18+
19+
/**
20+
* The number of Telegram Stars that must be paid to send the sticker
21+
*/
22+
star_count: number;
23+
24+
/**
25+
* Optional. The total number of the gifts of this type that can be sent; for limited gifts only
26+
*/
27+
total_count?: number;
28+
29+
/**
30+
* Optional. The number of remaining gifts of this type that can be sent; for limited gifts only
31+
*/
32+
remaining_count?: number;
33+
};

src/types/Gifts.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Gift } from './';
2+
3+
/**
4+
* ## Gifts
5+
* This object represent a list of gifts.
6+
* @see https://core.telegram.org/bots/api#gifts
7+
*/
8+
export type Gifts = {
9+
/**
10+
* The list of gifts
11+
*/
12+
gifts: Gift[];
13+
};

src/types/SuccessfulPayment.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ export type SuccessfulPayment = {
2323
*/
2424
invoice_payload: string;
2525

26+
/**
27+
* Optional. Expiration date of the subscription, in Unix time; for recurring payments only
28+
*/
29+
subscription_expiration_date?: number;
30+
31+
/**
32+
* Optional. True, if the payment is a recurring payment for a subscription
33+
*/
34+
is_recurring?: boolean;
35+
36+
/**
37+
* Optional. True, if the payment is the first payment for a subscription
38+
*/
39+
is_first_recurring?: boolean;
40+
2641
/**
2742
* Optional. Identifier of the shipping option chosen by the user
2843
*/

src/types/TransactionPartnerUser.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { User } from './User';
22
import { PaidMedia } from './PaidMedia';
3+
import { Gift } from './Gift';
34

45
/**
56
* ## TransactionPartnerUser
@@ -22,6 +23,11 @@ export type TransactionPartnerUser = {
2223
*/
2324
invoice_payload: string;
2425

26+
/**
27+
* Optional. The duration of the paid subscription
28+
*/
29+
subscription_period?: number;
30+
2531
/**
2632
* Optional. Information about the paid media bought by the user
2733
*/
@@ -31,4 +37,9 @@ export type TransactionPartnerUser = {
3137
* Optional. Bot-specified paid media payload
3238
*/
3339
paid_media_payload: string;
40+
41+
/**
42+
* Optional. The gift sent to the user by the bot
43+
*/
44+
gift?: Gift;
3445
};

src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export * from './Game';
7575
export * from './GameHighScore';
7676
export * from './GeneralForumTopicHidden';
7777
export * from './GeneralForumTopicUnhidden';
78+
export * from './Gift';
79+
export * from './Gifts';
7880
export * from './Giveaway';
7981
export * from './GiveawayCompleted';
8082
export * from './GiveawayCreated';

tests/index.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,17 @@ describe('.getUserProfilePhotos()', () => {
727727
});
728728
});
729729

730+
describe('.setUserEmojiStatus()', () => {
731+
test('should set user emoji status', async () => {
732+
await expect(
733+
bot.setUserEmojiStatus({
734+
user_id: USERID,
735+
emoji_status_custom_emoji_id: '',
736+
}),
737+
).rejects.toThrow("403 Forbidden: not enough rights to change the user's emoji status");
738+
});
739+
});
740+
730741
describe('.getFile()', () => {
731742
test('should get file', async () => {
732743
await expect(
@@ -1951,7 +1962,19 @@ describe('.refundStarPayment()', () => {
19511962
user_id: USERID,
19521963
telegram_payment_charge_id: 'PAYMENT_ID',
19531964
}),
1954-
).rejects.toThrow('400 Bad Request: CHARGE_NOT_FOUND');
1965+
).rejects.toThrow('400 Bad Request: CHARGE_ID_EMPTY');
1966+
});
1967+
});
1968+
1969+
describe('.editUserStarSubscription()', () => {
1970+
test('should edit user star subscription', async () => {
1971+
await expect(
1972+
bot.editUserStarSubscription({
1973+
user_id: USERID,
1974+
telegram_payment_charge_id: 'CHARGE_ID',
1975+
is_canceled: true,
1976+
}),
1977+
).rejects.toThrow('400 Bad Request: CHARGE_ID_INVALID');
19551978
});
19561979
});
19571980

@@ -2387,3 +2410,23 @@ describe('.setPassportDataErrors()', () => {
23872410
).rejects.toThrow('400 Bad Request: DATA_HASH_SIZE_INVALID');
23882411
});
23892412
});
2413+
2414+
describe('.getAvailableGifts()', () => {
2415+
test('should get available gifts', async () => {
2416+
await expect(bot.getAvailableGifts()).resolves.toHaveProperty('gifts');
2417+
});
2418+
});
2419+
2420+
describe('.sendGift()', () => {
2421+
test('should send gift', async () => {
2422+
const gifts = (await bot.getAvailableGifts()).gifts;
2423+
2424+
await expect(
2425+
bot.sendGift({
2426+
user_id: USERID,
2427+
gift_id: gifts[0].id,
2428+
text: 'text',
2429+
}),
2430+
).rejects.toThrow('400 Bad Request: BALANCE_TOO_LOW');
2431+
});
2432+
});

0 commit comments

Comments
 (0)