Skip to content

Commit

Permalink
feat: support Bot API 7.4 (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf authored May 28, 2024
1 parent 883ff3d commit a104c42
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<!-- deno-fmt-ignore-start -->

[![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-)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 16 additions & 4 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<
Expand All @@ -2662,7 +2660,6 @@ export class Context implements RenamedUpdate {
| "title"
| "description"
| "payload"
| "provider_token"
| "currency"
| "prices"
>,
Expand All @@ -2673,7 +2670,6 @@ export class Context implements RenamedUpdate {
title,
description,
payload,
provider_token,
currency,
prices,
other,
Expand Down Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/convenience/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 };
Expand Down
24 changes: 20 additions & 4 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,6 @@ export class Api<R extends RawApi = RawApi> {
* @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
Expand All @@ -2425,7 +2424,6 @@ export class Api<R extends RawApi = RawApi> {
title: string,
description: string,
payload: string,
provider_token: string,
currency: string,
prices: readonly LabeledPrice[],
other?: Other<
Expand All @@ -2435,7 +2433,6 @@ export class Api<R extends RawApi = RawApi> {
| "title"
| "description"
| "payload"
| "provider_token"
| "currency"
| "prices"
>,
Expand All @@ -2446,7 +2443,6 @@ export class Api<R extends RawApi = RawApi> {
title,
description,
payload,
provider_token,
currency,
prices,
...other,
Expand Down Expand Up @@ -2545,6 +2541,26 @@ export class Api<R extends RawApi = RawApi> {
);
}

/**
* 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.
*
Expand Down
3 changes: 3 additions & 0 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ const ENTITY_KEYS = {
underline: {},
strikethrough: {},
spoiler: {},
blockquote: {},
expandable_blockquote: {},
code: {},
pre: {},
text_link: {},
Expand Down Expand Up @@ -284,6 +286,7 @@ const COMMON_MESSAGE_KEYS = {
caption_entities: ENTITY_KEYS,
caption: {},

effect_id: {},
has_media_spoiler: {},

new_chat_title: {},
Expand Down
4 changes: 2 additions & 2 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 | (() => T | Promise<T>);
Expand Down
4 changes: 2 additions & 2 deletions src/types.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a104c42

Please sign in to comment.