grammy 1.30.1 โ†’ 1.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  <!-- deno-fmt-ignore-start -->
12
12
 
13
- [![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)
13
+ [![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)
14
14
  [![Deno](https://shield.deno.dev/x/grammy)](https://deno.land/x/grammy)
15
15
  [![npm](https://img.shields.io/npm/v/grammy?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/grammy)
16
16
  [![All Contributors](https://img.shields.io/github/all-contributors/grammyjs/grammy?style=flat&labelColor=000&color=3b82f6)](#contributors-)
@@ -314,6 +314,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
314
314
  <td align="center" valign="top" width="11.11%"><a href="https://nometa.xyz/"><img src="https://avatars.githubusercontent.com/u/68379695?v=4?s=100" width="100px;" alt="Mased"/><br /><sub><b>Mased</b></sub></a><br /><a href="#translation-MasedMSD" title="Translation">๐ŸŒ</a> <a href="https://github.com/grammyjs/grammY/commits?author=MasedMSD" title="Documentation">๐Ÿ“–</a></td>
315
315
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/ExposedCat"><img src="https://avatars.githubusercontent.com/u/44642024?v=4?s=100" width="100px;" alt="Artem Prokop"/><br /><sub><b>Artem Prokop</b></sub></a><br /><a href="#userTesting-ExposedCat" title="User Testing">๐Ÿ““</a></td>
316
316
  <td align="center" valign="top" width="11.11%"><a href="https://chinoman10.com/"><img src="https://avatars.githubusercontent.com/u/8300763?v=4?s=100" width="100px;" alt="Sรฉrgio Rebelo"/><br /><sub><b>Sรฉrgio Rebelo</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AChinoman10" title="Reviewed Pull Requests">๐Ÿ‘€</a></td>
317
+ <td align="center" valign="top" width="11.11%"><a href="https://blog.katsuba.dev"><img src="https://avatars.githubusercontent.com/u/10637135?v=4?s=100" width="100px;" alt="Igor Katsuba"/><br /><sub><b>Igor Katsuba</b></sub></a><br /><a href="#ideas-IKatsuba" title="Ideas, Planning, & Feedback">๐Ÿค”</a> <a href="https://github.com/grammyjs/grammY/commits?author=IKatsuba" title="Code">๐Ÿ’ป</a></td>
317
318
  </tr>
318
319
  </tbody>
319
320
  </table>
package/out/context.d.ts CHANGED
@@ -1242,7 +1242,7 @@ export declare class Context implements RenamedUpdate {
1242
1242
  */
1243
1243
  editMessageCaption(other?: Other<"editMessageCaption", "chat_id" | "message_id" | "inline_message_id">, signal?: AbortSignal): Promise<true | (Update.Edited & Message.CaptionableMessage)>;
1244
1244
  /**
1245
- * 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.
1245
+ * 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.
1246
1246
  *
1247
1247
  * @param media An object for a new media content of the message
1248
1248
  * @param other Optional remaining parameters, confer the official reference below
package/out/context.js CHANGED
@@ -1632,7 +1632,7 @@ class Context {
1632
1632
  : this.api.editMessageCaption(orThrow(this.chatId, "editMessageCaption"), orThrow((_d = (_b = (_a = this.msg) === null || _a === void 0 ? void 0 : _a.message_id) !== null && _b !== void 0 ? _b : (_c = this.messageReaction) === null || _c === void 0 ? void 0 : _c.message_id) !== null && _d !== void 0 ? _d : (_e = this.messageReactionCount) === null || _e === void 0 ? void 0 : _e.message_id, "editMessageCaption"), other, signal);
1633
1633
  }
1634
1634
  /**
1635
- * 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.
1635
+ * 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.
1636
1636
  *
1637
1637
  * @param media An object for a new media content of the message
1638
1638
  * @param other Optional remaining parameters, confer the official reference below
@@ -1,4 +1,4 @@
1
- import { type InlineKeyboardButton, type KeyboardButton, type KeyboardButtonPollType, type KeyboardButtonRequestChat, type KeyboardButtonRequestUsers, type LoginUrl, type SwitchInlineQueryChosenChat } from "../types.js";
1
+ import { type CopyTextButton, type InlineKeyboardButton, type KeyboardButton, type KeyboardButtonPollType, type KeyboardButtonRequestChat, type KeyboardButtonRequestUsers, type LoginUrl, type SwitchInlineQueryChosenChat, type WebAppInfo } from "../types.js";
2
2
  type KeyboardButtonSource = string | KeyboardButton;
3
3
  type KeyboardSource = KeyboardButtonSource[][] | Keyboard;
4
4
  /**
@@ -494,14 +494,14 @@ export declare class InlineKeyboard {
494
494
  * @param text The text to display
495
495
  * @param url An HTTPS URL of a Web App to be opened with additional data
496
496
  */
497
- webApp(text: string, url: string): this;
497
+ webApp(text: string, url: string | WebAppInfo): this;
498
498
  /**
499
499
  * Creates a new web app button, confer https://core.telegram.org/bots/webapps
500
500
  *
501
501
  * @param text The text to display
502
502
  * @param url An HTTPS URL of a Web App to be opened with additional data
503
503
  */
504
- static webApp(text: string, url: string): InlineKeyboardButton.WebAppButton;
504
+ static webApp(text: string, url: string | WebAppInfo): InlineKeyboardButton.WebAppButton;
505
505
  /**
506
506
  * Adds a new login button. This can be used as a replacement for the
507
507
  * Telegram Login Widget. You must specify an HTTPS URL used to
@@ -616,6 +616,22 @@ export declare class InlineKeyboard {
616
616
  * @param query The query object describing which chats can be picked
617
617
  */
618
618
  static switchInlineChosen(text: string, query?: SwitchInlineQueryChosenChat): InlineKeyboardButton.SwitchInlineChosenChatButton;
619
+ /**
620
+ * Adds a new copy text button. When clicked, the specified text will be
621
+ * copied to the clipboard.
622
+ *
623
+ * @param text The text to display
624
+ * @param copyText The text to be copied to the clipboard
625
+ */
626
+ copyText(text: string, copyText: string | CopyTextButton): this;
627
+ /**
628
+ * Creates a new copy text button. When clicked, the specified text will be
629
+ * copied to the clipboard.
630
+ *
631
+ * @param text The text to display
632
+ * @param copyText The text to be copied to the clipboard
633
+ */
634
+ static copyText(text: string, copyText: string | CopyTextButton): InlineKeyboardButton.CopyTextButtonButton;
619
635
  /**
620
636
  * Adds a new game query button, confer
621
637
  * https://core.telegram.org/bots/api#games
@@ -582,7 +582,7 @@ class InlineKeyboard {
582
582
  * @param url An HTTPS URL of a Web App to be opened with additional data
583
583
  */
584
584
  static webApp(text, url) {
585
- return { text, web_app: { url } };
585
+ return { text, web_app: typeof url === "string" ? { url } : url };
586
586
  }
587
587
  /**
588
588
  * Adds a new login button. This can be used as a replacement for the
@@ -719,6 +719,31 @@ class InlineKeyboard {
719
719
  static switchInlineChosen(text, query = {}) {
720
720
  return { text, switch_inline_query_chosen_chat: query };
721
721
  }
722
+ /**
723
+ * Adds a new copy text button. When clicked, the specified text will be
724
+ * copied to the clipboard.
725
+ *
726
+ * @param text The text to display
727
+ * @param copyText The text to be copied to the clipboard
728
+ */
729
+ copyText(text, copyText) {
730
+ return this.add(InlineKeyboard.copyText(text, copyText));
731
+ }
732
+ /**
733
+ * Creates a new copy text button. When clicked, the specified text will be
734
+ * copied to the clipboard.
735
+ *
736
+ * @param text The text to display
737
+ * @param copyText The text to be copied to the clipboard
738
+ */
739
+ static copyText(text, copyText) {
740
+ return {
741
+ text,
742
+ copy_text: typeof copyText === "string"
743
+ ? { text: copyText }
744
+ : copyText,
745
+ };
746
+ }
722
747
  /**
723
748
  * Adds a new game query button, confer
724
749
  * https://core.telegram.org/bots/api#games
package/out/core/api.d.ts CHANGED
@@ -1104,7 +1104,7 @@ export declare class Api<R extends RawApi = RawApi> {
1104
1104
  */
1105
1105
  editMessageCaptionInline(inline_message_id: string, other?: Other<R, "editMessageCaption", "chat_id" | "message_id" | "inline_message_id">, signal?: AbortSignal): Promise<true | (import("@grammyjs/types/update.js").Update.Edited & import("@grammyjs/types/message.js").Message.CaptionableMessage)>;
1106
1106
  /**
1107
- * 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.
1107
+ * 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.
1108
1108
  *
1109
1109
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1110
1110
  * @param message_id Identifier of the message to edit
@@ -1116,7 +1116,7 @@ export declare class Api<R extends RawApi = RawApi> {
1116
1116
  */
1117
1117
  editMessageMedia(chat_id: number | string, message_id: number, media: InputMedia, other?: Other<R, "editMessageMedia", "chat_id" | "message_id" | "inline_message_id" | "media">, signal?: AbortSignal): Promise<true | (import("@grammyjs/types/update.js").Update.Edited & import("@grammyjs/types/message.js").Message)>;
1118
1118
  /**
1119
- * 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.
1119
+ * 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.
1120
1120
  *
1121
1121
  * @param inline_message_id Identifier of the inline message
1122
1122
  * @param media An object for a new media content of the message
package/out/core/api.js CHANGED
@@ -1274,7 +1274,7 @@ class Api {
1274
1274
  return this.raw.editMessageCaption({ inline_message_id, ...other }, signal);
1275
1275
  }
1276
1276
  /**
1277
- * 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.
1277
+ * 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.
1278
1278
  *
1279
1279
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1280
1280
  * @param message_id Identifier of the message to edit
@@ -1288,7 +1288,7 @@ class Api {
1288
1288
  return this.raw.editMessageMedia({ chat_id, message_id, media, ...other }, signal);
1289
1289
  }
1290
1290
  /**
1291
- * 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.
1291
+ * 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.
1292
1292
  *
1293
1293
  * @param inline_message_id Identifier of the inline message
1294
1294
  * @param media An object for a new media content of the message
@@ -145,6 +145,10 @@ export interface ApiClientOptions {
145
145
  * compress: true }` (Node), `{}` (Deno)
146
146
  */
147
147
  baseFetchConfig?: Omit<NonNullable<Parameters<typeof fetch>[1]>, "method" | "headers" | "body">;
148
+ /**
149
+ * `fetch` function to use for making HTTP requests. Default: `node-fetch` in Node.js, `fetch` in Deno.
150
+ */
151
+ fetch?: typeof fetch;
148
152
  /**
149
153
  * When the network connection is unreliable and some API requests fail
150
154
  * because of that, grammY will throw errors that tell you exactly which
@@ -11,7 +11,7 @@ function concatTransformer(prev, trans) {
11
11
  }
12
12
  class ApiClient {
13
13
  constructor(token, options = {}, webhookReplyEnvelope = {}) {
14
- var _a, _b, _c, _d, _e, _f;
14
+ var _a, _b, _c, _d, _e, _f, _g;
15
15
  this.token = token;
16
16
  this.webhookReplyEnvelope = webhookReplyEnvelope;
17
17
  this.hasUsedWebhookReply = false;
@@ -46,7 +46,7 @@ class ApiClient {
46
46
  const sig = controller.signal;
47
47
  const options = { ...opts.baseFetchConfig, signal: sig, ...config };
48
48
  // Perform fetch call, and handle networking errors
49
- const successPromise = (0, shim_node_js_1.fetch)(url instanceof URL ? url.href : url, options).catch((0, error_js_1.toHttpError)(method, opts.sensitiveLogs));
49
+ const successPromise = this.fetch(url instanceof URL ? url.href : url, options).catch((0, error_js_1.toHttpError)(method, opts.sensitiveLogs));
50
50
  // Those are the three possible outcomes of the fetch call:
51
51
  const operations = [successPromise, streamErr.promise, timeout.promise];
52
52
  // Wait for result
@@ -72,7 +72,9 @@ class ApiClient {
72
72
  },
73
73
  canUseWebhookReply: (_e = options.canUseWebhookReply) !== null && _e !== void 0 ? _e : (() => false),
74
74
  sensitiveLogs: (_f = options.sensitiveLogs) !== null && _f !== void 0 ? _f : false,
75
+ fetch: (_g = options.fetch) !== null && _g !== void 0 ? _g : shim_node_js_1.fetch,
75
76
  };
77
+ this.fetch = this.options.fetch;
76
78
  if (this.options.apiRoot.endsWith("/")) {
77
79
  throw new Error(`Remove the trailing '/' from the 'apiRoot' option (use '${this.options.apiRoot.substring(0, this.options.apiRoot.length - 1)}' instead of '${this.options.apiRoot}')`);
78
80
  }
package/out/web.mjs CHANGED
@@ -2239,6 +2239,7 @@ class ApiClient {
2239
2239
  token;
2240
2240
  webhookReplyEnvelope;
2241
2241
  options;
2242
+ fetch;
2242
2243
  hasUsedWebhookReply;
2243
2244
  installedTransformers;
2244
2245
  constructor(token, options = {}, webhookReplyEnvelope = {}){
@@ -2275,7 +2276,7 @@ class ApiClient {
2275
2276
  signal: sig,
2276
2277
  ...config
2277
2278
  };
2278
- const successPromise = fetch(url instanceof URL ? url.href : url, options).catch(toHttpError(method, opts.sensitiveLogs));
2279
+ const successPromise = this.fetch(url instanceof URL ? url.href : url, options).catch(toHttpError(method, opts.sensitiveLogs));
2279
2280
  const operations = [
2280
2281
  successPromise,
2281
2282
  streamErr.promise,
@@ -2300,8 +2301,10 @@ class ApiClient {
2300
2301
  ...options.baseFetchConfig
2301
2302
  },
2302
2303
  canUseWebhookReply: options.canUseWebhookReply ?? (()=>false),
2303
- sensitiveLogs: options.sensitiveLogs ?? false
2304
+ sensitiveLogs: options.sensitiveLogs ?? false,
2305
+ fetch: options.fetch ?? fetch
2304
2306
  };
2307
+ this.fetch = this.options.fetch;
2305
2308
  if (this.options.apiRoot.endsWith("/")) {
2306
2309
  throw new Error(`Remove the trailing '/' from the 'apiRoot' option (use '${this.options.apiRoot.substring(0, this.options.apiRoot.length - 1)}' instead of '${this.options.apiRoot}')`);
2307
2310
  }
@@ -4157,9 +4160,9 @@ class InlineKeyboard {
4157
4160
  static webApp(text, url) {
4158
4161
  return {
4159
4162
  text,
4160
- web_app: {
4163
+ web_app: typeof url === "string" ? {
4161
4164
  url
4162
- }
4165
+ } : url
4163
4166
  };
4164
4167
  }
4165
4168
  login(text, loginUrl) {
@@ -4200,6 +4203,17 @@ class InlineKeyboard {
4200
4203
  switch_inline_query_chosen_chat: query
4201
4204
  };
4202
4205
  }
4206
+ copyText(text, copyText) {
4207
+ return this.add(InlineKeyboard.copyText(text, copyText));
4208
+ }
4209
+ static copyText(text, copyText) {
4210
+ return {
4211
+ text,
4212
+ copy_text: typeof copyText === "string" ? {
4213
+ text: copyText
4214
+ } : copyText
4215
+ };
4216
+ }
4203
4217
  game(text) {
4204
4218
  return this.add(InlineKeyboard.game(text));
4205
4219
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.30.1",
4
+ "version": "1.31.1",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -17,7 +17,7 @@
17
17
  "backport": "deno2node tsconfig.json"
18
18
  },
19
19
  "dependencies": {
20
- "@grammyjs/types": "3.14.0",
20
+ "@grammyjs/types": "3.15.0",
21
21
  "abort-controller": "^3.0.0",
22
22
  "debug": "^4.3.4",
23
23
  "node-fetch": "^2.7.0"