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: add support for Bot API 6.6 #381

Merged
merged 9 commits into from
Mar 9, 2023
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-6.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-6.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: 2 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"files": {
"exclude": [
"./deno_cache/",
"./node_modules/",
"./out/",
"./package-lock.json",
Expand All @@ -28,6 +29,7 @@
"lint": {
"files": {
"exclude": [
"./deno_cache/",
"./node_modules/",
"./out/",
"./package-lock.json",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"contribs": "all-contributors"
},
"dependencies": {
"@grammyjs/types": "^2.12.1",
"@grammyjs/types": "^3.0.1",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.6.9"
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,7 @@ export class Context implements RenamedUpdate {
* @param title Product name, 1-32 characters
* @param description Product description, 1-255 characters
* @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
* @param provider_token Payments provider token, obtained via BotFather
* @param provider_token Payment provider token, obtained via @BotFather
* @param currency Three-letter ISO 4217 currency code, see more on currencies
* @param prices Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
* @param other Optional remaining parameters, confer the official reference below
Expand Down
232 changes: 206 additions & 26 deletions src/core/api.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/platform.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (isDeno) {

// === Export system-specific operations
// Turn an AsyncIterable<Uint8Array> into a stream
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.176.0/streams/mod.ts";
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.178.0/streams/mod.ts";

// === Base configuration for `fetch` calls
export const baseFetchConfig = (_apiRoot: string) => ({});
Expand Down
2 changes: 1 addition & 1 deletion src/platform.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { d as debug };

// === Export system-specific operations
// Turn an AsyncIterable<Uint8Array> into a stream
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.176.0/streams/mod.ts";
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.178.0/streams/mod.ts";

// === Base configuration for `fetch` calls
export const baseFetchConfig = (_apiRoot: string) => ({});
Expand Down
40 changes: 25 additions & 15 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// === Needed imports
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
import { iterateReader } from "https://deno.land/[email protected]/streams/mod.ts";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/[email protected]";
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
import { iterateReader } from "https://deno.land/[email protected]/streams/mod.ts";
import { debug as d, isDeno, toRaw } from "./platform.deno.ts";
import {
type ApiMethods as ApiMethodsF,
type InputMedia as InputMediaF,
type InputMediaAnimation as InputMediaAnimationF,
type InputMediaAudio as InputMediaAudioF,
type InputMediaDocument as InputMediaDocumentF,
type InputMediaPhoto as InputMediaPhotoF,
type InputMediaVideo as InputMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/[email protected]/mod.ts";

const debug = d("grammy:warn");

// === Export all API types
export * from "https://esm.sh/@grammyjs/[email protected]";
export * from "https://deno.land/x/[email protected]/mod.ts";

/** Something that looks like a URL. */
interface URLLike {
Expand Down Expand Up @@ -118,29 +128,29 @@ function isDenoFile(data: unknown): data is Deno.FsFile {
}

// === Export InputFile types
type GrammyTypes = InputFileProxy<InputFile>;

/** Wrapper type to bundle all methods of the Telegram API */
export type ApiMethods = GrammyTypes["Telegram"];
export type ApiMethods = ApiMethodsF<InputFile>;

/** Utility type providing the argument type for the given method name or `{}` if the method does not take any parameters */
export type Opts<M extends keyof GrammyTypes["Telegram"]> =
GrammyTypes["Opts"][M];
export type Opts<M extends keyof ApiMethods> = OptsF<InputFile>[M];

/** This object describes a sticker to be added to a sticker set. */
export type InputSticker = InputStickerF<InputFile>;

/** This object represents the content of a media message to be sent. It should be one of
- InputMediaAnimation
- InputMediaDocument
- InputMediaAudio
- InputMediaPhoto
- InputMediaVideo */
export type InputMedia = GrammyTypes["InputMedia"];
export type InputMedia = InputMediaF<InputFile>;
/** Represents a photo to be sent. */
export type InputMediaPhoto = GrammyTypes["InputMediaPhoto"];
export type InputMediaPhoto = InputMediaPhotoF<InputFile>;
/** Represents a video to be sent. */
export type InputMediaVideo = GrammyTypes["InputMediaVideo"];
export type InputMediaVideo = InputMediaVideoF<InputFile>;
/** Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. */
export type InputMediaAnimation = GrammyTypes["InputMediaAnimation"];
export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
/** Represents an audio file to be treated as music to be sent. */
export type InputMediaAudio = GrammyTypes["InputMediaAudio"];
export type InputMediaAudio = InputMediaAudioF<InputFile>;
/** Represents a general file to be sent. */
export type InputMediaDocument = GrammyTypes["InputMediaDocument"];
export type InputMediaDocument = InputMediaDocumentF<InputFile>;
34 changes: 22 additions & 12 deletions src/types.node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// === Needed imports
import { type InputFileProxy } from "@grammyjs/types";
import {
type ApiMethods as ApiMethodsF,
type InputMedia as InputMediaF,
type InputMediaAnimation as InputMediaAnimationF,
type InputMediaAudio as InputMediaAudioF,
type InputMediaDocument as InputMediaDocumentF,
type InputMediaPhoto as InputMediaPhotoF,
type InputMediaVideo as InputMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "@grammyjs/types";
import { createReadStream, type ReadStream } from "fs";
import fetch from "node-fetch";
import { basename } from "path";
Expand Down Expand Up @@ -110,29 +120,29 @@ async function* fetchFile(url: string | URL): AsyncIterable<Uint8Array> {
}

// === Export InputFile types
type GrammyTypes = InputFileProxy<InputFile>;

/** Wrapper type to bundle all methods of the Telegram API */
export type ApiMethods = GrammyTypes["Telegram"];
export type ApiMethods = ApiMethodsF<InputFile>;

/** Utility type providing the argument type for the given method name or `{}` if the method does not take any parameters */
export type Opts<M extends keyof GrammyTypes["Telegram"]> =
GrammyTypes["Opts"][M];
export type Opts<M extends keyof ApiMethods> = OptsF<InputFile>[M];

/** This object describes a sticker to be added to a sticker set. */
export type InputSticker = InputStickerF<InputFile>;

/** This object represents the content of a media message to be sent. It should be one of
- InputMediaAnimation
- InputMediaDocument
- InputMediaAudio
- InputMediaPhoto
- InputMediaVideo */
export type InputMedia = GrammyTypes["InputMedia"];
export type InputMedia = InputMediaF<InputFile>;
/** Represents a photo to be sent. */
export type InputMediaPhoto = GrammyTypes["InputMediaPhoto"];
export type InputMediaPhoto = InputMediaPhotoF<InputFile>;
/** Represents a video to be sent. */
export type InputMediaVideo = GrammyTypes["InputMediaVideo"];
export type InputMediaVideo = InputMediaVideoF<InputFile>;
/** Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. */
export type InputMediaAnimation = GrammyTypes["InputMediaAnimation"];
export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
/** Represents an audio file to be treated as music to be sent. */
export type InputMediaAudio = GrammyTypes["InputMediaAudio"];
export type InputMediaAudio = InputMediaAudioF<InputFile>;
/** Represents a general file to be sent. */
export type InputMediaDocument = GrammyTypes["InputMediaDocument"];
export type InputMediaDocument = InputMediaDocumentF<InputFile>;
38 changes: 24 additions & 14 deletions src/types.web.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
// === Needed imports
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/[email protected]";
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
import {
type ApiMethods as ApiMethodsF,
type InputMedia as InputMediaF,
type InputMediaAnimation as InputMediaAnimationF,
type InputMediaAudio as InputMediaAudioF,
type InputMediaDocument as InputMediaDocumentF,
type InputMediaPhoto as InputMediaPhotoF,
type InputMediaVideo as InputMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/[email protected]/mod.ts";
import { toRaw } from "./platform.deno.ts";

// === Export all API types
export * from "https://esm.sh/@grammyjs/[email protected]";
export * from "https://deno.land/x/[email protected]/mod.ts";

/** Something that looks like a URL. */
interface URLLike {
Expand Down Expand Up @@ -90,29 +100,29 @@ async function* fetchFile(url: string | URL): AsyncIterable<Uint8Array> {
}

// === Export InputFile types
type GrammyTypes = InputFileProxy<InputFile>;

/** Wrapper type to bundle all methods of the Telegram API */
export type ApiMethods = GrammyTypes["Telegram"];
export type ApiMethods = ApiMethodsF<InputFile>;

/** Utility type providing the argument type for the given method name or `{}` if the method does not take any parameters */
export type Opts<M extends keyof GrammyTypes["Telegram"]> =
GrammyTypes["Opts"][M];
export type Opts<M extends keyof ApiMethods> = OptsF<InputFile>[M];

/** This object describes a sticker to be added to a sticker set. */
export type InputSticker = InputStickerF<InputFile>;

/** This object represents the content of a media message to be sent. It should be one of
- InputMediaAnimation
- InputMediaDocument
- InputMediaAudio
- InputMediaPhoto
- InputMediaVideo */
export type InputMedia = GrammyTypes["InputMedia"];
export type InputMedia = InputMediaF<InputFile>;
/** Represents a photo to be sent. */
export type InputMediaPhoto = GrammyTypes["InputMediaPhoto"];
export type InputMediaPhoto = InputMediaPhotoF<InputFile>;
/** Represents a video to be sent. */
export type InputMediaVideo = GrammyTypes["InputMediaVideo"];
export type InputMediaVideo = InputMediaVideoF<InputFile>;
/** Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. */
export type InputMediaAnimation = GrammyTypes["InputMediaAnimation"];
export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
/** Represents an audio file to be treated as music to be sent. */
export type InputMediaAudio = GrammyTypes["InputMediaAudio"];
export type InputMediaAudio = InputMediaAudioF<InputFile>;
/** Represents a general file to be sent. */
export type InputMediaDocument = GrammyTypes["InputMediaDocument"];
export type InputMediaDocument = InputMediaDocumentF<InputFile>;
2 changes: 1 addition & 1 deletion test/bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Bot } from "../src/bot.ts";
import {
assertEquals,
assertThrows,
} from "https://deno.land/std@0.176.0/testing/asserts.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";

function createBot(token: string) {
return new Bot(token);
Expand Down
6 changes: 3 additions & 3 deletions test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { type Context } from "../src/mod.ts";
import {
assertEquals,
assertRejects,
} from "https://deno.land/std@0.176.0/testing/asserts.ts";
import { type Spy, spy } from "https://deno.land/std@0.176.0/testing/mock.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { type Spy, spy } from "https://deno.land/std@0.178.0/testing/mock.ts";
import {
beforeEach,
describe,
it,
} from "https://deno.land/std@0.176.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/bdd.ts";

describe("Composer", () => {
let composer: Composer<Context>;
Expand Down
4 changes: 2 additions & 2 deletions test/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
assertEquals,
assertFalse,
assertThrows,
} from "https://deno.land/std@0.176.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.176.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";

describe("Context", () => {
const u = { id: 42, first_name: "bot", is_bot: true } as User;
Expand Down
4 changes: 2 additions & 2 deletions test/convenience/keyboard.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InlineKeyboard, Keyboard } from "../../src/convenience/keyboard.ts";
import { type LoginUrl } from "../../src/types.ts";
import { assertEquals } from "https://deno.land/std@0.170.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.170.0/testing/bdd.ts";
import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";

describe("Keyboard", () => {
it("should take initial buttons", () => {
Expand Down
6 changes: 3 additions & 3 deletions test/convenience/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
assertEquals,
assertRejects,
assertThrows,
} from "https://deno.land/std@0.170.0/testing/asserts.ts";
import { spy } from "https://deno.land/std@0.170.0/testing/mock.ts";
import { describe, it } from "https://deno.land/std@0.170.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { spy } from "https://deno.land/std@0.178.0/testing/mock.ts";
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";

const TICK_MS = 50;
const tick = (n = 1) => new Promise((r) => setTimeout(r, n * TICK_MS));
Expand Down
6 changes: 3 additions & 3 deletions test/core/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { type ApiResponse } from "../../src/types.ts";
import {
assertEquals,
assertRejects,
} from "https://deno.land/std@0.170.0/testing/asserts.ts";
import { spy, Stub, stub } from "https://deno.land/std@0.170.0/testing/mock.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { spy, Stub, stub } from "https://deno.land/std@0.178.0/testing/mock.ts";
import {
afterEach,
beforeEach,
describe,
it,
} from "https://deno.land/std@0.170.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/bdd.ts";

const token = "secret-token";

Expand Down
4 changes: 2 additions & 2 deletions test/core/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpError, toHttpError } from "../../src/core/error.ts";
import { assertThrows } from "https://deno.land/std@0.170.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.170.0/testing/bdd.ts";
import { assertThrows } from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";

describe("toHttpError", () => {
it("should throw errors", () => {
Expand Down
6 changes: 3 additions & 3 deletions test/core/payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
assert,
assertEquals,
assertFalse,
} from "https://deno.land/std@0.170.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.170.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";
import {
readAll,
readerFromIterable,
} from "https://deno.land/std@0.170.0/streams/conversion.ts";
} from "https://deno.land/std@0.178.0/streams/mod.ts";

describe("requiresFormDataUpload", () => {
it("should ignore primitives", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { type Context } from "../src/mod.ts";
import {
assert,
assertThrows,
} from "https://deno.land/std@0.176.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.176.0/testing/bdd.ts";
} from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";

describe("matchFilter", () => {
it("should reject empty filters", () => {
Expand Down