Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Bot API 7.2 #554

Merged
merged 7 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1-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.2-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.5.2",
"@grammyjs/types": "3.6.0",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.7.0"
Expand Down
249 changes: 146 additions & 103 deletions src/context.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/convenience/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ type MultiSessionOptionsRecord<
*
* > **What is a session?** Simply put, the session of a chat is a little
* > persistent storage that is attached to it. As an example, your bot can send
* > a message to a chat and store the ID of that message in the corresponding
* > session. The next time your bot receives an update from that chat, the
* > session will still contain that ID.
* > a message to a chat and store the identifier of that message in the
* > corresponding session. The next time your bot receives an update from that
* > chat, the session will still contain that ID.
* >
* > Session data can be stored in a database, in a file, or simply in memory.
* > grammY only supports memory sessions out of the box, but you can use
Expand Down
60 changes: 49 additions & 11 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
*
* @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)
* @param message_ids Identifiers of 1-100 messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order.
* @param message_ids A list of 1-100 identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order.
* @param other Optional remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
Expand Down Expand Up @@ -315,7 +315,7 @@
*
* @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)
* @param message_ids Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.
* @param message_ids A list of 1-100 identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.
* @param other Optional remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
Expand Down Expand Up @@ -751,7 +751,7 @@
*
* @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
* @param reaction New 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.
* @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.
* @param other Optional remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
Expand Down Expand Up @@ -844,6 +844,22 @@
return this.raw.getUserChatBoosts({ chat_id, user_id }, signal);
}

/**

Check warning on line 847 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L847

Added line #L847 was not covered by tests
* Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.
*
* @param business_connection_id Unique identifier of the business connection
* @param signal Optional `AbortSignal` to cancel the request
*/
getBusinessConnection(
business_connection_id: string,
signal?: AbortSignal,
) {
return this.raw.getBusinessConnection(
{ business_connection_id },
signal,

Check warning on line 859 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L852-L859

Added lines #L852 - L859 were not covered by tests
);
}

Check warning on line 861 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L861

Added line #L861 was not covered by tests

/**
* Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link `https://api.telegram.org/file/bot<token>/<file_path>`, where `<file_path>` is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
*
Expand Down Expand Up @@ -2034,7 +2050,7 @@
* Use this method to delete multiple messages simultaneously. 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_ids Identifiers of 1-100 messages to delete. See deleteMessage for limitations on which messages can be deleted
* @param message_ids A list of 1-100 identifiers of messages to delete. See deleteMessage for limitations on which messages can be deleted
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#deletemessages
Expand All @@ -2051,7 +2067,7 @@
* Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. 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 sticker Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP or .TGS sticker using multipart/form-data. Video stickers can only be sent by a file_id. Animated stickers can't be sent via an HTTP URL.
* @param sticker Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP, .TGS, or .WEBM sticker using multipart/form-data. Video and animated stickers can't be sent via an HTTP URL.
* @param other Optional remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
Expand Down Expand Up @@ -2081,7 +2097,7 @@
/**
* Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.
*
* @param custom_emoji_ids List of custom emoji identifiers
* @param custom_emoji_ids A list of custom emoji identifiers
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#getcustomemojistickers
Expand All @@ -2091,7 +2107,7 @@
}

/**
* Use this method to upload a file with a sticker for later use in the createNewStickerSet and addStickerToSet methods (the file can be used multiple times). Returns the uploaded File on success.
* Use this method to upload a file with a sticker for later use in the createNewStickerSet, addStickerToSet, or replaceStickerInSet methods (the file can be used multiple times). Returns the uploaded File on success.
*
* @param user_id User identifier of sticker file owner
* @param sticker_format Format of the sticker, must be one of “static”, “animated”, “video”
Expand Down Expand Up @@ -2119,7 +2135,6 @@
* @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only English letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in `_by_<bot_username>`. `<bot_username>` is case insensitive. 1-64 characters.
* @param title Sticker set title, 1-64 characters
* @param stickers A list of 1-50 initial stickers to be added to the sticker set
* @param sticker_format Format of the sticker, must be one of “static”, “animated”, “video”
* @param other Optional remaining parameters, confer the official reference below
* @param signal Optional `AbortSignal` to cancel the request
*
Expand All @@ -2130,7 +2145,6 @@
name: string,
title: string,
stickers: InputSticker[],
sticker_format: "static" | "animated" | "video",
other?: Other<
R,
"createNewStickerSet",
Expand All @@ -2143,7 +2157,7 @@
signal?: AbortSignal,
) {
return this.raw.createNewStickerSet(
{ user_id, name, title, stickers, sticker_format, ...other },
{ user_id, name, title, stickers, ...other },

Check warning on line 2160 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L2160

Added line #L2160 was not covered by tests
signal,
);
}
Expand Down Expand Up @@ -2199,6 +2213,28 @@
return this.raw.deleteStickerFromSet({ sticker }, signal);
}

/**

Check warning on line 2216 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L2216

Added line #L2216 was not covered by tests
* Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. Returns True on success.
*
* @param user_id User identifier of the sticker set owner
* @param name Sticker set name
* @param old_sticker File identifier of the replaced sticker
* @param sticker An object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged.:x
* @param signal Optional `AbortSignal` to cancel the request
*/
replaceStickerInSet(
user_id: number,
name: string,
old_sticker: string,
sticker: InputSticker,
signal?: AbortSignal,
) {
return this.raw.replaceStickerInSet(
{ user_id, name, old_sticker, sticker },
signal,

Check warning on line 2234 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L2224-L2234

Added lines #L2224 - L2234 were not covered by tests
);
}

Check warning on line 2236 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L2236

Added line #L2236 was not covered by tests

/**
* Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.
*
Expand Down Expand Up @@ -2284,6 +2320,7 @@
* @param name Sticker set name
* @param user_id User identifier of the sticker set owner
* @param thumbnail A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
* @param format Format of the thumbnail, must be one of “static” for a .WEBP or .PNG image, “animated” for a .TGS animation, or “video” for a WEBM video
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#setstickersetthumbnail
Expand All @@ -2292,10 +2329,11 @@
name: string,
user_id: number,
thumbnail: InputFile | string | undefined,
format: "static" | "animated" | "video",

Check warning on line 2332 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L2332

Added line #L2332 was not covered by tests
signal?: AbortSignal,
) {
return this.raw.setStickerSetThumbnail(
{ name, user_id, thumbnail },
{ name, user_id, thumbnail, format },

Check warning on line 2336 in src/core/api.ts

View check run for this annotation

Codecov / codecov/patch

src/core/api.ts#L2336

Added line #L2336 was not covered by tests
signal,
);
}
Expand Down
17 changes: 13 additions & 4 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const COMMON_MESSAGE_KEYS = {
forward_origin: FORWARD_ORIGIN_KEYS,
is_topic_message: {},
is_automatic_forward: {},
business_connection_id: {},

text: {},
animation: {},
Expand Down Expand Up @@ -327,22 +328,30 @@ const CHANNEL_POST_KEYS = {
...COMMON_MESSAGE_KEYS,
channel_chat_created: {},
} as const;
const CALLBACK_QUERY_KEYS = { data: {}, game_short_name: {} } as const;
const CHAT_MEMBER_UPDATED_KEYS = { from: USER_KEYS } as const;
const MESSAGE_REACTION_UPDATED_KEYS = {
const BUSINESS_CONNECTION_KEYS = {
can_reply: {},
is_enabled: {},
} as const;
const MESSAGE_REACTION_KEYS = {
old_reaction: REACTION_KEYS,
new_reaction: REACTION_KEYS,
} as const;
const MESSAGE_REACTION_COUNT_UPDATED_KEYS = {
reactions: REACTION_KEYS,
} as const;
const CALLBACK_QUERY_KEYS = { data: {}, game_short_name: {} } as const;
const CHAT_MEMBER_UPDATED_KEYS = { from: USER_KEYS } as const;

// L1
const UPDATE_KEYS = {
message: MESSAGE_KEYS,
edited_message: MESSAGE_KEYS,
channel_post: CHANNEL_POST_KEYS,
edited_channel_post: CHANNEL_POST_KEYS,
business_connection: BUSINESS_CONNECTION_KEYS,
business_message: MESSAGE_KEYS,
edited_business_message: MESSAGE_KEYS,
deleted_business_messages: {},
inline_query: {},
chosen_inline_result: {},
callback_query: CALLBACK_QUERY_KEYS,
Expand All @@ -353,7 +362,7 @@ const UPDATE_KEYS = {
my_chat_member: CHAT_MEMBER_UPDATED_KEYS,
chat_member: CHAT_MEMBER_UPDATED_KEYS,
chat_join_request: {},
message_reaction: MESSAGE_REACTION_UPDATED_KEYS,
message_reaction: MESSAGE_REACTION_KEYS,
message_reaction_count: MESSAGE_REACTION_COUNT_UPDATED_KEYS,
chat_boost: {},
removed_chat_boost: {},
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.5.2/mod.ts";
} from "https://deno.land/x/grammy_types@v3.6.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.5.2/mod.ts";
export * from "https://deno.land/x/grammy_types@v3.6.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.5.2/mod.ts";
} from "https://deno.land/x/grammy_types@v3.6.0/mod.ts";

// === Export all API types
export * from "https://deno.land/x/grammy_types@v3.5.2/mod.ts";
export * from "https://deno.land/x/grammy_types@v3.6.0/mod.ts";

/** Something that looks like a URL. */
interface URLLike {
Expand Down
Loading
Loading