From a104c42e9181e991c054fe3890878948bd6683be Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Tue, 28 May 2024 15:01:57 +0200 Subject: [PATCH] feat: support Bot API 7.4 (#590) --- README.md | 2 +- package.json | 2 +- src/context.ts | 20 ++++++++++++++++---- src/convenience/keyboard.ts | 4 ++-- src/core/api.ts | 24 ++++++++++++++++++++---- src/filter.ts | 3 +++ src/types.deno.ts | 4 ++-- src/types.web.ts | 4 ++-- 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index bdc54e84..c54cbbdc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ -[![Bot API](https://img.shields.io/badge/Bot%20API-7.3-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-7.4-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api) [![Deno](https://shield.deno.dev/x/grammy)](https://deno.land/x/grammy) [![npm](https://img.shields.io/npm/v/grammy?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/grammy) [![All Contributors](https://img.shields.io/github/all-contributors/grammyjs/grammy?style=flat&labelColor=000&color=3b82f6)](#contributors-) diff --git a/package.json b/package.json index d2cc4458..d598c53b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "backport": "deno2node tsconfig.json" }, "dependencies": { - "@grammyjs/types": "3.7.0", + "@grammyjs/types": "3.8.0", "abort-controller": "^3.0.0", "debug": "^4.3.4", "node-fetch": "^2.7.0" diff --git a/src/context.ts b/src/context.ts index d1595f76..23aef917 100644 --- a/src/context.ts +++ b/src/context.ts @@ -2641,7 +2641,6 @@ export class Context implements RenamedUpdate { * @param title Product name, 1-32 characters * @param description Product description, 1-255 characters * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. - * @param provider_token Payment provider token, obtained via @BotFather * @param currency Three-letter ISO 4217 currency code, see more on currencies * @param prices Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) * @param other Optional remaining parameters, confer the official reference below @@ -2653,7 +2652,6 @@ export class Context implements RenamedUpdate { title: string, description: string, payload: string, - provider_token: string, currency: string, prices: readonly LabeledPrice[], other?: Other< @@ -2662,7 +2660,6 @@ export class Context implements RenamedUpdate { | "title" | "description" | "payload" - | "provider_token" | "currency" | "prices" >, @@ -2673,7 +2670,6 @@ export class Context implements RenamedUpdate { title, description, payload, - provider_token, currency, prices, other, @@ -2728,6 +2724,22 @@ export class Context implements RenamedUpdate { ); } + /** + * Context-aware alias for `api.refundStarPayment`. Refunds a successful payment in Telegram Stars. + * + * @param signal Optional `AbortSignal` to cancel the request + * + * **Official reference:** https://core.telegram.org/bots/api#refundstarpayment + */ + refundStarPayment(signal?: AbortSignal) { + return this.api.refundStarPayment( + orThrow(this.from, "refundStarPayment").id, + orThrow(this.msg?.successful_payment, "refundStarPayment") + .telegram_payment_charge_id, + signal, + ); + } + /** * Context-aware alias for `api.setPassportDataErrors`. Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success. * diff --git a/src/convenience/keyboard.ts b/src/convenience/keyboard.ts index a69c2e05..78755fbd 100644 --- a/src/convenience/keyboard.ts +++ b/src/convenience/keyboard.ts @@ -818,7 +818,7 @@ export class InlineKeyboard { * This type of button must always be the first button in the first row and * can only be used in invoice messages. * - * @param text The text to display + * @param text The text to display. Substrings “⭐” and “XTR” in the buttons's text will be replaced with a Telegram Star icon. */ pay(text: string) { return this.add(InlineKeyboard.pay(text)); @@ -830,7 +830,7 @@ export class InlineKeyboard { * This type of button must always be the first button in the first row and * can only be used in invoice messages. * - * @param text The text to display + * @param text The text to display. Substrings “⭐” and “XTR” in the buttons's text will be replaced with a Telegram Star icon. */ static pay(text: string): InlineKeyboardButton.PayButton { return { text, pay: true }; diff --git a/src/core/api.ts b/src/core/api.ts index c682f9fe..ef484bf7 100644 --- a/src/core/api.ts +++ b/src/core/api.ts @@ -2412,7 +2412,6 @@ export class Api { * @param title Product name, 1-32 characters * @param description Product description, 1-255 characters * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. - * @param provider_token Payment provider token, obtained via @BotFather * @param currency Three-letter ISO 4217 currency code, see more on currencies * @param prices Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) * @param other Optional remaining parameters, confer the official reference below @@ -2425,7 +2424,6 @@ export class Api { title: string, description: string, payload: string, - provider_token: string, currency: string, prices: readonly LabeledPrice[], other?: Other< @@ -2435,7 +2433,6 @@ export class Api { | "title" | "description" | "payload" - | "provider_token" | "currency" | "prices" >, @@ -2446,7 +2443,6 @@ export class Api { title, description, payload, - provider_token, currency, prices, ...other, @@ -2545,6 +2541,26 @@ export class Api { ); } + /** + * Refunds a successful payment in Telegram Stars. + * + * @param user_id Identifier of the user whose payment will be refunded + * @param telegram_payment_charge_id Telegram payment identifier + * @param signal Optional `AbortSignal` to cancel the request + * + * **Official reference:** https://core.telegram.org/bots/api#refundstarpayment + */ + refundStarPayment( + user_id: number, + telegram_payment_charge_id: string, + signal?: AbortSignal, + ) { + return this.raw.refundStarPayment( + { user_id, telegram_payment_charge_id }, + signal, + ); + } + /** * Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success. * diff --git a/src/filter.ts b/src/filter.ts index bf098fe6..371225fe 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -228,6 +228,8 @@ const ENTITY_KEYS = { underline: {}, strikethrough: {}, spoiler: {}, + blockquote: {}, + expandable_blockquote: {}, code: {}, pre: {}, text_link: {}, @@ -284,6 +286,7 @@ const COMMON_MESSAGE_KEYS = { caption_entities: ENTITY_KEYS, caption: {}, + effect_id: {}, has_media_spoiler: {}, new_chat_title: {}, diff --git a/src/types.deno.ts b/src/types.deno.ts index 9f64baff..181ad6b1 100644 --- a/src/types.deno.ts +++ b/src/types.deno.ts @@ -11,13 +11,13 @@ import { type InputMediaVideo as InputMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, -} from "https://deno.land/x/grammy_types@v3.7.0/mod.ts"; +} from "https://deno.land/x/grammy_types@v3.8.0/mod.ts"; import { debug as d, isDeno } from "./platform.deno.ts"; const debug = d("grammy:warn"); // === Export all API types -export * from "https://deno.land/x/grammy_types@v3.7.0/mod.ts"; +export * from "https://deno.land/x/grammy_types@v3.8.0/mod.ts"; /** A value, or a potentially async function supplying that value */ type MaybeSupplier = T | (() => T | Promise); diff --git a/src/types.web.ts b/src/types.web.ts index d54c0315..ee02271e 100644 --- a/src/types.web.ts +++ b/src/types.web.ts @@ -10,10 +10,10 @@ import { type InputMediaVideo as InputMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, -} from "https://deno.land/x/grammy_types@v3.7.0/mod.ts"; +} from "https://deno.land/x/grammy_types@v3.8.0/mod.ts"; // === Export all API types -export * from "https://deno.land/x/grammy_types@v3.7.0/mod.ts"; +export * from "https://deno.land/x/grammy_types@v3.8.0/mod.ts"; /** Something that looks like a URL. */ interface URLLike {