grammy 1.30.0 β†’ 1.31.0

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.9-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-)
@@ -142,7 +142,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
142
142
  <table>
143
143
  <tbody>
144
144
  <tr>
145
- <td align="center" valign="top" width="11.11%"><a href="https://github.com/KnorpelSenf"><img src="https://avatars.githubusercontent.com/u/12952387?v=4?s=100" width="100px;" alt="KnorpelSenf"/><br /><sub><b>KnorpelSenf</b></sub></a><br /><a href="#ideas-KnorpelSenf" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Code">πŸ’»</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Documentation">πŸ“–</a> <a href="#design-KnorpelSenf" title="Design">🎨</a> <a href="#example-KnorpelSenf" title="Examples">πŸ’‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Tests">⚠️</a> <a href="#plugin-KnorpelSenf" title="Plugin/utility libraries">πŸ”Œ</a> <a href="#platform-KnorpelSenf" title="Packaging/porting to new platform">πŸ“¦</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AKnorpelSenf" title="Reviewed Pull Requests">πŸ‘€</a> <a href="#mentoring-KnorpelSenf" title="Mentoring">πŸ§‘β€πŸ«</a> <a href="#projectManagement-KnorpelSenf" title="Project Management">πŸ“†</a> <a href="#infra-KnorpelSenf" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="#audio-KnorpelSenf" title="Audio">πŸ”Š</a> <a href="#a11y-KnorpelSenf" title="Accessibility">️️️️♿️</a></td>
145
+ <td align="center" valign="top" width="11.11%"><a href="https://github.com/KnorpelSenf"><img src="https://avatars.githubusercontent.com/u/12952387?v=4?s=100" width="100px;" alt="KnorpelSenf"/><br /><sub><b>KnorpelSenf</b></sub></a><br /><a href="#ideas-KnorpelSenf" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Code">πŸ’»</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Documentation">πŸ“–</a> <a href="#design-KnorpelSenf" title="Design">🎨</a> <a href="#example-KnorpelSenf" title="Examples">πŸ’‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Tests">⚠️</a> <a href="#plugin-KnorpelSenf" title="Plugin/utility libraries">πŸ”Œ</a> <a href="#platform-KnorpelSenf" title="Packaging/porting to new platform">πŸ“¦</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AKnorpelSenf" title="Reviewed Pull Requests">πŸ‘€</a> <a href="#mentoring-KnorpelSenf" title="Mentoring">πŸ§‘β€πŸ«</a> <a href="#projectManagement-KnorpelSenf" title="Project Management">πŸ“†</a> <a href="#infra-KnorpelSenf" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="#audio-KnorpelSenf" title="Audio">πŸ”Š</a> <a href="#a11y-KnorpelSenf" title="Accessibility">️️️️♿️</a> <a href="#talk-KnorpelSenf" title="Talks">πŸ“’</a></td>
146
146
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/HeeroML"><img src="https://avatars.githubusercontent.com/u/42873000?v=4?s=100" width="100px;" alt="Heero"/><br /><sub><b>Heero</b></sub></a><br /><a href="#plugin-HeeroML" title="Plugin/utility libraries">πŸ”Œ</a> <a href="#userTesting-HeeroML" title="User Testing">πŸ““</a> <a href="#example-HeeroML" title="Examples">πŸ’‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=HeeroML" title="Documentation">πŸ“–</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AHeeroML" title="Reviewed Pull Requests">πŸ‘€</a> <a href="https://github.com/grammyjs/grammY/commits?author=HeeroML" title="Code">πŸ’»</a> <a href="#ideas-HeeroML" title="Ideas, Planning, & Feedback">πŸ€”</a></td>
147
147
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/wojpawlik"><img src="https://avatars.githubusercontent.com/u/23058303?v=4?s=100" width="100px;" alt="Wojciech Pawlik"/><br /><sub><b>Wojciech Pawlik</b></sub></a><br /><a href="#ideas-wojpawlik" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Awojpawlik" title="Reviewed Pull Requests">πŸ‘€</a> <a href="#infra-wojpawlik" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="#platform-wojpawlik" title="Packaging/porting to new platform">πŸ“¦</a> <a href="#tool-wojpawlik" title="Tools">πŸ”§</a></td>
148
148
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/MegaITA"><img src="https://avatars.githubusercontent.com/u/32493080?v=4?s=100" width="100px;" alt="Alessandro Bertozzi"/><br /><sub><b>Alessandro Bertozzi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=MegaITA" title="Documentation">πŸ“–</a></td>
@@ -309,6 +309,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
309
309
  <tr>
310
310
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/rayz1065"><img src="https://avatars.githubusercontent.com/u/37779815?v=4?s=100" width="100px;" alt="rayz"/><br /><sub><b>rayz</b></sub></a><br /><a href="#question-rayz1065" title="Answering Questions">πŸ’¬</a> <a href="#ideas-rayz1065" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/grammyjs/grammY/commits?author=rayz1065" title="Code">πŸ’»</a></td>
311
311
  <td align="center" valign="top" width="11.11%"><a href="https://github.com/z44d"><img src="https://avatars.githubusercontent.com/u/162994967?v=4?s=100" width="100px;" alt="Zaid"/><br /><sub><b>Zaid</b></sub></a><br /><a href="#tool-z44d" title="Tools">πŸ”§</a></td>
312
+ <td align="center" valign="top" width="11.11%"><a href="https://github.com/matmilbury"><img src="https://avatars.githubusercontent.com/u/73319876?v=4?s=100" width="100px;" alt="Mat Milbury"/><br /><sub><b>Mat Milbury</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Amatmilbury" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=matmilbury" title="Code">πŸ’»</a></td>
313
+ <td align="center" valign="top" width="11.11%"><a href="https://lao.sb/"><img src="https://avatars.githubusercontent.com/u/2545261?v=4?s=100" width="100px;" alt="Shibo Lyu"/><br /><sub><b>Shibo Lyu</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=laosb" title="Code">πŸ’»</a></td>
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
+ <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
+ <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>
312
317
  </tr>
313
318
  </tbody>
314
319
  </table>
package/out/bot.d.ts CHANGED
@@ -21,11 +21,11 @@ export interface PollingOptions {
21
21
  timeout?: number;
22
22
  /**
23
23
  * A list of the update types you want your bot to receive. For example,
24
- * specify [β€œmessage”, β€œedited_channel_post”, β€œcallback_query”] to only
24
+ * specify ["message", "edited_channel_post", "callback_query"] to only
25
25
  * receive updates of these types. See Update for a complete list of
26
26
  * available update types. Specify an empty list to receive all update types
27
- * except chat_member (default). If not specified, the previous setting will
28
- * be used.
27
+ * except chat_member, message_reaction, and message_reaction_count
28
+ * (default). If not specified, the previous setting will be used.
29
29
  *
30
30
  * Please note that this parameter doesn't affect updates created before the
31
31
  * call to the getUpdates, so unwanted updates may be received for a short
@@ -43,6 +43,9 @@ export interface PollingOptions {
43
43
  * fetched. The bot information `bot.botInfo` will be available when the
44
44
  * function is run. For convenience, the callback function receives the
45
45
  * value of `bot.botInfo` as an argument.
46
+ *
47
+ * When this function is invoked, the bot already signals that it is
48
+ * running. In other words, `bot.isRunning()` already returns true.
46
49
  */
47
50
  onStart?: (botInfo: UserFromGetMe) => void | Promise<void>;
48
51
  }
@@ -260,6 +263,21 @@ export declare class Bot<C extends Context = Context, A extends Api = Api> exten
260
263
  * > for the promise returned by `bot.start()` to resolve.
261
264
  */
262
265
  stop(): Promise<void>;
266
+ /**
267
+ * Returns true if the bot is currently running via built-in long polling,
268
+ * and false otherwise.
269
+ *
270
+ * If this method returns true, it means that `bot.start()` has been called,
271
+ * and that the bot has neither crashed nor was it stopped via a call to
272
+ * `bot.stop()`. This also means that you cannot use this method to check if
273
+ * a webhook server is running, or if grammY runner was started.
274
+ *
275
+ * Note that this method will already begin to return true even before the
276
+ * call to `bot.start()` has completed its initialization phase (and hence
277
+ * before `bot.isInited()` returns true). By extension, this method
278
+ * returns true before `onStart` callback of `bot.start()` is invoked.
279
+ */
280
+ isRunning(): boolean;
263
281
  /**
264
282
  * Sets the bots error handler that is used during long polling.
265
283
  *
package/out/bot.js CHANGED
@@ -346,6 +346,23 @@ a known bot info object.");
346
346
  debug("Bot is not running!");
347
347
  }
348
348
  }
349
+ /**
350
+ * Returns true if the bot is currently running via built-in long polling,
351
+ * and false otherwise.
352
+ *
353
+ * If this method returns true, it means that `bot.start()` has been called,
354
+ * and that the bot has neither crashed nor was it stopped via a call to
355
+ * `bot.stop()`. This also means that you cannot use this method to check if
356
+ * a webhook server is running, or if grammY runner was started.
357
+ *
358
+ * Note that this method will already begin to return true even before the
359
+ * call to `bot.start()` has completed its initialization phase (and hence
360
+ * before `bot.isInited()` returns true). By extension, this method
361
+ * returns true before `onStart` callback of `bot.start()` is invoked.
362
+ */
363
+ isRunning() {
364
+ return this.pollingRunning;
365
+ }
349
366
  /**
350
367
  * Sets the bots error handler that is used during long polling.
351
368
  *
@@ -370,17 +387,22 @@ a known bot info object.");
370
387
  const limit = options === null || options === void 0 ? void 0 : options.limit;
371
388
  const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 30; // seconds
372
389
  let allowed_updates = (_b = options === null || options === void 0 ? void 0 : options.allowed_updates) !== null && _b !== void 0 ? _b : []; // reset to default if unspecified
373
- while (this.pollingRunning) {
374
- // fetch updates
375
- const updates = await this.fetchUpdates({ limit, timeout, allowed_updates });
376
- // check if polling stopped
377
- if (updates === undefined)
378
- break;
379
- // handle updates
380
- await this.handleUpdates(updates);
381
- // Telegram uses the last setting if `allowed_updates` is omitted so
382
- // we can save some traffic by only sending it in the first request
383
- allowed_updates = undefined;
390
+ try {
391
+ while (this.pollingRunning) {
392
+ // fetch updates
393
+ const updates = await this.fetchUpdates({ limit, timeout, allowed_updates });
394
+ // check if polling stopped
395
+ if (updates === undefined)
396
+ break;
397
+ // handle updates
398
+ await this.handleUpdates(updates);
399
+ // Telegram uses the last setting if `allowed_updates` is omitted so
400
+ // we can save some traffic by only sending it in the first request
401
+ allowed_updates = undefined;
402
+ }
403
+ }
404
+ finally {
405
+ this.pollingRunning = false;
384
406
  }
385
407
  }
386
408
  /**
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
@@ -163,7 +163,7 @@ export declare const InlineQueryResultBuilder: {
163
163
  * @param options Remaining options
164
164
  */
165
165
  game(id: string, game_short_name: string, options?: InlineQueryResultOptions<InlineQueryResultGame, "game_short_name">): {
166
- reply_markup?: import("@grammyjs/types/markup.js").InlineKeyboardMarkup;
166
+ reply_markup?: import("@grammyjs/types/markup.js").InlineKeyboardMarkup | undefined;
167
167
  type: string;
168
168
  id: string;
169
169
  game_short_name: string;
@@ -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
@@ -12,6 +12,14 @@ const callbackAdapter = (update, callback, header, unauthorized = () => callback
12
12
  });
13
13
  const adapters = { ...frameworks_js_1.adapters, callback: callbackAdapter };
14
14
  function webhookCallback(bot, adapter = platform_node_js_1.defaultAdapter, onTimeout, timeoutMilliseconds, secretToken) {
15
+ if (bot.isRunning()) {
16
+ throw new Error("Bot is already running via long polling, the webhook setup won't receive any updates!");
17
+ }
18
+ else {
19
+ bot.start = () => {
20
+ throw new Error("You already started the bot via webhooks, calling `bot.start()` starts the bot with long polling and this will prevent your webhook setup from receiving any updates!");
21
+ };
22
+ }
15
23
  const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10000, secretToken: token, } = typeof onTimeout === "object"
16
24
  ? onTimeout
17
25
  : { onTimeout, timeoutMilliseconds, secretToken };
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
package/out/web.mjs CHANGED
@@ -3465,6 +3465,9 @@ a known bot info object.");
3465
3465
  debug2("Bot is not running!");
3466
3466
  }
3467
3467
  }
3468
+ isRunning() {
3469
+ return this.pollingRunning;
3470
+ }
3468
3471
  catch(errorHandler) {
3469
3472
  this.errorHandler = errorHandler;
3470
3473
  }
@@ -3472,15 +3475,19 @@ a known bot info object.");
3472
3475
  const limit = options?.limit;
3473
3476
  const timeout = options?.timeout ?? 30;
3474
3477
  let allowed_updates = options?.allowed_updates ?? [];
3475
- while(this.pollingRunning){
3476
- const updates = await this.fetchUpdates({
3477
- limit,
3478
- timeout,
3479
- allowed_updates
3480
- });
3481
- if (updates === undefined) break;
3482
- await this.handleUpdates(updates);
3483
- allowed_updates = undefined;
3478
+ try {
3479
+ while(this.pollingRunning){
3480
+ const updates = await this.fetchUpdates({
3481
+ limit,
3482
+ timeout,
3483
+ allowed_updates
3484
+ });
3485
+ if (updates === undefined) break;
3486
+ await this.handleUpdates(updates);
3487
+ allowed_updates = undefined;
3488
+ }
3489
+ } finally{
3490
+ this.pollingRunning = false;
3484
3491
  }
3485
3492
  }
3486
3493
  async fetchUpdates({ limit, timeout, allowed_updates }) {
@@ -4150,9 +4157,9 @@ class InlineKeyboard {
4150
4157
  static webApp(text, url) {
4151
4158
  return {
4152
4159
  text,
4153
- web_app: {
4160
+ web_app: typeof url === "string" ? {
4154
4161
  url
4155
- }
4162
+ } : url
4156
4163
  };
4157
4164
  }
4158
4165
  login(text, loginUrl) {
@@ -4193,6 +4200,17 @@ class InlineKeyboard {
4193
4200
  switch_inline_query_chosen_chat: query
4194
4201
  };
4195
4202
  }
4203
+ copyText(text, copyText) {
4204
+ return this.add(InlineKeyboard.copyText(text, copyText));
4205
+ }
4206
+ static copyText(text, copyText) {
4207
+ return {
4208
+ text,
4209
+ copy_text: typeof copyText === "string" ? {
4210
+ text: copyText
4211
+ } : copyText
4212
+ };
4213
+ }
4196
4214
  game(text) {
4197
4215
  return this.add(InlineKeyboard.game(text));
4198
4216
  }
@@ -4899,6 +4917,13 @@ const adapters1 = {
4899
4917
  callback: callbackAdapter
4900
4918
  };
4901
4919
  function webhookCallback(bot, adapter = defaultAdapter, onTimeout, timeoutMilliseconds, secretToken) {
4920
+ if (bot.isRunning()) {
4921
+ throw new Error("Bot is already running via long polling, the webhook setup won't receive any updates!");
4922
+ } else {
4923
+ bot.start = ()=>{
4924
+ throw new Error("You already started the bot via webhooks, calling `bot.start()` starts the bot with long polling and this will prevent your webhook setup from receiving any updates!");
4925
+ };
4926
+ }
4902
4927
  const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10_000, secretToken: token } = typeof onTimeout === "object" ? onTimeout : {
4903
4928
  onTimeout,
4904
4929
  timeoutMilliseconds,
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.0",
4
+ "version": "1.31.0",
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"