grammy 1.25.0 → 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/README.md +3 -1
- 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/convenience/webhook.d.ts +30 -6
- package/out/convenience/webhook.js +1 -1
- package/out/filter.d.ts +1 -1
- package/out/web.mjs +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -260,7 +260,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
260
260
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/shevernitskiy"><img src="https://avatars.githubusercontent.com/u/28886342?v=4?s=100" width="100px;" alt="shevernitskiy"/><br /><sub><b>shevernitskiy</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ashevernitskiy" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Ashevernitskiy" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/grammyjs/grammY/commits?author=shevernitskiy" title="Code">💻</a></td>
|
|
261
261
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/mrmaster009"><img src="https://avatars.githubusercontent.com/u/81420490?v=4?s=100" width="100px;" alt="mrmaster009"/><br /><sub><b>mrmaster009</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=mrmaster009" title="Documentation">📖</a></td>
|
|
262
262
|
<td align="center" valign="top" width="11.11%"><a href="https://lwjerri.dev/"><img src="https://avatars.githubusercontent.com/u/50290430?v=4?s=100" width="100px;" alt="Andrey Zontov"/><br /><sub><b>Andrey Zontov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3ALWJerri" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=LWJerri" title="Code">💻</a> <a href="#question-LWJerri" title="Answering Questions">💬</a> <a href="#ideas-LWJerri" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/commits?author=LWJerri" title="Documentation">📖</a> <a href="#translation-LWJerri" title="Translation">🌍</a></td>
|
|
263
|
-
<td align="center" valign="top" width="11.11%"><a href="https://github.com/AbbassAlmusawi"><img src="https://avatars.githubusercontent.com/u/73327881?v=4?s=100" width="100px;" alt="Abbass Al-Musawi"/><br /><sub><b>Abbass Al-Musawi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=AbbassAlmusawi" title="Documentation">📖</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3AAbbassAlmusawi" title="Bug reports">🐛</a></td>
|
|
263
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/AbbassAlmusawi"><img src="https://avatars.githubusercontent.com/u/73327881?v=4?s=100" width="100px;" alt="Abbass Al-Musawi"/><br /><sub><b>Abbass Al-Musawi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=AbbassAlmusawi" title="Documentation">📖</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3AAbbassAlmusawi" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=AbbassAlmusawi" title="Code">💻</a></td>
|
|
264
264
|
</tr>
|
|
265
265
|
<tr>
|
|
266
266
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/inji-gg"><img src="https://avatars.githubusercontent.com/u/5071242?v=4?s=100" width="100px;" alt="ArunR"/><br /><sub><b>ArunR</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ainji-gg" title="Bug reports">🐛</a> <a href="https://github.com/grammyjs/grammY/commits?author=inji-gg" title="Code">💻</a></td>
|
|
@@ -300,6 +300,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
300
300
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/MobinAskari"><img src="https://avatars.githubusercontent.com/u/132358316?v=4?s=100" width="100px;" alt="Mobin Askari"/><br /><sub><b>Mobin Askari</b></sub></a><br /><a href="#plugin-MobinAskari" title="Plugin/utility libraries">🔌</a></td>
|
|
301
301
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/ubertao"><img src="https://avatars.githubusercontent.com/u/4099333?v=4?s=100" width="100px;" alt="Ubertao"/><br /><sub><b>Ubertao</b></sub></a><br /><a href="#ideas-ubertao" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/commits?author=ubertao" title="Code">💻</a></td>
|
|
302
302
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/SunsetTechuila"><img src="https://avatars.githubusercontent.com/u/115353812?v=4?s=100" width="100px;" alt="Grigory"/><br /><sub><b>Grigory</b></sub></a><br /><a href="#ideas-SunsetTechuila" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/commits?author=SunsetTechuila" title="Code">💻</a> <a href="https://github.com/grammyjs/grammY/commits?author=SunsetTechuila" title="Documentation">📖</a></td>
|
|
303
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/aleveha"><img src="https://avatars.githubusercontent.com/u/63300936?v=4?s=100" width="100px;" alt="aleveha"/><br /><sub><b>aleveha</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=aleveha" title="Code">💻</a></td>
|
|
304
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/barinbritva"><img src="https://avatars.githubusercontent.com/u/4758362?v=4?s=100" width="100px;" alt="barinbritva"/><br /><sub><b>barinbritva</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Abarinbritva" title="Reviewed Pull Requests">👀</a></td>
|
|
303
305
|
</tr>
|
|
304
306
|
</tbody>
|
|
305
307
|
</table>
|
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.
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { type Bot } from "../bot.js";
|
|
2
2
|
import { type Context } from "../context.js";
|
|
3
|
-
import {
|
|
3
|
+
import { type FrameworkAdapter } from "./frameworks.js";
|
|
4
|
+
declare const adapters: {
|
|
5
|
+
callback: FrameworkAdapter;
|
|
6
|
+
"aws-lambda": import("./frameworks.js").LambdaAdapter;
|
|
7
|
+
"aws-lambda-async": import("./frameworks.js").LambdaAsyncAdapter;
|
|
8
|
+
azure: import("./frameworks.js").AzureAdapter;
|
|
9
|
+
bun: import("./frameworks.js").BunAdapter;
|
|
10
|
+
cloudflare: import("./frameworks.js").CloudflareAdapter;
|
|
11
|
+
"cloudflare-mod": import("./frameworks.js").CloudflareModuleAdapter;
|
|
12
|
+
express: import("./frameworks.js").ExpressAdapter;
|
|
13
|
+
fastify: import("./frameworks.js").FastifyAdapter;
|
|
14
|
+
hono: import("./frameworks.js").HonoAdapter;
|
|
15
|
+
http: import("./frameworks.js").HttpAdapter;
|
|
16
|
+
https: import("./frameworks.js").HttpAdapter;
|
|
17
|
+
koa: import("./frameworks.js").KoaAdapter;
|
|
18
|
+
"next-js": import("./frameworks.js").NextAdapter;
|
|
19
|
+
nhttp: import("./frameworks.js").NHttpAdapter;
|
|
20
|
+
oak: import("./frameworks.js").OakAdapter;
|
|
21
|
+
serveHttp: import("./frameworks.js").ServeHttpAdapter;
|
|
22
|
+
"std/http": import("./frameworks.js").StdHttpAdapter;
|
|
23
|
+
sveltekit: import("./frameworks.js").SveltekitAdapter;
|
|
24
|
+
worktop: import("./frameworks.js").WorktopAdapter;
|
|
25
|
+
};
|
|
4
26
|
export interface WebhookOptions {
|
|
5
27
|
/** An optional strategy to handle timeouts (default: 'throw') */
|
|
6
28
|
onTimeout?: "throw" | "return" | ((...args: any[]) => unknown);
|
|
@@ -9,6 +31,9 @@ export interface WebhookOptions {
|
|
|
9
31
|
/** An optional string to compare to X-Telegram-Bot-Api-Secret-Token */
|
|
10
32
|
secretToken?: string;
|
|
11
33
|
}
|
|
34
|
+
type Adapters = typeof adapters;
|
|
35
|
+
type AdapterNames = keyof Adapters;
|
|
36
|
+
type ResolveName<A extends FrameworkAdapter | AdapterNames> = A extends AdapterNames ? Adapters[A] : A;
|
|
12
37
|
/**
|
|
13
38
|
* Creates a callback function that you can pass to a web framework (such as
|
|
14
39
|
* express) if you want to run your bot via webhooks. Use it like this:
|
|
@@ -25,9 +50,8 @@ export interface WebhookOptions {
|
|
|
25
50
|
*
|
|
26
51
|
* @param bot The bot for which to create a callback
|
|
27
52
|
* @param adapter An optional string identifying the framework (default: 'express')
|
|
28
|
-
* @param
|
|
29
|
-
* @param timeoutMilliseconds An optional number of timeout milliseconds (default: 10_000)
|
|
53
|
+
* @param webhookOptions Further options for the webhook setup
|
|
30
54
|
*/
|
|
31
|
-
export declare function webhookCallback<C extends Context = Context>(bot: Bot<C>, adapter
|
|
32
|
-
export declare function webhookCallback<C extends Context = Context>(bot: Bot<C>, adapter?:
|
|
33
|
-
export
|
|
55
|
+
export declare function webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(bot: Bot<C>, adapter: A, webhookOptions?: WebhookOptions): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
|
|
56
|
+
export declare function webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(bot: Bot<C>, adapter: A, onTimeout?: WebhookOptions["onTimeout"], timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"], secretToken?: WebhookOptions["secretToken"]): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
|
|
57
|
+
export {};
|
|
@@ -11,7 +11,7 @@ const callbackAdapter = (update, callback, header, unauthorized = () => callback
|
|
|
11
11
|
unauthorized,
|
|
12
12
|
});
|
|
13
13
|
const adapters = { ...frameworks_js_1.adapters, callback: callbackAdapter };
|
|
14
|
-
function webhookCallback(bot, adapter = platform_node_js_1.defaultAdapter, onTimeout
|
|
14
|
+
function webhookCallback(bot, adapter = platform_node_js_1.defaultAdapter, onTimeout, timeoutMilliseconds, secretToken) {
|
|
15
15
|
const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10000, secretToken: token, } = typeof onTimeout === "object"
|
|
16
16
|
? onTimeout
|
|
17
17
|
: { onTimeout, timeoutMilliseconds, secretToken };
|
package/out/filter.d.ts
CHANGED
|
@@ -838,7 +838,7 @@ interface Shortcuts<U extends Update> {
|
|
|
838
838
|
senderChat: [Shortcuts<U>["msg"]] extends [object] ? Shortcuts<U>["msg"]["sender_chat"] : undefined;
|
|
839
839
|
from: [U["business_connection"]] extends [object] ? U["business_connection"]["user"] : [U["message_reaction"]] extends [object] ? U["message_reaction"]["user"] : [U["chat_boost"]] extends [object] ? U["chat_boost"]["boost"]["source"]["user"] : [U["removed_chat_boost"]] extends [object] ? U["removed_chat_boost"]["source"]["user"] : [U["callback_query"]] extends [object] ? U["callback_query"]["from"] : [Shortcuts<U>["msg"]] extends [object] ? Shortcuts<U>["msg"]["from"] : [U["inline_query"]] extends [object] ? U["inline_query"]["from"] : [U["chosen_inline_result"]] extends [object] ? U["chosen_inline_result"]["from"] : [U["shipping_query"]] extends [object] ? U["shipping_query"]["from"] : [U["pre_checkout_query"]] extends [object] ? U["pre_checkout_query"]["from"] : [U["my_chat_member"]] extends [object] ? U["my_chat_member"]["from"] : [U["chat_member"]] extends [object] ? U["chat_member"]["from"] : [U["chat_join_request"]] extends [object] ? U["chat_join_request"]["from"] : undefined;
|
|
840
840
|
msgId: [U["callback_query"]] extends [object] ? number | undefined : [Shortcuts<U>["msg"]] extends [object] ? number : [U["message_reaction"]] extends [object] ? number : [U["message_reaction_count"]] extends [object] ? number : undefined;
|
|
841
|
-
chatId: [Shortcuts<U>["chat"]] extends [object] ? number : [U["business_connection"]] extends [object] ? number : undefined;
|
|
841
|
+
chatId: [U["callback_query"]] extends [object] ? number | undefined : [Shortcuts<U>["chat"]] extends [object] ? number : [U["business_connection"]] extends [object] ? number : undefined;
|
|
842
842
|
businessConnectionId: [U["callback_query"]] extends [object] ? string | undefined : [Shortcuts<U>["msg"]] extends [object] ? string | undefined : [U["business_connection"]] extends [object] ? string : [U["deleted_business_messages"]] extends [object] ? string : undefined;
|
|
843
843
|
}
|
|
844
844
|
declare const L1_SHORTCUTS: {
|
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);
|
|
@@ -4819,7 +4841,7 @@ const adapters1 = {
|
|
|
4819
4841
|
...adapters,
|
|
4820
4842
|
callback: callbackAdapter
|
|
4821
4843
|
};
|
|
4822
|
-
function webhookCallback(bot, adapter = defaultAdapter, onTimeout
|
|
4844
|
+
function webhookCallback(bot, adapter = defaultAdapter, onTimeout, timeoutMilliseconds, secretToken) {
|
|
4823
4845
|
const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10_000, secretToken: token } = typeof onTimeout === "object" ? onTimeout : {
|
|
4824
4846
|
onTimeout,
|
|
4825
4847
|
timeoutMilliseconds,
|