grammy 1.5.0 → 1.5.4

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
@@ -12,7 +12,7 @@ _<h2 align="center"> [:mag: Documentation](https://grammy.dev) | [:page_with_cur
12
12
 
13
13
  [![Bot API](https://img.shields.io/badge/Bot%20API-5.5-blue?logo=telegram&style=flat-square)](https://core.telegram.org/bots/api)
14
14
  [![npm](https://img.shields.io/npm/v/grammy?logo=npm&style=flat-square)](https://www.npmjs.org/package/grammy) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
15
- [![All Contributors](https://img.shields.io/badge/all_contributors-44-orange.svg?style=flat-square)](#contributors-)
15
+ [![All Contributors](https://img.shields.io/badge/all_contributors-46-orange.svg?style=flat-square)](#contributors-)
16
16
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
17
17
 
18
18
  <!-- deno-fmt-ignore-end -->
@@ -108,6 +108,16 @@ However, given that most bot developers are still using Node.js, all documentati
108
108
 
109
109
  You may also be interested in [why we support Deno](https://grammy.dev/resources/faq.html#why-do-you-support-deno).
110
110
 
111
+ ## Browser Support
112
+
113
+ The grammY core package in this repository is avaiable as a JavaScript bundle from the CDN at `get.grammy.dev`.
114
+ Currently, we transpile all stable versions (all releases since v1.0) as well as the current `main` branch to ES3, ES5, ES6, and ESNext.
115
+
116
+ You can download them from the URL `https://get.grammy.dev/[ES version lowercased]@[grammY version including v-prefix].js`.
117
+ For example, the most recent source on `main` in ES6 is available from <https://get.grammy.dev/es6@dev.js>.
118
+
119
+ So far, this is mainly useful for running bots on Cloudflare Workers.
120
+
111
121
  ## [Contribution Guide »](./CONTRIBUTING.md)
112
122
 
113
123
  ## Contributors ✨
@@ -175,6 +185,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
175
185
  <tr>
176
186
  <td align="center"><a href="http://///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////kraftwerk28.pp.ua"><img src="https://avatars.githubusercontent.com/u/31807671?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vsevolod</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=kraftwerk28" title="Code">💻</a> <a href="#ideas-kraftwerk28" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Akraftwerk28" title="Reviewed Pull Requests">👀</a></td>
177
187
  <td align="center"><a href="https://github.com/habemuscode"><img src="https://avatars.githubusercontent.com/u/34692207?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Habemuscode</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Ahabemuscode" title="Reviewed Pull Requests">👀</a></td>
188
+ <td align="center"><a href="https://borodutch.com/"><img src="https://avatars.githubusercontent.com/u/3192028?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nikita Kolmogorov</b></sub></a><br /><a href="#plugin-backmeupplz" title="Plugin/utility libraries">🔌</a></td>
189
+ <td align="center"><a href="http://glukki.ru"><img src="https://avatars.githubusercontent.com/u/140462?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vitaliy Meshchaninov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aglukki" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=glukki" title="Code">💻</a></td>
178
190
  </tr>
179
191
  </table>
180
192
 
package/out/bot.js CHANGED
@@ -301,7 +301,7 @@ you can circumvent this protection against memory leaks.`);
301
301
  }
302
302
  else
303
303
  debugErr(error);
304
- debugErr("Call to `getUpdates` failed, retrying in 3 seconds ...");
304
+ debugErr("Call to getUpdates failed, retrying in 3 seconds ...");
305
305
  await new Promise((r) => setTimeout(r, 3000));
306
306
  };
307
307
  while (this.pollingRunning) {
@@ -313,7 +313,10 @@ you can circumvent this protection against memory leaks.`);
313
313
  updates = await this.api.getUpdates({ offset, limit, timeout, allowed_updates }, this.pollingAbortController.signal);
314
314
  }
315
315
  catch (error) {
316
- await handleErr(error);
316
+ if (this.pollingRunning)
317
+ await handleErr(error);
318
+ else
319
+ debug("Pending getUpdates request cancelled");
317
320
  }
318
321
  } while (updates === undefined && this.pollingRunning);
319
322
  if (updates === undefined)
package/out/composer.js CHANGED
@@ -299,7 +299,7 @@ class Composer {
299
299
  const noAtCommands = new Set();
300
300
  toArray(command).forEach((cmd) => {
301
301
  if (cmd.startsWith("/")) {
302
- throw new Error(`Do not include '/' when registering command handlers (use '${cmd.substr(0, 1)}' not '${cmd}')`);
302
+ throw new Error(`Do not include '/' when registering command handlers (use '${cmd.substr(1)}' not '${cmd}')`);
303
303
  }
304
304
  const set = cmd.indexOf("@") === -1 ? noAtCommands : atCommands;
305
305
  set.add(cmd);
package/out/context.d.ts CHANGED
@@ -448,15 +448,14 @@ export declare class Context implements RenamedUpdate {
448
448
  */
449
449
  setChatAdministratorCustomTitle(user_id: number, custom_title: string, signal?: AbortSignal): Promise<true>;
450
450
  /**
451
- * Context-aware alias for `api.banChatSenderChat`. Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
451
+ * Context-aware alias for `api.banChatSenderChat`. Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
452
452
  *
453
453
  * @param sender_chat_id Unique identifier of the target sender chat
454
- * @param other Optional remaining parameters, confer the official reference below
455
454
  * @param signal Optional `AbortSignal` to cancel the request
456
455
  *
457
456
  * **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
458
457
  */
459
- banChatSenderChat(sender_chat_id: number, other?: Other<"banChatSenderChat", "sender_chat_id">, signal?: AbortSignal): Promise<true>;
458
+ banChatSenderChat(sender_chat_id: number, signal?: AbortSignal): Promise<true>;
460
459
  /**
461
460
  * Context-aware alias for `api.unbanChatSenderChat`. Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
462
461
  *
@@ -772,7 +771,7 @@ export declare class Context implements RenamedUpdate {
772
771
  *
773
772
  * **Official reference:** https://core.telegram.org/bots/api#sendinvoice
774
773
  */
775
- replyWithInvoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: readonly LabeledPrice[], other?: Other<"sendInvoice", "title" | "description" | "payload" | "provider_token" | "start_parameter" | "currency" | "prices">, signal?: AbortSignal): Promise<Message.InvoiceMessage>;
774
+ replyWithInvoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: readonly LabeledPrice[], other?: Other<"sendInvoice", "title" | "description" | "payload" | "provider_token" | "currency" | "prices">, signal?: AbortSignal): Promise<Message.InvoiceMessage>;
776
775
  /**
777
776
  * Context-aware alias for `api.answerShippingQuery`. If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
778
777
  *
package/out/context.js CHANGED
@@ -577,16 +577,15 @@ class Context {
577
577
  return this.api.setChatAdministratorCustomTitle(orThrow(this.chat, "setChatAdministratorCustomTitle").id, user_id, custom_title, signal);
578
578
  }
579
579
  /**
580
- * Context-aware alias for `api.banChatSenderChat`. Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
580
+ * Context-aware alias for `api.banChatSenderChat`. Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
581
581
  *
582
582
  * @param sender_chat_id Unique identifier of the target sender chat
583
- * @param other Optional remaining parameters, confer the official reference below
584
583
  * @param signal Optional `AbortSignal` to cancel the request
585
584
  *
586
585
  * **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
587
586
  */
588
- banChatSenderChat(sender_chat_id, other, signal) {
589
- return this.api.banChatSenderChat(orThrow(this.chat, "banChatSenderChat").id, sender_chat_id, other, signal);
587
+ banChatSenderChat(sender_chat_id, signal) {
588
+ return this.api.banChatSenderChat(orThrow(this.chat, "banChatSenderChat").id, sender_chat_id, signal);
590
589
  }
591
590
  /**
592
591
  * Context-aware alias for `api.unbanChatSenderChat`. Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
@@ -1,20 +1,20 @@
1
1
  import { InlineKeyboardButton, KeyboardButton, LoginUrl } from "../platform.node.js";
2
2
  /**
3
- * Use this class to simplify building a keyboard (something like this:
3
+ * Use this class to simplify building a custom keyboard (something like this:
4
4
  * https://core.telegram.org/bots#keyboards).
5
5
  *
6
6
  * ```ts
7
- * // Build a keyboard:
7
+ * // Build a custom keyboard:
8
8
  * const keyboard = new Keyboard()
9
9
  * .text('A').text('B').row()
10
10
  * .text('C').text('D')
11
11
  *
12
12
  * // Now you can either pass it directly:
13
- * ctx.reply('Here is your keyboard!', {
13
+ * ctx.reply('Here is your custom keyboard!', {
14
14
  * reply_markup: keyboard
15
15
  * })
16
16
  * // Or if you need to specify more options in `reply_markup`:
17
- * ctx.reply('Here is your keyboard!', {
17
+ * ctx.reply('Here is your custom keyboard!', {
18
18
  * reply_markup: {
19
19
  * keyboard: keyboard.build(), // note the `build` call
20
20
  * one_time_keyboard: true,
@@ -23,12 +23,12 @@ import { InlineKeyboardButton, KeyboardButton, LoginUrl } from "../platform.node
23
23
  * ```
24
24
  *
25
25
  * Be sure to check out the
26
- * [documentation](https://grammy.dev/plugins/keyboard.html#keyboards) on
27
- * keyboards in grammY.
26
+ * [documentation](https://grammy.dev/plugins/keyboard.html#custom-keyboards) on
27
+ * custom keyboards in grammY.
28
28
  */
29
29
  export declare class Keyboard {
30
30
  /**
31
- * The nested array that holds the keyboard. It will be extended every time
31
+ * The nested array that holds the custom keyboard. It will be extended every time
32
32
  * you call one of the provided methods.
33
33
  */
34
34
  readonly keyboard: KeyboardButton[][];
@@ -82,8 +82,8 @@ export declare class Keyboard {
82
82
  */
83
83
  requestPoll(text: string, type?: "quiz" | "regular"): this;
84
84
  /**
85
- * Return the resulting keyboard that was built. May be called in the end if
86
- * necessary so you can specify more options in `reply_markup`.
85
+ * Return the resulting custom keyboard that was built. May be called in the
86
+ * end if necessary so you can specify more options in `reply_markup`.
87
87
  */
88
88
  build(): KeyboardButton[][];
89
89
  }
@@ -2,21 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InlineKeyboard = exports.Keyboard = void 0;
4
4
  /**
5
- * Use this class to simplify building a keyboard (something like this:
5
+ * Use this class to simplify building a custom keyboard (something like this:
6
6
  * https://core.telegram.org/bots#keyboards).
7
7
  *
8
8
  * ```ts
9
- * // Build a keyboard:
9
+ * // Build a custom keyboard:
10
10
  * const keyboard = new Keyboard()
11
11
  * .text('A').text('B').row()
12
12
  * .text('C').text('D')
13
13
  *
14
14
  * // Now you can either pass it directly:
15
- * ctx.reply('Here is your keyboard!', {
15
+ * ctx.reply('Here is your custom keyboard!', {
16
16
  * reply_markup: keyboard
17
17
  * })
18
18
  * // Or if you need to specify more options in `reply_markup`:
19
- * ctx.reply('Here is your keyboard!', {
19
+ * ctx.reply('Here is your custom keyboard!', {
20
20
  * reply_markup: {
21
21
  * keyboard: keyboard.build(), // note the `build` call
22
22
  * one_time_keyboard: true,
@@ -25,13 +25,13 @@ exports.InlineKeyboard = exports.Keyboard = void 0;
25
25
  * ```
26
26
  *
27
27
  * Be sure to check out the
28
- * [documentation](https://grammy.dev/plugins/keyboard.html#keyboards) on
29
- * keyboards in grammY.
28
+ * [documentation](https://grammy.dev/plugins/keyboard.html#custom-keyboards) on
29
+ * custom keyboards in grammY.
30
30
  */
31
31
  class Keyboard {
32
32
  constructor() {
33
33
  /**
34
- * The nested array that holds the keyboard. It will be extended every time
34
+ * The nested array that holds the custom keyboard. It will be extended every time
35
35
  * you call one of the provided methods.
36
36
  */
37
37
  Object.defineProperty(this, "keyboard", {
@@ -106,8 +106,8 @@ class Keyboard {
106
106
  return this.add({ text, request_poll: { type } });
107
107
  }
108
108
  /**
109
- * Return the resulting keyboard that was built. May be called in the end if
110
- * necessary so you can specify more options in `reply_markup`.
109
+ * Return the resulting custom keyboard that was built. May be called in the
110
+ * end if necessary so you can specify more options in `reply_markup`.
111
111
  */
112
112
  build() {
113
113
  return this.keyboard;
@@ -218,7 +218,13 @@ export declare function lazySession<S, C extends Context>(options?: SessionOptio
218
218
  */
219
219
  export declare class MemorySessionStorage<S> implements StorageAdapter<S> {
220
220
  private readonly timeToLive;
221
- private readonly storage;
221
+ /**
222
+ * Internally used `Map` instance that stores the session data
223
+ */
224
+ protected readonly storage: Map<string, {
225
+ session: S;
226
+ expires?: number | undefined;
227
+ }>;
222
228
  /**
223
229
  * Constructs a new memory session storage with the given time to live. Note
224
230
  * that this storage adapter will not store your data permanently.
@@ -227,6 +233,11 @@ export declare class MemorySessionStorage<S> implements StorageAdapter<S> {
227
233
  */
228
234
  constructor(timeToLive?: number);
229
235
  read(key: string): S | undefined;
236
+ /**
237
+ * Reads the values for all keys of the session storage, and returns them as
238
+ * an array.
239
+ */
240
+ readAll(): S[];
230
241
  write(key: string, value: S): void;
231
242
  private addExpiryDate;
232
243
  delete(key: string): void;
@@ -218,6 +218,9 @@ class MemorySessionStorage {
218
218
  writable: true,
219
219
  value: timeToLive
220
220
  });
221
+ /**
222
+ * Internally used `Map` instance that stores the session data
223
+ */
221
224
  Object.defineProperty(this, "storage", {
222
225
  enumerable: true,
223
226
  configurable: true,
@@ -235,6 +238,16 @@ class MemorySessionStorage {
235
238
  }
236
239
  return value.session;
237
240
  }
241
+ /**
242
+ * Reads the values for all keys of the session storage, and returns them as
243
+ * an array.
244
+ */
245
+ readAll() {
246
+ return Array
247
+ .from(this.storage.keys())
248
+ .map((key) => this.read(key))
249
+ .filter((value) => value !== undefined);
250
+ }
238
251
  write(key, value) {
239
252
  this.storage.set(key, this.addExpiryDate(value));
240
253
  }
package/out/core/api.d.ts CHANGED
@@ -460,16 +460,15 @@ export declare class Api<R extends RawApi = RawApi> {
460
460
  */
461
461
  setChatAdministratorCustomTitle(chat_id: number | string, user_id: number, custom_title: string, signal?: AbortSignal): Promise<true>;
462
462
  /**
463
- * Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
463
+ * Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
464
464
  *
465
465
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
466
466
  * @param sender_chat_id Unique identifier of the target sender chat
467
- * @param other Optional remaining parameters, confer the official reference below
468
467
  * @param signal Optional `AbortSignal` to cancel the request
469
468
  *
470
469
  * **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
471
470
  */
472
- banChatSenderChat(chat_id: number | string, sender_chat_id: number, other?: Other<R, "banChatSenderChat", "sender_chat_id">, signal?: AbortSignal): Promise<true>;
471
+ banChatSenderChat(chat_id: number | string, sender_chat_id: number, signal?: AbortSignal): Promise<true>;
473
472
  /**
474
473
  * Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
475
474
  *
@@ -959,7 +958,7 @@ export declare class Api<R extends RawApi = RawApi> {
959
958
  *
960
959
  * **Official reference:** https://core.telegram.org/bots/api#sendinvoice
961
960
  */
962
- sendInvoice(chat_id: number | string, title: string, description: string, payload: string, provider_token: string, currency: string, prices: readonly LabeledPrice[], other?: Other<R, "sendInvoice", "title" | "description" | "payload" | "provider_token" | "start_parameter" | "currency" | "prices">, signal?: AbortSignal): Promise<import("@grammyjs/types/message").Message.InvoiceMessage>;
961
+ sendInvoice(chat_id: number | string, title: string, description: string, payload: string, provider_token: string, currency: string, prices: readonly LabeledPrice[], other?: Other<R, "sendInvoice", "title" | "description" | "payload" | "provider_token" | "currency" | "prices">, signal?: AbortSignal): Promise<import("@grammyjs/types/message").Message.InvoiceMessage>;
963
962
  /**
964
963
  * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
965
964
  *
package/out/core/api.js CHANGED
@@ -526,17 +526,16 @@ class Api {
526
526
  return this.raw.setChatAdministratorCustomTitle({ chat_id, user_id, custom_title }, signal);
527
527
  }
528
528
  /**
529
- * Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
529
+ * Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
530
530
  *
531
531
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
532
532
  * @param sender_chat_id Unique identifier of the target sender chat
533
- * @param other Optional remaining parameters, confer the official reference below
534
533
  * @param signal Optional `AbortSignal` to cancel the request
535
534
  *
536
535
  * **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
537
536
  */
538
- banChatSenderChat(chat_id, sender_chat_id, other, signal) {
539
- return this.raw.banChatSenderChat({ chat_id, sender_chat_id, ...other }, signal);
537
+ banChatSenderChat(chat_id, sender_chat_id, signal) {
538
+ return this.raw.banChatSenderChat({ chat_id, sender_chat_id }, signal);
540
539
  }
541
540
  /**
542
541
  * Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
package/out/filter.js CHANGED
@@ -127,9 +127,7 @@ Permitted values are: ${permitted.map((k) => `'${k}'`).join(", ")}.`;
127
127
  const permitted = Object.keys(l2Obj);
128
128
  return `Invalid L3 filter '${l3}' given in '${filter.join(":")}'. ${permitted.length === 0
129
129
  ? `No further filtering is possible after '${l1}:${l2}'.`
130
- : `Permitted values are: ${permitted
131
- .map((k) => `'${k}'`)
132
- .join(", ")}.`}`;
130
+ : `Permitted values are: ${permitted.map((k) => `'${k}'`).join(", ")}.`}`;
133
131
  }
134
132
  if (n.length === 0)
135
133
  return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.5.0",
4
+ "version": "1.5.4",
5
5
  "author": "KnorpelSenf",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -23,7 +23,7 @@
23
23
  "contribs": "all-contributors"
24
24
  },
25
25
  "dependencies": {
26
- "@grammyjs/types": "^2.4.0",
26
+ "@grammyjs/types": "^2.4.5",
27
27
  "abort-controller": "^3.0.0",
28
28
  "debug": "^4.3.3",
29
29
  "node-fetch": "^2.6.5"