Skip to content

Commit

Permalink
feat: support Bot API 6.5 (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf authored Feb 3, 2023
1 parent 01adad1 commit 1b4b2eb
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 20 deletions.
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.11.0",
"@grammyjs/types": "^2.12.0",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.6.7"
Expand Down
46 changes: 45 additions & 1 deletion src/convenience/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
type InlineKeyboardButton,
type KeyboardButton,
type KeyboardButtonRequestChat,
type KeyboardButtonRequestUser,
type LoginUrl,
} from "../types.ts";

Expand Down Expand Up @@ -101,6 +103,48 @@ export class Keyboard {
text(text: string) {
return this.add({ text });
}
/**
* Adds a new request user button. When the user presses the button, a list
* of suitable users will be opened. Tapping on any user will send their
* identifier to the bot in a “user_shared” service message. Available in
* private chats only.
*
* @param text The text to display
* @param requestId A signed 32-bit identifier of the request
* @param options Options object for further requirements
*/
requestUser(
text: string,
requestId: number,
options: Omit<KeyboardButtonRequestUser, "request_id"> = {},
) {
return this.add({
text,
request_user: { request_id: requestId, ...options },
});
}
/**
* Adds a new request chat button. When the user presses the button, a list
* of suitable users will be opened. Tapping on a chat will send its
* identifier to the bot in a “chat_shared” service message. Available in
* private chats only.
*
* @param text The text to display
* @param requestId A signed 32-bit identifier of the request
* @param options Options object for further requirements
*/
requestChat(
text: string,
requestId: number,
options: Omit<KeyboardButtonRequestChat, "request_id"> = {
chat_is_channel: false,
},
) {
return this.add({
text,
request_chat: { request_id: requestId, ...options },
});
}
/**
* Adds a new contact request button. The user's phone number will be sent
* as a contact when the button is pressed. Available in private chats only.
Expand Down Expand Up @@ -135,7 +179,7 @@ export class Keyboard {
* user presses the button. The Web App will be able to send a
* “web_app_data” service message. Available in private chats only.
*
* @param text Text text to display
* @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) {
Expand Down
2 changes: 2 additions & 0 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ const MESSAGE_KEYS = {
migrate_to_chat_id: {},
migrate_from_chat_id: {},
successful_payment: {},
user_shared: {},
chat_shared: {},
connected_website: {},
write_access_allowed: {},
passport_data: {},
Expand Down
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.170.0/streams/mod.ts";
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.176.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.170.0/streams/mod.ts";
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.176.0/streams/mod.ts";

// === Base configuration for `fetch` calls
export const baseFetchConfig = (_apiRoot: string) => ({});
Expand Down
8 changes: 4 additions & 4 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// === Needed imports
import { basename } from "https://deno.land/std@0.170.0/path/mod.ts";
import { iterateReader } from "https://deno.land/std@0.170.0/streams/mod.ts";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/types@2.11.0";
import { basename } from "https://deno.land/std@0.176.0/path/mod.ts";
import { iterateReader } from "https://deno.land/std@0.176.0/streams/mod.ts";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/types@2.12.0";
import { debug as d, isDeno, toRaw } from "./platform.deno.ts";

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

// === Export all API types
export * from "https://esm.sh/@grammyjs/types@2.11.0";
export * from "https://esm.sh/@grammyjs/types@2.12.0";

/** Something that looks like a URL. */
interface URLLike {
Expand Down
6 changes: 3 additions & 3 deletions src/types.web.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// === Needed imports
import { basename } from "https://deno.land/std@0.170.0/path/mod.ts";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/types@2.11.0";
import { basename } from "https://deno.land/std@0.176.0/path/mod.ts";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/types@2.12.0";
import { toRaw } from "./platform.deno.ts";

// === Export all API types
export * from "https://esm.sh/@grammyjs/types@2.11.0";
export * from "https://esm.sh/@grammyjs/types@2.12.0";

/** Something that looks like a URL. */
interface URLLike {
Expand Down
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.170.0/testing/asserts.ts";
} from "https://deno.land/std@0.176.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.170.0/testing/asserts.ts";
import { type Spy, spy } from "https://deno.land/std@0.170.0/testing/mock.ts";
} 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";
import {
beforeEach,
describe,
it,
} from "https://deno.land/std@0.170.0/testing/bdd.ts";
} from "https://deno.land/std@0.176.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.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.176.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.176.0/testing/bdd.ts";

describe("Context", () => {
const u = { id: 42, first_name: "bot", is_bot: true } as User;
Expand Down
12 changes: 11 additions & 1 deletion test/convenience/keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ describe("Keyboard", () => {
.requestContact("contact")
.requestLocation("location")
.requestPoll("poll", "quiz")
.webApp("web app", "https://grammy.dev");
.webApp("web app", "https://grammy.dev")
.requestUser("user", 12, { user_is_bot: true })
.requestChat("chat", 42);
assertEquals(keyboard.build(), [[
{ text: "button" },
{ text: "contact", request_contact: true },
{ text: "location", request_location: true },
{ text: "poll", request_poll: { type: "quiz" } },
{ text: "web app", web_app: { url: "https://grammy.dev" } },
{
text: "user",
request_user: { request_id: 12, user_is_bot: true },
},
{
text: "chat",
request_chat: { request_id: 42, chat_is_channel: false },
},
]]);
});

Expand Down
1 change: 1 addition & 0 deletions test/convenience/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ describe("enhanceStorage", () => {
storage: new MemorySessionStorage<Enhance<number>>(),
millisecondsToLive: TICK_MS,
});
assertEquals(await store.read("k"), undefined);
await store.write("k", 42);
assertEquals(await store.read("k"), 42);
await tick(2);
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.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.176.0/testing/asserts.ts";
import { describe, it } from "https://deno.land/std@0.176.0/testing/bdd.ts";

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

0 comments on commit 1b4b2eb

Please sign in to comment.