grammy 1.25.1 → 1.25.2
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/out/composer.d.ts +59 -1
- package/out/composer.js +44 -0
- package/out/context.d.ts +58 -0
- package/out/context.js +32 -0
- package/out/web.mjs +22 -0
- package/package.json +1 -1
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>;
|
|
@@ -428,6 +428,46 @@ 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 pre-checkout
|
|
433
|
+
* query to your bot whenever a user has confirmed their payment and shipping
|
|
434
|
+
* details. You bot will then receive all information about the order and
|
|
435
|
+
* has to respond within 10 seconds with a confirmation of whether everything
|
|
436
|
+
* is alright (goods are available, etc.) and the bot is ready to proceed
|
|
437
|
+
* with the order. Check out https://core.telegram.org/bots/api#precheckoutquery
|
|
438
|
+
* to read more about pre-checkout queries.
|
|
439
|
+
*
|
|
440
|
+
* ```ts
|
|
441
|
+
* bot.preCheckoutQuery('invoice_payload', async ctx => {
|
|
442
|
+
* // Answer the pre-checkout query, confer https://core.telegram.org/bots/api#answerprecheckoutquery
|
|
443
|
+
* await ctx.answerPreCheckoutQuery( ... )
|
|
444
|
+
* })
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* @param trigger The string to look for in the invoice payload
|
|
448
|
+
* @param middleware The middleware to register
|
|
449
|
+
*/
|
|
450
|
+
preCheckoutQuery(trigger: MaybeArray<string | RegExp>, ...middleware: Array<PreCheckoutQueryMiddleware<C>>): Composer<PreCheckoutQueryContext<C>>;
|
|
451
|
+
/**
|
|
452
|
+
* Registers middleware for shipping queries. If you sent an invoice requesting
|
|
453
|
+
* a shipping address and the parameter _is_flexible_ was specified, Telegram
|
|
454
|
+
* will send a shipping query to your bot whenever a user has confirmed their
|
|
455
|
+
* shipping details. You bot will then receive the shipping information and
|
|
456
|
+
* can respond with a confirmation of whether delivery to the specified address
|
|
457
|
+
* is possible. Check out https://core.telegram.org/bots/api#shippingquery to
|
|
458
|
+
* read more about shipping queries.
|
|
459
|
+
*
|
|
460
|
+
* ```ts
|
|
461
|
+
* bot.shippingQuery('invoice_payload', async ctx => {
|
|
462
|
+
* // Answer the shipping query, confer https://core.telegram.org/bots/api#answershippingquery
|
|
463
|
+
* await ctx.answerShippingQuery( ... )
|
|
464
|
+
* })
|
|
465
|
+
* ```
|
|
466
|
+
*
|
|
467
|
+
* @param trigger The string to look for in the invoice payload
|
|
468
|
+
* @param middleware The middleware to register
|
|
469
|
+
*/
|
|
470
|
+
shippingQuery(trigger: MaybeArray<string | RegExp>, ...middleware: Array<ShippingQueryMiddleware<C>>): Composer<ShippingQueryContext<C>>;
|
|
431
471
|
/**
|
|
432
472
|
* > This is an advanced method of grammY.
|
|
433
473
|
*
|
|
@@ -692,6 +732,24 @@ export type InlineQueryMiddleware<C extends Context> = Middleware<InlineQueryCon
|
|
|
692
732
|
* modular code where handlers are defined in separate files.
|
|
693
733
|
*/
|
|
694
734
|
export type ChosenInlineResultMiddleware<C extends Context> = Middleware<ChosenInlineResultContext<C>>;
|
|
735
|
+
/**
|
|
736
|
+
* Type of the middleware that can be passed to `bot.preCheckoutQuery`.
|
|
737
|
+
*
|
|
738
|
+
* This helper type can be used to annotate middleware functions that are
|
|
739
|
+
* defined in one place, so that they have the correct type when passed to
|
|
740
|
+
* `bot.preCheckoutQuery` in a different place. For instance, this allows for more
|
|
741
|
+
* modular code where handlers are defined in separate files.
|
|
742
|
+
*/
|
|
743
|
+
export type PreCheckoutQueryMiddleware<C extends Context> = Middleware<PreCheckoutQueryContext<C>>;
|
|
744
|
+
/**
|
|
745
|
+
* Type of the middleware that can be passed to `bot.shippingQuery`.
|
|
746
|
+
*
|
|
747
|
+
* This helper type can be used to annotate middleware functions that are
|
|
748
|
+
* defined in one place, so that they have the correct type when passed to
|
|
749
|
+
* `bot.shippingQuery` in a different place. For instance, this allows for more
|
|
750
|
+
* modular code where handlers are defined in separate files.
|
|
751
|
+
*/
|
|
752
|
+
export type ShippingQueryMiddleware<C extends Context> = Middleware<ShippingQueryContext<C>>;
|
|
695
753
|
/**
|
|
696
754
|
* Type of the middleware that can be passed to `bot.chatType`.
|
|
697
755
|
*
|
package/out/composer.js
CHANGED
|
@@ -447,6 +447,50 @@ 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 pre-checkout
|
|
452
|
+
* query to your bot whenever a user has confirmed their payment and shipping
|
|
453
|
+
* details. You bot will then receive all information about the order and
|
|
454
|
+
* has to respond within 10 seconds with a confirmation of whether everything
|
|
455
|
+
* is alright (goods are available, etc.) and the bot is ready to proceed
|
|
456
|
+
* with the order. Check out https://core.telegram.org/bots/api#precheckoutquery
|
|
457
|
+
* to read more about pre-checkout queries.
|
|
458
|
+
*
|
|
459
|
+
* ```ts
|
|
460
|
+
* bot.preCheckoutQuery('invoice_payload', async ctx => {
|
|
461
|
+
* // Answer the pre-checkout query, confer https://core.telegram.org/bots/api#answerprecheckoutquery
|
|
462
|
+
* await ctx.answerPreCheckoutQuery( ... )
|
|
463
|
+
* })
|
|
464
|
+
* ```
|
|
465
|
+
*
|
|
466
|
+
* @param trigger The string to look for in the invoice payload
|
|
467
|
+
* @param middleware The middleware to register
|
|
468
|
+
*/
|
|
469
|
+
preCheckoutQuery(trigger, ...middleware) {
|
|
470
|
+
return this.filter(context_js_1.Context.has.preCheckoutQuery(trigger), ...middleware);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Registers middleware for shipping queries. If you sent an invoice requesting
|
|
474
|
+
* a shipping address and the parameter _is_flexible_ was specified, Telegram
|
|
475
|
+
* will send a shipping query to your bot whenever a user has confirmed their
|
|
476
|
+
* shipping details. You bot will then receive the shipping information and
|
|
477
|
+
* can respond with a confirmation of whether delivery to the specified address
|
|
478
|
+
* is possible. Check out https://core.telegram.org/bots/api#shippingquery to
|
|
479
|
+
* read more about shipping queries.
|
|
480
|
+
*
|
|
481
|
+
* ```ts
|
|
482
|
+
* bot.shippingQuery('invoice_payload', async ctx => {
|
|
483
|
+
* // Answer the shipping query, confer https://core.telegram.org/bots/api#answershippingquery
|
|
484
|
+
* await ctx.answerShippingQuery( ... )
|
|
485
|
+
* })
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @param trigger The string to look for in the invoice payload
|
|
489
|
+
* @param middleware The middleware to register
|
|
490
|
+
*/
|
|
491
|
+
shippingQuery(trigger, ...middleware) {
|
|
492
|
+
return this.filter(context_js_1.Context.has.shippingQuery(trigger), ...middleware);
|
|
493
|
+
}
|
|
450
494
|
filter(predicate, ...middleware) {
|
|
451
495
|
const composer = new Composer(...middleware);
|
|
452
496
|
this.branch(predicate, composer, pass);
|
package/out/context.d.ts
CHANGED
|
@@ -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
|
|
97
|
+
* match 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
|
|
@@ -407,6 +425,22 @@ export declare class Context implements RenamedUpdate {
|
|
|
407
425
|
* @param trigger The string or regex to match
|
|
408
426
|
*/
|
|
409
427
|
hasChosenInlineResult(trigger: MaybeArray<string | RegExp>): this is ChosenInlineResultContextCore;
|
|
428
|
+
/**
|
|
429
|
+
* Returns `true` if this context object contains the given pre-checkout query,
|
|
430
|
+
* or if the contained pre-checkout query matches the given regular expression.
|
|
431
|
+
* It returns `false` otherwise. This uses the same logic as `bot.preCheckoutQuery`.
|
|
432
|
+
*
|
|
433
|
+
* @param trigger The string or regex to match
|
|
434
|
+
*/
|
|
435
|
+
hasPreCheckoutQuery(trigger: MaybeArray<string | RegExp>): this is PreCheckoutQueryContextCore;
|
|
436
|
+
/**
|
|
437
|
+
* Returns `true` if this context object contains the given shipping query,
|
|
438
|
+
* or if the contained shipping query matches the given regular expression.
|
|
439
|
+
* It returns `false` otherwise. This uses the same logic as `bot.shippingQuery`.
|
|
440
|
+
*
|
|
441
|
+
* @param trigger The string or regex to match
|
|
442
|
+
*/
|
|
443
|
+
hasShippingQuery(trigger: MaybeArray<string | RegExp>): this is ShippingQueryContextCore;
|
|
410
444
|
/**
|
|
411
445
|
* Context-aware alias for `api.sendMessage`. Use this method to send text messages. On success, the sent Message is returned.
|
|
412
446
|
*
|
|
@@ -1395,6 +1429,30 @@ type ChosenInlineResultContextCore = FilterCore<"chosen_inline_result">;
|
|
|
1395
1429
|
* in separate files and still have the correct types.
|
|
1396
1430
|
*/
|
|
1397
1431
|
export type ChosenInlineResultContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "chosen_inline_result">;
|
|
1432
|
+
type PreCheckoutQueryContextCore = FilterCore<"pre_checkout_query">;
|
|
1433
|
+
/**
|
|
1434
|
+
* Type of the context object that is available inside the handlers for
|
|
1435
|
+
* `bot.preCheckoutQuery`.
|
|
1436
|
+
*
|
|
1437
|
+
* This helper type can be used to narrow down context objects the same way how
|
|
1438
|
+
* annotate `bot.preCheckoutQuery` does it. This allows you to context objects in
|
|
1439
|
+
* middleware that is not directly passed to `bot.preCheckoutQuery`, hence not
|
|
1440
|
+
* inferring the correct type automatically. That way, handlers can be defined
|
|
1441
|
+
* in separate files and still have the correct types.
|
|
1442
|
+
*/
|
|
1443
|
+
export type PreCheckoutQueryContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "pre_checkout_query">;
|
|
1444
|
+
type ShippingQueryContextCore = FilterCore<"shipping_query">;
|
|
1445
|
+
/**
|
|
1446
|
+
* Type of the context object that is available inside the handlers for
|
|
1447
|
+
* `bot.shippingQuery`.
|
|
1448
|
+
*
|
|
1449
|
+
* This helper type can be used to narrow down context objects the same way how
|
|
1450
|
+
* annotate `bot.shippingQuery` does it. This allows you to context objects in
|
|
1451
|
+
* middleware that is not directly passed to `bot.shippingQuery`, hence not
|
|
1452
|
+
* inferring the correct type automatically. That way, handlers can be defined
|
|
1453
|
+
* in separate files and still have the correct types.
|
|
1454
|
+
*/
|
|
1455
|
+
export type ShippingQueryContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "shipping_query">;
|
|
1398
1456
|
type ChatTypeContextCore<T extends Chat["type"]> = Record<"update", ChatTypeUpdate<T>> & ChatType<T> & Record<"chatId", number> & ChatFrom<T> & ChatTypeRecord<"msg", T> & AliasProps<ChatTypeUpdate<T>>;
|
|
1399
1457
|
/**
|
|
1400
1458
|
* 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
|
/**
|
|
@@ -590,6 +602,26 @@ class Context {
|
|
|
590
602
|
hasChosenInlineResult(trigger) {
|
|
591
603
|
return Context.has.chosenInlineResult(trigger)(this);
|
|
592
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Returns `true` if this context object contains the given pre-checkout query,
|
|
607
|
+
* or if the contained pre-checkout query matches the given regular expression.
|
|
608
|
+
* It returns `false` otherwise. This uses the same logic as `bot.preCheckoutQuery`.
|
|
609
|
+
*
|
|
610
|
+
* @param trigger The string or regex to match
|
|
611
|
+
*/
|
|
612
|
+
hasPreCheckoutQuery(trigger) {
|
|
613
|
+
return Context.has.preCheckoutQuery(trigger)(this);
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Returns `true` if this context object contains the given shipping query,
|
|
617
|
+
* or if the contained shipping query matches the given regular expression.
|
|
618
|
+
* It returns `false` otherwise. This uses the same logic as `bot.shippingQuery`.
|
|
619
|
+
*
|
|
620
|
+
* @param trigger The string or regex to match
|
|
621
|
+
*/
|
|
622
|
+
hasShippingQuery(trigger) {
|
|
623
|
+
return Context.has.shippingQuery(trigger)(this);
|
|
624
|
+
}
|
|
593
625
|
// API
|
|
594
626
|
/**
|
|
595
627
|
* Context-aware alias for `api.sendMessage`. Use this method to send text messages. On success, the sent Message is returned.
|
package/out/web.mjs
CHANGED
|
@@ -471,6 +471,16 @@ const checker = {
|
|
|
471
471
|
const hasChosenInlineResult = checker.filterQuery("chosen_inline_result");
|
|
472
472
|
const trg = triggerFn(trigger);
|
|
473
473
|
return (ctx)=>hasChosenInlineResult(ctx) && match(ctx, ctx.chosenInlineResult.result_id, trg);
|
|
474
|
+
},
|
|
475
|
+
preCheckoutQuery (trigger) {
|
|
476
|
+
const hasPreCheckoutQuery = checker.filterQuery("pre_checkout_query");
|
|
477
|
+
const trg = triggerFn(trigger);
|
|
478
|
+
return (ctx)=>hasPreCheckoutQuery(ctx) && match(ctx, ctx.preCheckoutQuery.invoice_payload, trg);
|
|
479
|
+
},
|
|
480
|
+
shippingQuery (trigger) {
|
|
481
|
+
const hasShippingQuery = checker.filterQuery("shipping_query");
|
|
482
|
+
const trg = triggerFn(trigger);
|
|
483
|
+
return (ctx)=>hasShippingQuery(ctx) && match(ctx, ctx.shippingQuery.invoice_payload, trg);
|
|
474
484
|
}
|
|
475
485
|
};
|
|
476
486
|
class Context {
|
|
@@ -685,6 +695,12 @@ class Context {
|
|
|
685
695
|
hasChosenInlineResult(trigger) {
|
|
686
696
|
return Context.has.chosenInlineResult(trigger)(this);
|
|
687
697
|
}
|
|
698
|
+
hasPreCheckoutQuery(trigger) {
|
|
699
|
+
return Context.has.preCheckoutQuery(trigger)(this);
|
|
700
|
+
}
|
|
701
|
+
hasShippingQuery(trigger) {
|
|
702
|
+
return Context.has.shippingQuery(trigger)(this);
|
|
703
|
+
}
|
|
688
704
|
reply(text, other, signal) {
|
|
689
705
|
return this.api.sendMessage(orThrow(this.chatId, "sendMessage"), text, {
|
|
690
706
|
business_connection_id: this.businessConnectionId,
|
|
@@ -1173,6 +1189,12 @@ class Composer {
|
|
|
1173
1189
|
chosenInlineResult(resultId, ...middleware) {
|
|
1174
1190
|
return this.filter(Context.has.chosenInlineResult(resultId), ...middleware);
|
|
1175
1191
|
}
|
|
1192
|
+
preCheckoutQuery(trigger, ...middleware) {
|
|
1193
|
+
return this.filter(Context.has.preCheckoutQuery(trigger), ...middleware);
|
|
1194
|
+
}
|
|
1195
|
+
shippingQuery(trigger, ...middleware) {
|
|
1196
|
+
return this.filter(Context.has.shippingQuery(trigger), ...middleware);
|
|
1197
|
+
}
|
|
1176
1198
|
filter(predicate, ...middleware) {
|
|
1177
1199
|
const composer = new Composer(...middleware);
|
|
1178
1200
|
this.branch(predicate, composer, pass);
|