Skip to content

Commit

Permalink
feat: support Bot API 7.11 (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf authored Oct 31, 2024
1 parent ac6c765 commit 501dfb0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 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.10-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.11-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.14.0",
"@grammyjs/types": "3.15.0",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.7.0"
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,7 @@ export class Context implements RenamedUpdate {
}

/**
* Context-aware alias for `api.editMessageMedia`. Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
* Context-aware alias for `api.editMessageMedia`. Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @param media An object for a new media content of the message
* @param other Optional remaining parameters, confer the official reference below
Expand Down
36 changes: 33 additions & 3 deletions src/convenience/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
type CopyTextButton,
type InlineKeyboardButton,
type KeyboardButton,
type KeyboardButtonPollType,
type KeyboardButtonRequestChat,
type KeyboardButtonRequestUsers,
type LoginUrl,
type SwitchInlineQueryChosenChat,
type WebAppInfo,
} from "../types.ts";

type KeyboardButtonSource = string | KeyboardButton;
Expand Down Expand Up @@ -624,7 +626,7 @@ export class InlineKeyboard {
* @param text The text to display
* @param url An HTTPS URL of a Web App to be opened with additional data
*/
webApp(text: string, url: string) {
webApp(text: string, url: string | WebAppInfo) {
return this.add(InlineKeyboard.webApp(text, url));
}
/**
Expand All @@ -635,9 +637,9 @@ export class InlineKeyboard {
*/
static webApp(
text: string,
url: string,
url: string | WebAppInfo,
): InlineKeyboardButton.WebAppButton {
return { text, web_app: { url } };
return { text, web_app: typeof url === "string" ? { url } : url };
}
/**
* Adds a new login button. This can be used as a replacement for the
Expand Down Expand Up @@ -789,6 +791,34 @@ export class InlineKeyboard {
): InlineKeyboardButton.SwitchInlineChosenChatButton {
return { text, switch_inline_query_chosen_chat: query };
}
/**
* Adds a new copy text button. When clicked, the specified text will be
* copied to the clipboard.
*
* @param text The text to display
* @param copyText The text to be copied to the clipboard
*/
copyText(text: string, copyText: string | CopyTextButton) {
return this.add(InlineKeyboard.copyText(text, copyText));
}
/**
* Creates a new copy text button. When clicked, the specified text will be
* copied to the clipboard.
*
* @param text The text to display
* @param copyText The text to be copied to the clipboard
*/
static copyText(
text: string,
copyText: string | CopyTextButton,
): InlineKeyboardButton.CopyTextButtonButton {
return {
text,
copy_text: typeof copyText === "string"
? { text: copyText }
: copyText,
};
}
/**
* Adds a new game query button, confer
* https://core.telegram.org/bots/api#games
Expand Down
4 changes: 2 additions & 2 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ export class Api<R extends RawApi = RawApi> {
}

/**
* Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
* Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @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 message to edit
Expand Down Expand Up @@ -2030,7 +2030,7 @@ export class Api<R extends RawApi = RawApi> {
}

/**
* Use this method to edit animation, audio, document, photo, or video inline messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
* Use this method to edit animation, audio, document, photo, or video inline messages, or to add media to text inline messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* @param inline_message_id Identifier of the inline message
* @param media An object for a new media content of the message
Expand Down
4 changes: 2 additions & 2 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.14.0/mod.ts";
} from "https://deno.land/x/grammy_types@v3.15.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.14.0/mod.ts";
export * from "https://deno.land/x/grammy_types@v3.15.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 @@ -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.14.0/mod.ts";
} from "https://deno.land/x/grammy_types@v3.15.0/mod.ts";

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

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

0 comments on commit 501dfb0

Please sign in to comment.