From 9d2a0c8dd998b4d5085cd50dc0b54448e0921748 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Tue, 28 Jan 2025 22:35:48 +0100 Subject: [PATCH 1/4] feat: support Bot API 8.3 --- src/context.ts | 28 +++++++++++++++++++++++++--- src/core/api.ts | 29 ++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/context.ts b/src/context.ts index fe4c542d..9addb2f4 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1538,7 +1538,7 @@ export class Context implements RenamedUpdate { } /** - * Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success. + * Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages of some types can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success. * * @param reaction A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots. * @param other Optional remaining parameters, confer the official reference below @@ -2822,7 +2822,7 @@ export class Context implements RenamedUpdate { } /** - * Context-aware alias for `api.sendGift`. Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success. + * Context-aware alias for `api.sendGift`. Sends a gift to the given user. The gift can't be converted to Telegram Stars by the receiver. Returns True on success. * * @param gift_id Identifier of the gift * @param other Optional remaining parameters, confer the official reference below @@ -2832,7 +2832,7 @@ export class Context implements RenamedUpdate { */ replyWithGift( gift_id: string, - other?: Other<"sendGift", "user_id" | "gift_id">, + other?: Other<"sendGift", "user_id" | "chat_id" | "gift_id">, signal?: AbortSignal, ) { return this.api.sendGift( @@ -2843,6 +2843,28 @@ export class Context implements RenamedUpdate { ); } + /** + * Context-aware alias for `api.sendGift`. Sends a gift to the given channel chat. The gift can't be converted to Telegram Stars by the receiver. Returns True on success. + * + * @param gift_id Identifier of the gift + * @param other Optional remaining parameters, confer the official reference below + * @param signal Optional `AbortSignal` to cancel the request + * + * **Official reference:** https://core.telegram.org/bots/api#sendgift + */ + replyWithGiftToChannel( + gift_id: string, + other?: Other<"sendGift", "user_id" | "chat_id" | "gift_id">, + signal?: AbortSignal, + ) { + return this.api.sendGift( + orThrow(this.chat, "sendGift").id, + gift_id, + other, + signal, + ); + } + /** * Context-aware alias for `api.answerInlineQuery`. Use this method to send answers to an inline query. On success, True is returned. * No more than 50 results per query are allowed. diff --git a/src/core/api.ts b/src/core/api.ts index 4e3650e8..deca1c1b 100644 --- a/src/core/api.ts +++ b/src/core/api.ts @@ -789,7 +789,7 @@ export class Api { } /** - * Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success. + * Use this method to change the chosen reactions on a message. Service messages of some types can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param message_id Identifier of the target message @@ -2481,7 +2481,7 @@ export class Api { } /** - * Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object. + * Returns the list of gifts that can be sent by the bot to users and channel chats. Requires no parameters. Returns a Gifts object. * * @param signal Optional `AbortSignal` to cancel the request * @@ -2492,9 +2492,9 @@ export class Api { } /** - * Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success. + * Sends a gift to the given user. The gift can't be converted to Telegram Stars by the receiver. Returns True on success. * - * @param user_id Unique identifier of the target user that will receive the gift + * @param user_id Unique identifier of the target user who will receive the gift * @param gift_id Identifier of the gift * @param other Optional remaining parameters, confer the official reference below * @param signal Optional `AbortSignal` to cancel the request @@ -2504,12 +2504,31 @@ export class Api { sendGift( user_id: number, gift_id: string, - other?: Other, + other?: Other, signal?: AbortSignal, ) { return this.raw.sendGift({ user_id, gift_id, ...other }, signal); } + /** + * Sends a gift to the given channel chat. The gift can't be converted to Telegram Stars by the receiver. Returns True on success. + * + * @param chat_id Unique identifier for the chat or username of the channel (in the format @channelusername) that will receive the gift + * @param gift_id Identifier of the gift + * @param other Optional remaining parameters, confer the official reference below + * @param signal Optional `AbortSignal` to cancel the request + * + * **Official reference:** https://core.telegram.org/bots/api#sendgift + */ + sendGiftToChannel( + chat_id: number | string, + gift_id: string, + other?: Other, + signal?: AbortSignal, + ) { + return this.raw.sendGift({ chat_id, gift_id, ...other }, signal); + } + /** * Use this method to send answers to an inline query. On success, True is returned. * No more than 50 results per query are allowed. From e3f07cefc25552bdd1ed4f19dab004bbdea41fa1 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Tue, 28 Jan 2025 22:35:58 +0100 Subject: [PATCH 2/4] docs: mention support for Bot API 8.3 in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dfdaf503..7133d1b9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ -[![Bot API](https://img.shields.io/badge/Bot%20API-8.2-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-8.3-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-) From 2f40b255b15a0521ac7b122033930d6dfccdc481 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Wed, 12 Feb 2025 15:04:55 +0100 Subject: [PATCH 3/4] build: update type dep --- package.json | 2 +- src/types.deno.ts | 4 ++-- src/types.web.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 088c58d6..62466e1f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "backport": "deno2node tsconfig.json" }, "dependencies": { - "@grammyjs/types": "3.18.0", + "@grammyjs/types": "3.19.0", "abort-controller": "^3.0.0", "debug": "^4.3.4", "node-fetch": "^2.7.0" diff --git a/src/types.deno.ts b/src/types.deno.ts index 333f2203..5520a6bc 100644 --- a/src/types.deno.ts +++ b/src/types.deno.ts @@ -14,13 +14,13 @@ import { type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, -} from "https://deno.land/x/grammy_types@v3.18.0/mod.ts"; +} from "https://deno.land/x/grammy_types@v3.19.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.18.0/mod.ts"; +export * from "https://deno.land/x/grammy_types@v3.19.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 edb43e71..3515c319 100644 --- a/src/types.web.ts +++ b/src/types.web.ts @@ -13,10 +13,10 @@ import { type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, -} from "https://deno.land/x/grammy_types@v3.18.0/mod.ts"; +} from "https://deno.land/x/grammy_types@v3.19.0/mod.ts"; // === Export all API types -export * from "https://deno.land/x/grammy_types@v3.18.0/mod.ts"; +export * from "https://deno.land/x/grammy_types@v3.19.0/mod.ts"; /** Something that looks like a URL. */ interface URLLike { From 1c0694bc58e62eba825ab07ee1ede27fa432fbd3 Mon Sep 17 00:00:00 2001 From: KnorpelSenf Date: Wed, 12 Feb 2025 15:16:39 +0100 Subject: [PATCH 4/4] fix: oops --- src/context.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context.ts b/src/context.ts index 9addb2f4..8f341efa 100644 --- a/src/context.ts +++ b/src/context.ts @@ -2857,7 +2857,7 @@ export class Context implements RenamedUpdate { other?: Other<"sendGift", "user_id" | "chat_id" | "gift_id">, signal?: AbortSignal, ) { - return this.api.sendGift( + return this.api.sendGiftToChannel( orThrow(this.chat, "sendGift").id, gift_id, other,