diff --git a/README.md b/README.md index 0a8544f4..216d824d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ -[![Bot API](https://img.shields.io/badge/Bot%20API-7.5-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.6-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 a64eb63a..f1906b74 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "backport": "deno2node tsconfig.json" }, "dependencies": { - "@grammyjs/types": "3.9.0", + "@grammyjs/types": "3.10.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 8d6326d5..f7bd5e73 100644 --- a/src/context.ts +++ b/src/context.ts @@ -17,6 +17,7 @@ import { type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, + type InputPaidMedia, type InputPollOption, type LabeledPrice, type Message, @@ -998,7 +999,7 @@ export class Context implements RenamedUpdate { } /** - * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. + * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param other Optional remaining parameters, confer the official reference below @@ -1021,7 +1022,7 @@ export class Context implements RenamedUpdate { } /** - * Context-aware alias for `api.copyMessages`.Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. + * Context-aware alias for `api.copyMessages`. Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param message_ids A list of 1-100 identifiers of messages in the current chat to copy. The identifiers must be specified in a strictly increasing order. @@ -1324,6 +1325,31 @@ export class Context implements RenamedUpdate { ); } + /** + * Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media to channel chats. On success, the sent Message is returned. + * + * @param star_count The number of Telegram Stars that must be paid to buy access to the media + * @param media An array describing the media to be sent; up to 10 items + * @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#sendpaidmedia + */ + sendPaidMedia( + star_count: number, + media: InputPaidMedia[], + other?: Other<"sendPaidMedia", "chat_id" | "star_count" | "media">, + signal?: AbortSignal, + ) { + return this.api.sendPaidMedia( + orThrow(this.chatId, "sendPaidMedia"), + star_count, + media, + other, + signal, + ); + } + /** * Context-aware alias for `api.sendVenue`. Use this method to send information about a venue. On success, the sent Message is returned. * diff --git a/src/core/api.ts b/src/core/api.ts index cff6c6d5..7e1ede69 100644 --- a/src/core/api.ts +++ b/src/core/api.ts @@ -9,6 +9,7 @@ import { type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, + type InputPaidMedia, type InputPollOption, type InputSticker, type LabeledPrice, @@ -293,7 +294,7 @@ export class Api { } /** - * Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. + * Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) @@ -321,7 +322,7 @@ export class Api { } /** - * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. + * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. * * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param from_chat_id Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) @@ -653,6 +654,30 @@ export class Api { ); } + /** + * Use this method to send paid media to channel chats. On success, the sent Message is returned. + * + * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param star_count The number of Telegram Stars that must be paid to buy access to the media + * @param media An array describing the media to be sent; up to 10 items + * @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#sendpaidmedia + */ + sendPaidMedia( + chat_id: number | string, + star_count: number, + media: InputPaidMedia[], + other?: Other, + signal?: AbortSignal, + ) { + return this.raw.sendPaidMedia( + { chat_id, star_count, media, ...other }, + signal, + ); + } + /** * Use this method to send information about a venue. On success, the sent Message is returned. * diff --git a/src/filter.ts b/src/filter.ts index 2ce60db4..b0aa2f0b 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -281,6 +281,7 @@ const COMMON_MESSAGE_KEYS = { poll: {}, venue: {}, location: {}, + paid_media: {}, entities: ENTITY_KEYS, caption_entities: ENTITY_KEYS, diff --git a/src/types.deno.ts b/src/types.deno.ts index 0f6f3f66..b9352ef3 100644 --- a/src/types.deno.ts +++ b/src/types.deno.ts @@ -9,15 +9,18 @@ import { type InputMediaDocument as InputMediaDocumentF, type InputMediaPhoto as InputMediaPhotoF, type InputMediaVideo as InputMediaVideoF, + type InputPaidMedia as InputPaidMediaF, + type InputPaidMediaPhoto as InputPaidMediaPhotoF, + type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, -} from "https://deno.land/x/grammy_types@v3.9.0/mod.ts"; +} from "https://deno.land/x/grammy_types@v3.10.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.9.0/mod.ts"; +export * from "https://deno.land/x/grammy_types@v3.10.0/mod.ts"; /** A value, or a potentially async function supplying that value */ type MaybeSupplier = T | (() => T | Promise); @@ -179,3 +182,11 @@ export type InputMediaAnimation = InputMediaAnimationF; export type InputMediaAudio = InputMediaAudioF; /** Represents a general file to be sent. */ export type InputMediaDocument = InputMediaDocumentF; +/** This object describes the paid media to be sent. Currently, it can be one of +- InputPaidMediaPhoto +- InputPaidMediaVideo */ +export type InputPaidMedia = InputPaidMediaF; +/** The paid media to send is a photo. */ +export type InputPaidMediaPhoto = InputPaidMediaPhotoF; +/** The paid media to send is a video. */ +export type InputPaidMediaVideo = InputPaidMediaVideoF; diff --git a/src/types.node.ts b/src/types.node.ts index c7bde749..36ae2bea 100644 --- a/src/types.node.ts +++ b/src/types.node.ts @@ -7,6 +7,9 @@ import { type InputMediaDocument as InputMediaDocumentF, type InputMediaPhoto as InputMediaPhotoF, type InputMediaVideo as InputMediaVideoF, + type InputPaidMedia as InputPaidMediaF, + type InputPaidMediaPhoto as InputPaidMediaPhotoF, + type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, } from "@grammyjs/types"; @@ -165,3 +168,11 @@ export type InputMediaAnimation = InputMediaAnimationF; export type InputMediaAudio = InputMediaAudioF; /** Represents a general file to be sent. */ export type InputMediaDocument = InputMediaDocumentF; +/** This object describes the paid media to be sent. Currently, it can be one of +- InputPaidMediaPhoto +- InputPaidMediaVideo */ +export type InputPaidMedia = InputPaidMediaF; +/** The paid media to send is a photo. */ +export type InputPaidMediaPhoto = InputPaidMediaPhotoF; +/** The paid media to send is a video. */ +export type InputPaidMediaVideo = InputPaidMediaVideoF; diff --git a/src/types.web.ts b/src/types.web.ts index 8208c303..2a1f2131 100644 --- a/src/types.web.ts +++ b/src/types.web.ts @@ -8,12 +8,15 @@ import { type InputMediaDocument as InputMediaDocumentF, type InputMediaPhoto as InputMediaPhotoF, type InputMediaVideo as InputMediaVideoF, + type InputPaidMedia as InputPaidMediaF, + type InputPaidMediaPhoto as InputPaidMediaPhotoF, + type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF, -} from "https://deno.land/x/grammy_types@v3.9.0/mod.ts"; +} from "https://deno.land/x/grammy_types@v3.10.0/mod.ts"; // === Export all API types -export * from "https://deno.land/x/grammy_types@v3.9.0/mod.ts"; +export * from "https://deno.land/x/grammy_types@v3.10.0/mod.ts"; /** Something that looks like a URL. */ interface URLLike { @@ -131,3 +134,11 @@ export type InputMediaAnimation = InputMediaAnimationF; export type InputMediaAudio = InputMediaAudioF; /** Represents a general file to be sent. */ export type InputMediaDocument = InputMediaDocumentF; +/** This object describes the paid media to be sent. Currently, it can be one of +- InputPaidMediaPhoto +- InputPaidMediaVideo */ +export type InputPaidMedia = InputPaidMediaF; +/** The paid media to send is a photo. */ +export type InputPaidMediaPhoto = InputPaidMediaPhotoF; +/** The paid media to send is a video. */ +export type InputPaidMediaVideo = InputPaidMediaVideoF;