Skip to content

Commit

Permalink
feat: support Bot API 7.6 (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf authored Jul 1, 2024
1 parent b06c962 commit 9577dfc
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 10 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.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-)
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.9.0",
"@grammyjs/types": "3.10.0",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.7.0"
Expand Down
30 changes: 28 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type InputMediaDocument,
type InputMediaPhoto,
type InputMediaVideo,
type InputPaidMedia,
type InputPollOption,
type LabeledPrice,
type Message,
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
29 changes: 27 additions & 2 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type InputMediaDocument,
type InputMediaPhoto,
type InputMediaVideo,
type InputPaidMedia,
type InputPollOption,
type InputSticker,
type LabeledPrice,
Expand Down Expand Up @@ -293,7 +294,7 @@ export class Api<R extends RawApi = RawApi> {
}

/**
* 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)
Expand Down Expand Up @@ -321,7 +322,7 @@ export class Api<R extends RawApi = RawApi> {
}

/**
* 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)
Expand Down Expand Up @@ -653,6 +654,30 @@ export class Api<R extends RawApi = RawApi> {
);
}

/**
* 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<R, "sendPaidMedia", "chat_id" | "star_count" | "media">,
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.
*
Expand Down
1 change: 1 addition & 0 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ const COMMON_MESSAGE_KEYS = {
poll: {},
venue: {},
location: {},
paid_media: {},

entities: ENTITY_KEYS,
caption_entities: ENTITY_KEYS,
Expand Down
15 changes: 13 additions & 2 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 | (() => T | Promise<T>);
Expand Down Expand Up @@ -179,3 +182,11 @@ export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
export type InputMediaAudio = InputMediaAudioF<InputFile>;
/** Represents a general file to be sent. */
export type InputMediaDocument = InputMediaDocumentF<InputFile>;
/** This object describes the paid media to be sent. Currently, it can be one of
- InputPaidMediaPhoto
- InputPaidMediaVideo */
export type InputPaidMedia = InputPaidMediaF<InputFile>;
/** The paid media to send is a photo. */
export type InputPaidMediaPhoto = InputPaidMediaPhotoF<InputFile>;
/** The paid media to send is a video. */
export type InputPaidMediaVideo = InputPaidMediaVideoF<InputFile>;
11 changes: 11 additions & 0 deletions src/types.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -165,3 +168,11 @@ export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
export type InputMediaAudio = InputMediaAudioF<InputFile>;
/** Represents a general file to be sent. */
export type InputMediaDocument = InputMediaDocumentF<InputFile>;
/** This object describes the paid media to be sent. Currently, it can be one of
- InputPaidMediaPhoto
- InputPaidMediaVideo */
export type InputPaidMedia = InputPaidMediaF<InputFile>;
/** The paid media to send is a photo. */
export type InputPaidMediaPhoto = InputPaidMediaPhotoF<InputFile>;
/** The paid media to send is a video. */
export type InputPaidMediaVideo = InputPaidMediaVideoF<InputFile>;
15 changes: 13 additions & 2 deletions src/types.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -131,3 +134,11 @@ export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
export type InputMediaAudio = InputMediaAudioF<InputFile>;
/** Represents a general file to be sent. */
export type InputMediaDocument = InputMediaDocumentF<InputFile>;
/** This object describes the paid media to be sent. Currently, it can be one of
- InputPaidMediaPhoto
- InputPaidMediaVideo */
export type InputPaidMedia = InputPaidMediaF<InputFile>;
/** The paid media to send is a photo. */
export type InputPaidMediaPhoto = InputPaidMediaPhotoF<InputFile>;
/** The paid media to send is a video. */
export type InputPaidMediaVideo = InputPaidMediaVideoF<InputFile>;

0 comments on commit 9577dfc

Please sign in to comment.