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 8.2 #734

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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-8.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-8.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.17.0",
"@grammyjs/types": "3.18.0",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.7.0"
Expand Down
68 changes: 68 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,74 @@ export class Context implements RenamedUpdate {
);
}

/**
* Context-aware alias for `api.verifyUser`. Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.
*
* @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#verifyuser
*/
verifyUser(
other?: Other<"verifyUser">,
signal?: AbortSignal,
) {
return this.api.verifyUser(
orThrow(this.from, "verifyUser").id,
other,
signal,
);
}

/**
* Context-aware alias for `api.verifyChat`. Verifies a chat on behalf of the organization which is represented by the bot. Returns True on success.
*
* @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#verifychat
*/
verifyChat(
other?: Other<"verifyChat">,
signal?: AbortSignal,
) {
return this.api.verifyChat(
orThrow(this.chatId, "verifyChat"),
other,
signal,
);
}

/**
* Context-aware alias for `api.removeUserVerification`. Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.
*
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#removeuserverification
*/
removeUserVerification(signal?: AbortSignal) {
return this.api.removeUserVerification(
orThrow(this.from, "removeUserVerification").id,
signal,
);
}

/**
* Context-aware alias for `api.removeChatVerification`. Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.
*
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#removechatverification
*/
removeChatVerification(
signal?: AbortSignal,
) {
return this.api.removeChatVerification(
orThrow(this.chatId, "removeChatVerification"),
signal,
);
}

/**
* Context-aware alias for `api.setPassportDataErrors`. Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.
*
Expand Down
6 changes: 3 additions & 3 deletions src/convenience/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export type HonoAdapter = (c: {
header: (header: string) => string | undefined;
};
body: (
data: string | ArrayBuffer | ReadableStream | null,
data: string | ArrayBuffer | ReadableStream,
// deno-lint-ignore no-explicit-any
arg?: any,
headers?: Record<string, string | string[]>,
Expand Down Expand Up @@ -390,14 +390,14 @@ const hono: HonoAdapter = (c) => {
update: c.req.json(),
header: c.req.header(SECRET_HEADER),
end: () => {
resolveResponse(c.body(null));
resolveResponse(c.body(""));
},
respond: (json) => {
resolveResponse(c.json(json));
},
unauthorized: () => {
c.status(401);
resolveResponse(c.body(null));
resolveResponse(c.body(""));
},
handlerReturn: new Promise<Response>((resolve) => {
resolveResponse = resolve;
Expand Down
61 changes: 61 additions & 0 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,67 @@ export class Api<R extends RawApi = RawApi> {
);
}

/**
* Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.
*
* @param user_id Unique identifier of the target user
* @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#verifyuser
*/
verifyUser(
user_id: number,
other?: Other<R, "verifyUser">,
signal?: AbortSignal,
) {
return this.raw.verifyUser({ user_id, ...other }, signal);
}

/**
* Verifies a chat on behalf of the organization which is represented by the bot. Returns True 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
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#verifychat
*/
verifyChat(
chat_id: number | string,
other?: Other<R, "verifyChat">,
signal?: AbortSignal,
) {
return this.raw.verifyChat({ chat_id, ...other }, signal);
}

/**
* Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.
*
* @param user_id Unique identifier of the target user
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#removeuserverification
*/
removeUserVerification(user_id: number, signal?: AbortSignal) {
return this.raw.removeUserVerification({ user_id }, signal);
}

/**
* Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.
*
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
* @param signal Optional `AbortSignal` to cancel the request
*
* **Official reference:** https://core.telegram.org/bots/api#removechatverification
*/
removeChatVerification(
chat_id: number | string,
signal?: AbortSignal,
) {
return this.raw.removeChatVerification({ chat_id }, signal);
}

/**
* Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.
*
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.17.0/mod.ts";
} from "https://deno.land/x/grammy_types@v3.18.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.17.0/mod.ts";
export * from "https://deno.land/x/grammy_types@v3.18.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.17.0/mod.ts";
} from "https://deno.land/x/grammy_types@v3.18.0/mod.ts";

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

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