grammy 1.25.1 → 1.26.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.5-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.6-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-)
package/out/composer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type CallbackQueryContext, type ChatTypeContext, type ChosenInlineResultContext, type CommandContext, Context, type GameQueryContext, type HearsContext, type InlineQueryContext, type MaybeArray, type ReactionContext, type StringWithSuggestions } from "./context.js";
1
+ import { type CallbackQueryContext, type ChatTypeContext, type ChosenInlineResultContext, type CommandContext, Context, type GameQueryContext, type HearsContext, type InlineQueryContext, type MaybeArray, type PreCheckoutQueryContext, type ReactionContext, type ShippingQueryContext, type StringWithSuggestions } from "./context.js";
2
2
  import { type Filter, type FilterQuery } from "./filter.js";
3
3
  import { type Chat, type ReactionType, type ReactionTypeEmoji } from "./types.js";
4
4
  type MaybePromise<T> = T | Promise<T>;
@@ -412,10 +412,10 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
412
412
  inlineQuery(trigger: MaybeArray<string | RegExp>, ...middleware: Array<InlineQueryMiddleware<C>>): Composer<InlineQueryContext<C>>;
413
413
  /**
414
414
  * Registers middleware for the ChosenInlineResult by the given id or ids.
415
- * ChosenInlineResult represents a result of an inline query that was
416
- * chosen by the user and sent to their chat partner. Check out
417
- * https://core.telegram.org/bots/api#choseninlineresult to read more
418
- * about chosen inline results.
415
+ * ChosenInlineResult represents a result of an inline query that was chosen
416
+ * by the user and sent to their chat partner. Check out
417
+ * https://core.telegram.org/bots/api#choseninlineresult to read more about
418
+ * chosen inline results.
419
419
  *
420
420
  * ```ts
421
421
  * bot.chosenInlineResult('id', async ctx => {
@@ -428,6 +428,48 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
428
428
  * @param middleware The middleware to register
429
429
  */
430
430
  chosenInlineResult(resultId: MaybeArray<string | RegExp>, ...middleware: Array<ChosenInlineResultMiddleware<C>>): Composer<ChosenInlineResultContext<C>>;
431
+ /**
432
+ * Registers middleware for pre-checkout queries. Telegram sends a
433
+ * pre-checkout query to your bot whenever a user has confirmed their
434
+ * payment and shipping details. You bot will then receive all information
435
+ * about the order and has to respond within 10 seconds with a confirmation
436
+ * of whether everything is alright (goods are available, etc.) and the bot
437
+ * is ready to proceed with the order. Check out
438
+ * https://core.telegram.org/bots/api#precheckoutquery to read more about
439
+ * pre-checkout queries.
440
+ *
441
+ * ```ts
442
+ * bot.preCheckoutQuery('invoice_payload', async ctx => {
443
+ * // Answer the pre-checkout query, confer https://core.telegram.org/bots/api#answerprecheckoutquery
444
+ * await ctx.answerPreCheckoutQuery( ... )
445
+ * })
446
+ * ```
447
+ *
448
+ * @param trigger The string to look for in the invoice payload
449
+ * @param middleware The middleware to register
450
+ */
451
+ preCheckoutQuery(trigger: MaybeArray<string | RegExp>, ...middleware: Array<PreCheckoutQueryMiddleware<C>>): Composer<PreCheckoutQueryContext<C>>;
452
+ /**
453
+ * Registers middleware for shipping queries. If you sent an invoice
454
+ * requesting a shipping address and the parameter _is_flexible_ was
455
+ * specified, Telegram will send a shipping query to your bot whenever a
456
+ * user has confirmed their shipping details. You bot will then receive the
457
+ * shipping information and can respond with a confirmation of whether
458
+ * delivery to the specified address is possible. Check out
459
+ * https://core.telegram.org/bots/api#shippingquery to read more about
460
+ * shipping queries.
461
+ *
462
+ * ```ts
463
+ * bot.shippingQuery('invoice_payload', async ctx => {
464
+ * // Answer the shipping query, confer https://core.telegram.org/bots/api#answershippingquery
465
+ * await ctx.answerShippingQuery( ... )
466
+ * })
467
+ * ```
468
+ *
469
+ * @param trigger The string to look for in the invoice payload
470
+ * @param middleware The middleware to register
471
+ */
472
+ shippingQuery(trigger: MaybeArray<string | RegExp>, ...middleware: Array<ShippingQueryMiddleware<C>>): Composer<ShippingQueryContext<C>>;
431
473
  /**
432
474
  * > This is an advanced method of grammY.
433
475
  *
@@ -688,10 +730,28 @@ export type InlineQueryMiddleware<C extends Context> = Middleware<InlineQueryCon
688
730
  *
689
731
  * This helper type can be used to annotate middleware functions that are
690
732
  * defined in one place, so that they have the correct type when passed to
691
- * `bot.chosenInlineResult` in a different place. For instance, this allows for more
692
- * modular code where handlers are defined in separate files.
733
+ * `bot.chosenInlineResult` in a different place. For instance, this allows for
734
+ * more modular code where handlers are defined in separate files.
693
735
  */
694
736
  export type ChosenInlineResultMiddleware<C extends Context> = Middleware<ChosenInlineResultContext<C>>;
737
+ /**
738
+ * Type of the middleware that can be passed to `bot.preCheckoutQuery`.
739
+ *
740
+ * This helper type can be used to annotate middleware functions that are
741
+ * defined in one place, so that they have the correct type when passed to
742
+ * `bot.preCheckoutQuery` in a different place. For instance, this allows for
743
+ * more modular code where handlers are defined in separate files.
744
+ */
745
+ export type PreCheckoutQueryMiddleware<C extends Context> = Middleware<PreCheckoutQueryContext<C>>;
746
+ /**
747
+ * Type of the middleware that can be passed to `bot.shippingQuery`.
748
+ *
749
+ * This helper type can be used to annotate middleware functions that are
750
+ * defined in one place, so that they have the correct type when passed to
751
+ * `bot.shippingQuery` in a different place. For instance, this allows for more
752
+ * modular code where handlers are defined in separate files.
753
+ */
754
+ export type ShippingQueryMiddleware<C extends Context> = Middleware<ShippingQueryContext<C>>;
695
755
  /**
696
756
  * Type of the middleware that can be passed to `bot.chatType`.
697
757
  *
package/out/composer.js CHANGED
@@ -429,10 +429,10 @@ class Composer {
429
429
  }
430
430
  /**
431
431
  * Registers middleware for the ChosenInlineResult by the given id or ids.
432
- * ChosenInlineResult represents a result of an inline query that was
433
- * chosen by the user and sent to their chat partner. Check out
434
- * https://core.telegram.org/bots/api#choseninlineresult to read more
435
- * about chosen inline results.
432
+ * ChosenInlineResult represents a result of an inline query that was chosen
433
+ * by the user and sent to their chat partner. Check out
434
+ * https://core.telegram.org/bots/api#choseninlineresult to read more about
435
+ * chosen inline results.
436
436
  *
437
437
  * ```ts
438
438
  * bot.chosenInlineResult('id', async ctx => {
@@ -447,6 +447,52 @@ class Composer {
447
447
  chosenInlineResult(resultId, ...middleware) {
448
448
  return this.filter(context_js_1.Context.has.chosenInlineResult(resultId), ...middleware);
449
449
  }
450
+ /**
451
+ * Registers middleware for pre-checkout queries. Telegram sends a
452
+ * pre-checkout query to your bot whenever a user has confirmed their
453
+ * payment and shipping details. You bot will then receive all information
454
+ * about the order and has to respond within 10 seconds with a confirmation
455
+ * of whether everything is alright (goods are available, etc.) and the bot
456
+ * is ready to proceed with the order. Check out
457
+ * https://core.telegram.org/bots/api#precheckoutquery to read more about
458
+ * pre-checkout queries.
459
+ *
460
+ * ```ts
461
+ * bot.preCheckoutQuery('invoice_payload', async ctx => {
462
+ * // Answer the pre-checkout query, confer https://core.telegram.org/bots/api#answerprecheckoutquery
463
+ * await ctx.answerPreCheckoutQuery( ... )
464
+ * })
465
+ * ```
466
+ *
467
+ * @param trigger The string to look for in the invoice payload
468
+ * @param middleware The middleware to register
469
+ */
470
+ preCheckoutQuery(trigger, ...middleware) {
471
+ return this.filter(context_js_1.Context.has.preCheckoutQuery(trigger), ...middleware);
472
+ }
473
+ /**
474
+ * Registers middleware for shipping queries. If you sent an invoice
475
+ * requesting a shipping address and the parameter _is_flexible_ was
476
+ * specified, Telegram will send a shipping query to your bot whenever a
477
+ * user has confirmed their shipping details. You bot will then receive the
478
+ * shipping information and can respond with a confirmation of whether
479
+ * delivery to the specified address is possible. Check out
480
+ * https://core.telegram.org/bots/api#shippingquery to read more about
481
+ * shipping queries.
482
+ *
483
+ * ```ts
484
+ * bot.shippingQuery('invoice_payload', async ctx => {
485
+ * // Answer the shipping query, confer https://core.telegram.org/bots/api#answershippingquery
486
+ * await ctx.answerShippingQuery( ... )
487
+ * })
488
+ * ```
489
+ *
490
+ * @param trigger The string to look for in the invoice payload
491
+ * @param middleware The middleware to register
492
+ */
493
+ shippingQuery(trigger, ...middleware) {
494
+ return this.filter(context_js_1.Context.has.shippingQuery(trigger), ...middleware);
495
+ }
450
496
  filter(predicate, ...middleware) {
451
497
  const composer = new Composer(...middleware);
452
498
  this.branch(predicate, composer, pass);
package/out/context.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type Api, type Other as OtherApi } from "./core/api.js";
2
2
  import { type Methods, type RawApi } from "./core/client.js";
3
3
  import { type Filter, type FilterCore, type FilterQuery } from "./filter.js";
4
- import { type Chat, type ChatPermissions, type InlineQueryResult, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputPollOption, type LabeledPrice, type Message, type MessageEntity, type PassportElementError, type ReactionType, type ReactionTypeEmoji, type Update, type User, type UserFromGetMe } from "./types.js";
4
+ import { type Chat, type ChatPermissions, type InlineQueryResult, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputPaidMedia, type InputPollOption, type LabeledPrice, type Message, type MessageEntity, type PassportElementError, type ReactionType, type ReactionTypeEmoji, type Update, type User, type UserFromGetMe } from "./types.js";
5
5
  export type MaybeArray<T> = T | T[];
6
6
  export type StringWithSuggestions<S extends string> = (string & Record<never, never>) | S;
7
7
  type Other<M extends Methods<RawApi>, X extends string = never> = OtherApi<RawApi, M, X>;
@@ -34,9 +34,9 @@ interface StaticHas {
34
34
  */
35
35
  command<S extends string>(command: MaybeArray<StringWithSuggestions<S | "start" | "help" | "settings">>): <C extends Context>(ctx: C) => ctx is CommandContext<C>;
36
36
  /**
37
- * Generates a predicate function that can test context
38
- * objects for containing a message reaction update. This uses the same
39
- * logic as `bot.reaction`.
37
+ * Generates a predicate function that can test context objects for
38
+ * containing a message reaction update. This uses the same logic as
39
+ * `bot.reaction`.
40
40
  *
41
41
  * @param reaction The reaction to test against
42
42
  */
@@ -82,6 +82,24 @@ interface StaticHas {
82
82
  * @param trigger The string or regex to match
83
83
  */
84
84
  chosenInlineResult(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is ChosenInlineResultContext<C>;
85
+ /**
86
+ * Generates a predicate function that can test context objects for
87
+ * containing the given pre-checkout query, or for the pre-checkout query
88
+ * payload to match the given regular expression. This uses the same logic
89
+ * as `bot.preCheckoutQuery`.
90
+ *
91
+ * @param trigger The string or regex to match
92
+ */
93
+ preCheckoutQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is PreCheckoutQueryContext<C>;
94
+ /**
95
+ * Generates a predicate function that can test context objects for
96
+ * containing the given shipping query, or for the shipping query to match
97
+ * the given regular expression. This uses the same logic as
98
+ * `bot.shippingQuery`.
99
+ *
100
+ * @param trigger The string or regex to match
101
+ */
102
+ shippingQuery(trigger: MaybeArray<string | RegExp>): <C extends Context>(ctx: C) => ctx is ShippingQueryContext<C>;
85
103
  }
86
104
  /**
87
105
  * When your bot receives a message, Telegram sends an update object to your
@@ -248,11 +266,12 @@ export declare class Context implements RenamedUpdate {
248
266
  */
249
267
  get businessConnectionId(): string | undefined;
250
268
  /**
251
- * Get entities and their text. Extracts the text from `ctx.msg.text` or `ctx.msg.caption`.
252
- * Returns an empty array if one of `ctx.msg`, `ctx.msg.text`
253
- * or `ctx.msg.entities` is undefined.
269
+ * Get entities and their text. Extracts the text from `ctx.msg.text` or
270
+ * `ctx.msg.caption`. Returns an empty array if one of `ctx.msg`,
271
+ * `ctx.msg.text` or `ctx.msg.entities` is undefined.
254
272
  *
255
- * You can filter specific entity types by passing the `types` parameter. Example:
273
+ * You can filter specific entity types by passing the `types` parameter.
274
+ * Example:
256
275
  *
257
276
  * ```ts
258
277
  * ctx.entities() // Returns all entity types
@@ -400,13 +419,32 @@ export declare class Context implements RenamedUpdate {
400
419
  */
401
420
  hasInlineQuery(trigger: MaybeArray<string | RegExp>): this is InlineQueryContextCore;
402
421
  /**
403
- * Returns `true` if this context object contains the chosen inline result, or
404
- * if the contained chosen inline result matches the given regular expression. It
405
- * returns `false` otherwise. This uses the same logic as `bot.chosenInlineResult`.
422
+ * Returns `true` if this context object contains the chosen inline result,
423
+ * or if the contained chosen inline result matches the given regular
424
+ * expression. It returns `false` otherwise. This uses the same logic as
425
+ * `bot.chosenInlineResult`.
406
426
  *
407
427
  * @param trigger The string or regex to match
408
428
  */
409
429
  hasChosenInlineResult(trigger: MaybeArray<string | RegExp>): this is ChosenInlineResultContextCore;
430
+ /**
431
+ * Returns `true` if this context object contains the given pre-checkout
432
+ * query, or if the contained pre-checkout query matches the given regular
433
+ * expression. It returns `false` otherwise. This uses the same logic as
434
+ * `bot.preCheckoutQuery`.
435
+ *
436
+ * @param trigger The string or regex to match
437
+ */
438
+ hasPreCheckoutQuery(trigger: MaybeArray<string | RegExp>): this is PreCheckoutQueryContextCore;
439
+ /**
440
+ * Returns `true` if this context object contains the given shipping query,
441
+ * or if the contained shipping query matches the given regular expression.
442
+ * It returns `false` otherwise. This uses the same logic as
443
+ * `bot.shippingQuery`.
444
+ *
445
+ * @param trigger The string or regex to match
446
+ */
447
+ hasShippingQuery(trigger: MaybeArray<string | RegExp>): this is ShippingQueryContextCore;
410
448
  /**
411
449
  * Context-aware alias for `api.sendMessage`. Use this method to send text messages. On success, the sent Message is returned.
412
450
  *
@@ -439,7 +477,7 @@ export declare class Context implements RenamedUpdate {
439
477
  */
440
478
  forwardMessages(chat_id: number | string, message_ids: number[], other?: Other<"forwardMessages", "chat_id" | "from_chat_id" | "message_ids">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId[]>;
441
479
  /**
442
- * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
480
+ * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
443
481
  *
444
482
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
445
483
  * @param other Optional remaining parameters, confer the official reference below
@@ -449,7 +487,7 @@ export declare class Context implements RenamedUpdate {
449
487
  */
450
488
  copyMessage(chat_id: number | string, other?: Other<"copyMessage", "chat_id" | "from_chat_id" | "message_id">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId>;
451
489
  /**
452
- * Context-aware alias for `api.copyMessages`.Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
490
+ * Context-aware alias for `api.copyMessages`. Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
453
491
  *
454
492
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
455
493
  * @param message_ids A list of 1-100 identifiers of messages in the current chat to copy. The identifiers must be specified in a strictly increasing order.
@@ -577,6 +615,17 @@ export declare class Context implements RenamedUpdate {
577
615
  stopMessageLiveLocation(other?: Other<"stopMessageLiveLocation", "chat_id" | "message_id" | "inline_message_id">, signal?: AbortSignal): Promise<true | (Update.Edited & Message.CommonMessage & {
578
616
  location: import("@grammyjs/types/message.js").Location;
579
617
  })>;
618
+ /**
619
+ * Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media to channel chats. On success, the sent Message is returned.
620
+ *
621
+ * @param star_count The number of Telegram Stars that must be paid to buy access to the media
622
+ * @param media An array describing the media to be sent; up to 10 items
623
+ * @param other Optional remaining parameters, confer the official reference below
624
+ * @param signal Optional `AbortSignal` to cancel the request
625
+ *
626
+ * **Official reference:** https://core.telegram.org/bots/api#sendpaidmedia
627
+ */
628
+ sendPaidMedia(star_count: number, media: InputPaidMedia[], other?: Other<"sendPaidMedia", "chat_id" | "star_count" | "media">, signal?: AbortSignal): Promise<Message.PaidMediaMessage>;
580
629
  /**
581
630
  * Context-aware alias for `api.sendVenue`. Use this method to send information about a venue. On success, the sent Message is returned.
582
631
  *
@@ -1395,6 +1444,30 @@ type ChosenInlineResultContextCore = FilterCore<"chosen_inline_result">;
1395
1444
  * in separate files and still have the correct types.
1396
1445
  */
1397
1446
  export type ChosenInlineResultContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "chosen_inline_result">;
1447
+ type PreCheckoutQueryContextCore = FilterCore<"pre_checkout_query">;
1448
+ /**
1449
+ * Type of the context object that is available inside the handlers for
1450
+ * `bot.preCheckoutQuery`.
1451
+ *
1452
+ * This helper type can be used to narrow down context objects the same way how
1453
+ * annotate `bot.preCheckoutQuery` does it. This allows you to context objects in
1454
+ * middleware that is not directly passed to `bot.preCheckoutQuery`, hence not
1455
+ * inferring the correct type automatically. That way, handlers can be defined
1456
+ * in separate files and still have the correct types.
1457
+ */
1458
+ export type PreCheckoutQueryContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "pre_checkout_query">;
1459
+ type ShippingQueryContextCore = FilterCore<"shipping_query">;
1460
+ /**
1461
+ * Type of the context object that is available inside the handlers for
1462
+ * `bot.shippingQuery`.
1463
+ *
1464
+ * This helper type can be used to narrow down context objects the same way how
1465
+ * annotate `bot.shippingQuery` does it. This allows you to context objects in
1466
+ * middleware that is not directly passed to `bot.shippingQuery`, hence not
1467
+ * inferring the correct type automatically. That way, handlers can be defined
1468
+ * in separate files and still have the correct types.
1469
+ */
1470
+ export type ShippingQueryContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "shipping_query">;
1398
1471
  type ChatTypeContextCore<T extends Chat["type"]> = Record<"update", ChatTypeUpdate<T>> & ChatType<T> & Record<"chatId", number> & ChatFrom<T> & ChatTypeRecord<"msg", T> & AliasProps<ChatTypeUpdate<T>>;
1399
1472
  /**
1400
1473
  * Type of the context object that is available inside the handlers for
package/out/context.js CHANGED
@@ -151,6 +151,18 @@ const checker = {
151
151
  return (ctx) => hasChosenInlineResult(ctx) &&
152
152
  match(ctx, ctx.chosenInlineResult.result_id, trg);
153
153
  },
154
+ preCheckoutQuery(trigger) {
155
+ const hasPreCheckoutQuery = checker.filterQuery("pre_checkout_query");
156
+ const trg = triggerFn(trigger);
157
+ return (ctx) => hasPreCheckoutQuery(ctx) &&
158
+ match(ctx, ctx.preCheckoutQuery.invoice_payload, trg);
159
+ },
160
+ shippingQuery(trigger) {
161
+ const hasShippingQuery = checker.filterQuery("shipping_query");
162
+ const trg = triggerFn(trigger);
163
+ return (ctx) => hasShippingQuery(ctx) &&
164
+ match(ctx, ctx.shippingQuery.invoice_payload, trg);
165
+ },
154
166
  };
155
167
  // === Context class
156
168
  /**
@@ -581,15 +593,38 @@ class Context {
581
593
  return Context.has.inlineQuery(trigger)(this);
582
594
  }
583
595
  /**
584
- * Returns `true` if this context object contains the chosen inline result, or
585
- * if the contained chosen inline result matches the given regular expression. It
586
- * returns `false` otherwise. This uses the same logic as `bot.chosenInlineResult`.
596
+ * Returns `true` if this context object contains the chosen inline result,
597
+ * or if the contained chosen inline result matches the given regular
598
+ * expression. It returns `false` otherwise. This uses the same logic as
599
+ * `bot.chosenInlineResult`.
587
600
  *
588
601
  * @param trigger The string or regex to match
589
602
  */
590
603
  hasChosenInlineResult(trigger) {
591
604
  return Context.has.chosenInlineResult(trigger)(this);
592
605
  }
606
+ /**
607
+ * Returns `true` if this context object contains the given pre-checkout
608
+ * query, or if the contained pre-checkout query matches the given regular
609
+ * expression. It returns `false` otherwise. This uses the same logic as
610
+ * `bot.preCheckoutQuery`.
611
+ *
612
+ * @param trigger The string or regex to match
613
+ */
614
+ hasPreCheckoutQuery(trigger) {
615
+ return Context.has.preCheckoutQuery(trigger)(this);
616
+ }
617
+ /**
618
+ * Returns `true` if this context object contains the given shipping query,
619
+ * or if the contained shipping query matches the given regular expression.
620
+ * It returns `false` otherwise. This uses the same logic as
621
+ * `bot.shippingQuery`.
622
+ *
623
+ * @param trigger The string or regex to match
624
+ */
625
+ hasShippingQuery(trigger) {
626
+ return Context.has.shippingQuery(trigger)(this);
627
+ }
593
628
  // API
594
629
  /**
595
630
  * Context-aware alias for `api.sendMessage`. Use this method to send text messages. On success, the sent Message is returned.
@@ -629,7 +664,7 @@ class Context {
629
664
  return this.api.forwardMessages(chat_id, orThrow(this.chatId, "forwardMessages"), message_ids, other, signal);
630
665
  }
631
666
  /**
632
- * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
667
+ * Context-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
633
668
  *
634
669
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
635
670
  * @param other Optional remaining parameters, confer the official reference below
@@ -641,7 +676,7 @@ class Context {
641
676
  return this.api.copyMessage(chat_id, orThrow(this.chatId, "copyMessage"), orThrow(this.msgId, "copyMessage"), other, signal);
642
677
  }
643
678
  /**
644
- * Context-aware alias for `api.copyMessages`.Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
679
+ * Context-aware alias for `api.copyMessages`. Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
645
680
  *
646
681
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
647
682
  * @param message_ids A list of 1-100 identifiers of messages in the current chat to copy. The identifiers must be specified in a strictly increasing order.
@@ -795,6 +830,19 @@ class Context {
795
830
  ? this.api.stopMessageLiveLocationInline(inlineId, other)
796
831
  : this.api.stopMessageLiveLocation(orThrow(this.chatId, "stopMessageLiveLocation"), orThrow(this.msgId, "stopMessageLiveLocation"), other, signal);
797
832
  }
833
+ /**
834
+ * Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media to channel chats. On success, the sent Message is returned.
835
+ *
836
+ * @param star_count The number of Telegram Stars that must be paid to buy access to the media
837
+ * @param media An array describing the media to be sent; up to 10 items
838
+ * @param other Optional remaining parameters, confer the official reference below
839
+ * @param signal Optional `AbortSignal` to cancel the request
840
+ *
841
+ * **Official reference:** https://core.telegram.org/bots/api#sendpaidmedia
842
+ */
843
+ sendPaidMedia(star_count, media, other, signal) {
844
+ return this.api.sendPaidMedia(orThrow(this.chatId, "sendPaidMedia"), star_count, media, other, signal);
845
+ }
798
846
  /**
799
847
  * Context-aware alias for `api.sendVenue`. Use this method to send information about a venue. On success, the sent Message is returned.
800
848
  *
package/out/core/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BotCommand, type ChatPermissions, type InlineQueryResult, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputPollOption, type InputSticker, type LabeledPrice, type MaskPosition, type PassportElementError, type ReactionType } from "../types.js";
1
+ import { type BotCommand, type ChatPermissions, type InlineQueryResult, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputPaidMedia, type InputPollOption, type InputSticker, type LabeledPrice, type MaskPosition, type PassportElementError, type ReactionType } from "../types.js";
2
2
  import { type ApiClientOptions, type Methods, type Payload, type RawApi, type Transformer, type TransformerConsumer, type WebhookReplyEnvelope } from "./client.js";
3
3
  /**
4
4
  * Helper type to derive remaining properties of a given API method call M,
@@ -179,7 +179,7 @@ export declare class Api<R extends RawApi = RawApi> {
179
179
  */
180
180
  forwardMessages(chat_id: number | string, from_chat_id: number | string, message_ids: number[], other?: Other<R, "forwardMessages", "chat_id" | "from_chat_id" | "message_ids">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId[]>;
181
181
  /**
182
- * Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
182
+ * Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
183
183
  *
184
184
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
185
185
  * @param from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
@@ -191,7 +191,7 @@ export declare class Api<R extends RawApi = RawApi> {
191
191
  */
192
192
  copyMessage(chat_id: number | string, from_chat_id: number | string, message_id: number, other?: Other<R, "copyMessage", "chat_id" | "from_chat_id" | "message_id">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").MessageId>;
193
193
  /**
194
- * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
194
+ * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
195
195
  *
196
196
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
197
197
  * @param from_chat_id Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername)
@@ -359,6 +359,18 @@ export declare class Api<R extends RawApi = RawApi> {
359
359
  stopMessageLiveLocationInline(inline_message_id: string, other?: Other<R, "stopMessageLiveLocation", "chat_id" | "message_id" | "inline_message_id">, signal?: AbortSignal): Promise<true | (import("@grammyjs/types/update.js").Update.Edited & import("@grammyjs/types/message.js").Message.CommonMessage & {
360
360
  location: import("@grammyjs/types/message.js").Location;
361
361
  })>;
362
+ /**
363
+ * Use this method to send paid media to channel chats. On success, the sent Message is returned.
364
+ *
365
+ * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
366
+ * @param star_count The number of Telegram Stars that must be paid to buy access to the media
367
+ * @param media An array describing the media to be sent; up to 10 items
368
+ * @param other Optional remaining parameters, confer the official reference below
369
+ * @param signal Optional `AbortSignal` to cancel the request
370
+ *
371
+ * **Official reference:** https://core.telegram.org/bots/api#sendpaidmedia
372
+ */
373
+ sendPaidMedia(chat_id: number | string, star_count: number, media: InputPaidMedia[], other?: Other<R, "sendPaidMedia", "chat_id" | "star_count" | "media">, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").Message.PaidMediaMessage>;
362
374
  /**
363
375
  * Use this method to send information about a venue. On success, the sent Message is returned.
364
376
  *
package/out/core/api.js CHANGED
@@ -173,7 +173,7 @@ class Api {
173
173
  }, signal);
174
174
  }
175
175
  /**
176
- * Use this method to copy messages of any kind. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
176
+ * Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
177
177
  *
178
178
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
179
179
  * @param from_chat_id Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
@@ -187,7 +187,7 @@ class Api {
187
187
  return this.raw.copyMessage({ chat_id, from_chat_id, message_id, ...other }, signal);
188
188
  }
189
189
  /**
190
- * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
190
+ * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.
191
191
  *
192
192
  * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
193
193
  * @param from_chat_id Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername)
@@ -380,6 +380,20 @@ class Api {
380
380
  stopMessageLiveLocationInline(inline_message_id, other, signal) {
381
381
  return this.raw.stopMessageLiveLocation({ inline_message_id, ...other }, signal);
382
382
  }
383
+ /**
384
+ * Use this method to send paid media to channel chats. On success, the sent Message is returned.
385
+ *
386
+ * @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
387
+ * @param star_count The number of Telegram Stars that must be paid to buy access to the media
388
+ * @param media An array describing the media to be sent; up to 10 items
389
+ * @param other Optional remaining parameters, confer the official reference below
390
+ * @param signal Optional `AbortSignal` to cancel the request
391
+ *
392
+ * **Official reference:** https://core.telegram.org/bots/api#sendpaidmedia
393
+ */
394
+ sendPaidMedia(chat_id, star_count, media, other, signal) {
395
+ return this.raw.sendPaidMedia({ chat_id, star_count, media, ...other }, signal);
396
+ }
383
397
  /**
384
398
  * Use this method to send information about a venue. On success, the sent Message is returned.
385
399
  *
package/out/filter.d.ts CHANGED
@@ -91,6 +91,7 @@ declare const UPDATE_KEYS: {
91
91
  readonly poll: {};
92
92
  readonly venue: {};
93
93
  readonly location: {};
94
+ readonly paid_media: {};
94
95
  readonly entities: {
95
96
  readonly mention: {};
96
97
  readonly hashtag: {};
@@ -213,6 +214,7 @@ declare const UPDATE_KEYS: {
213
214
  readonly poll: {};
214
215
  readonly venue: {};
215
216
  readonly location: {};
217
+ readonly paid_media: {};
216
218
  readonly entities: {
217
219
  readonly mention: {};
218
220
  readonly hashtag: {};
@@ -303,6 +305,7 @@ declare const UPDATE_KEYS: {
303
305
  readonly poll: {};
304
306
  readonly venue: {};
305
307
  readonly location: {};
308
+ readonly paid_media: {};
306
309
  readonly entities: {
307
310
  readonly mention: {};
308
311
  readonly hashtag: {};
@@ -393,6 +396,7 @@ declare const UPDATE_KEYS: {
393
396
  readonly poll: {};
394
397
  readonly venue: {};
395
398
  readonly location: {};
399
+ readonly paid_media: {};
396
400
  readonly entities: {
397
401
  readonly mention: {};
398
402
  readonly hashtag: {};
@@ -519,6 +523,7 @@ declare const UPDATE_KEYS: {
519
523
  readonly poll: {};
520
524
  readonly venue: {};
521
525
  readonly location: {};
526
+ readonly paid_media: {};
522
527
  readonly entities: {
523
528
  readonly mention: {};
524
529
  readonly hashtag: {};
@@ -641,6 +646,7 @@ declare const UPDATE_KEYS: {
641
646
  readonly poll: {};
642
647
  readonly venue: {};
643
648
  readonly location: {};
649
+ readonly paid_media: {};
644
650
  readonly entities: {
645
651
  readonly mention: {};
646
652
  readonly hashtag: {};
package/out/filter.js CHANGED
@@ -265,6 +265,7 @@ const COMMON_MESSAGE_KEYS = {
265
265
  poll: {},
266
266
  venue: {},
267
267
  location: {},
268
+ paid_media: {},
268
269
  entities: ENTITY_KEYS,
269
270
  caption_entities: ENTITY_KEYS,
270
271
  caption: {},
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- 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";
2
+ 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 InputPaidMedia as InputPaidMediaF, type InputPaidMediaPhoto as InputPaidMediaPhotoF, type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF } from "@grammyjs/types";
3
3
  import { type ReadStream } from "fs";
4
4
  export * from "@grammyjs/types";
5
5
  /** A value, or a potentially async function supplying that value */
@@ -69,3 +69,11 @@ export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
69
69
  export type InputMediaAudio = InputMediaAudioF<InputFile>;
70
70
  /** Represents a general file to be sent. */
71
71
  export type InputMediaDocument = InputMediaDocumentF<InputFile>;
72
+ /** This object describes the paid media to be sent. Currently, it can be one of
73
+ - InputPaidMediaPhoto
74
+ - InputPaidMediaVideo */
75
+ export type InputPaidMedia = InputPaidMediaF<InputFile>;
76
+ /** The paid media to send is a photo. */
77
+ export type InputPaidMediaPhoto = InputPaidMediaPhotoF<InputFile>;
78
+ /** The paid media to send is a video. */
79
+ export type InputPaidMediaVideo = InputPaidMediaVideoF<InputFile>;
package/out/web.mjs CHANGED
@@ -210,6 +210,7 @@ const COMMON_MESSAGE_KEYS = {
210
210
  poll: {},
211
211
  venue: {},
212
212
  location: {},
213
+ paid_media: {},
213
214
  entities: ENTITY_KEYS,
214
215
  caption_entities: ENTITY_KEYS,
215
216
  caption: {},
@@ -471,6 +472,16 @@ const checker = {
471
472
  const hasChosenInlineResult = checker.filterQuery("chosen_inline_result");
472
473
  const trg = triggerFn(trigger);
473
474
  return (ctx)=>hasChosenInlineResult(ctx) && match(ctx, ctx.chosenInlineResult.result_id, trg);
475
+ },
476
+ preCheckoutQuery (trigger) {
477
+ const hasPreCheckoutQuery = checker.filterQuery("pre_checkout_query");
478
+ const trg = triggerFn(trigger);
479
+ return (ctx)=>hasPreCheckoutQuery(ctx) && match(ctx, ctx.preCheckoutQuery.invoice_payload, trg);
480
+ },
481
+ shippingQuery (trigger) {
482
+ const hasShippingQuery = checker.filterQuery("shipping_query");
483
+ const trg = triggerFn(trigger);
484
+ return (ctx)=>hasShippingQuery(ctx) && match(ctx, ctx.shippingQuery.invoice_payload, trg);
474
485
  }
475
486
  };
476
487
  class Context {
@@ -685,6 +696,12 @@ class Context {
685
696
  hasChosenInlineResult(trigger) {
686
697
  return Context.has.chosenInlineResult(trigger)(this);
687
698
  }
699
+ hasPreCheckoutQuery(trigger) {
700
+ return Context.has.preCheckoutQuery(trigger)(this);
701
+ }
702
+ hasShippingQuery(trigger) {
703
+ return Context.has.shippingQuery(trigger)(this);
704
+ }
688
705
  reply(text, other, signal) {
689
706
  return this.api.sendMessage(orThrow(this.chatId, "sendMessage"), text, {
690
707
  business_connection_id: this.businessConnectionId,
@@ -765,6 +782,9 @@ class Context {
765
782
  const inlineId = this.inlineMessageId;
766
783
  return inlineId !== undefined ? this.api.stopMessageLiveLocationInline(inlineId, other) : this.api.stopMessageLiveLocation(orThrow(this.chatId, "stopMessageLiveLocation"), orThrow(this.msgId, "stopMessageLiveLocation"), other, signal);
767
784
  }
785
+ sendPaidMedia(star_count, media, other, signal) {
786
+ return this.api.sendPaidMedia(orThrow(this.chatId, "sendPaidMedia"), star_count, media, other, signal);
787
+ }
768
788
  replyWithVenue(latitude, longitude, title, address, other, signal) {
769
789
  return this.api.sendVenue(orThrow(this.chatId, "sendVenue"), latitude, longitude, title, address, {
770
790
  business_connection_id: this.businessConnectionId,
@@ -1173,6 +1193,12 @@ class Composer {
1173
1193
  chosenInlineResult(resultId, ...middleware) {
1174
1194
  return this.filter(Context.has.chosenInlineResult(resultId), ...middleware);
1175
1195
  }
1196
+ preCheckoutQuery(trigger, ...middleware) {
1197
+ return this.filter(Context.has.preCheckoutQuery(trigger), ...middleware);
1198
+ }
1199
+ shippingQuery(trigger, ...middleware) {
1200
+ return this.filter(Context.has.shippingQuery(trigger), ...middleware);
1201
+ }
1176
1202
  filter(predicate, ...middleware) {
1177
1203
  const composer = new Composer(...middleware);
1178
1204
  this.branch(predicate, composer, pass);
@@ -2541,6 +2567,14 @@ class Api {
2541
2567
  ...other
2542
2568
  }, signal);
2543
2569
  }
2570
+ sendPaidMedia(chat_id, star_count, media, other, signal) {
2571
+ return this.raw.sendPaidMedia({
2572
+ chat_id,
2573
+ star_count,
2574
+ media,
2575
+ ...other
2576
+ }, signal);
2577
+ }
2544
2578
  sendVenue(chat_id, latitude, longitude, title, address, other, signal) {
2545
2579
  return this.raw.sendVenue({
2546
2580
  chat_id,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "grammy",
3
3
  "description": "The Telegram Bot Framework.",
4
- "version": "1.25.1",
4
+ "version": "1.26.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.9.0",
20
+ "@grammyjs/types": "3.10.0",
21
21
  "abort-controller": "^3.0.0",
22
22
  "debug": "^4.3.4",
23
23
  "node-fetch": "^2.7.0"