grammy 1.9.2 β†’ 1.11.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
@@ -96,7 +96,7 @@ Includes a setup to easily run any of them.
96
96
  β€”Telegram chat where you can ask any question about grammY or bots in general.
97
97
  We are also open for feedback, ideas, and contributions!
98
98
 
99
- The Russian commnity chat can be found [here](https://t.me/grammyjs_ru).
99
+ The Russian community chat can be found [here](https://t.me/grammyjs_ru).
100
100
 
101
101
  ### [grammY News Channel](https://t.me/grammyjs_news)
102
102
 
@@ -151,7 +151,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
151
151
  <td align="center"><a href="https://github.com/jokasimr"><img src="https://avatars.githubusercontent.com/u/20954731?v=4?s=100" width="100px;" alt=""/><br /><sub><b>jokasimr</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ajokasimr" title="Bug reports">πŸ›</a></td>
152
152
  <td align="center"><a href="https://github.com/CikiMomogi"><img src="https://avatars.githubusercontent.com/u/74030149?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ciki Momogi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=CikiMomogi" title="Documentation">πŸ“–</a></td>
153
153
  <td align="center"><a href="https://github.com/AndreoliBR"><img src="https://avatars.githubusercontent.com/u/15970011?v=4?s=100" width="100px;" alt=""/><br /><sub><b>AndreoliBR</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AAndreoliBR" title="Reviewed Pull Requests">πŸ‘€</a></td>
154
- <td align="center"><a href="https://github.com/Loskir"><img src="https://avatars.githubusercontent.com/u/21295738?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kirill Loskutov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Loskir" title="Documentation">πŸ“–</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3ALoskir" title="Bug reports">πŸ›</a> <a href="#ideas-Loskir" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="#design-Loskir" title="Design">🎨</a> <a href="#question-Loskir" title="Answering Questions">πŸ’¬</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3ALoskir" title="Reviewed Pull Requests">πŸ‘€</a></td>
154
+ <td align="center"><a href="https://github.com/Loskir"><img src="https://avatars.githubusercontent.com/u/21295738?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kirill Loskutov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Loskir" title="Documentation">πŸ“–</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3ALoskir" title="Bug reports">πŸ›</a> <a href="#ideas-Loskir" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="#design-Loskir" title="Design">🎨</a> <a href="#question-Loskir" title="Answering Questions">πŸ’¬</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3ALoskir" title="Reviewed Pull Requests">πŸ‘€</a> <a href="https://github.com/grammyjs/grammY/commits?author=Loskir" title="Code">πŸ’»</a> <a href="#plugin-Loskir" title="Plugin/utility libraries">πŸ”Œ</a></td>
155
155
  </tr>
156
156
  <tr>
157
157
  <td align="center"><a href="https://lungers.com/"><img src="https://avatars.githubusercontent.com/u/32808683?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andrew Lane</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3AAndrewLaneX" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AAndrewLaneX" title="Reviewed Pull Requests">πŸ‘€</a></td>
@@ -178,13 +178,13 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
178
178
  <td align="center"><a href="https://zhemu.buzz/"><img src="https://avatars.githubusercontent.com/u/56839018?v=4?s=100" width="100px;" alt=""/><br /><sub><b>linbuxiao</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=linbuxiao" title="Documentation">πŸ“–</a> <a href="#translation-linbuxiao" title="Translation">🌍</a></td>
179
179
  <td align="center"><a href="https://github.com/JiquanWang99"><img src="https://avatars.githubusercontent.com/u/63894579?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JiquanWang99</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=JiquanWang99" title="Documentation">πŸ“–</a> <a href="#translation-JiquanWang99" title="Translation">🌍</a></td>
180
180
  <td align="center"><a href="http://bor691.ir/"><img src="https://avatars.githubusercontent.com/u/4184939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Borhan Hafez</b></sub></a><br /><a href="#plugin-zumoshi" title="Plugin/utility libraries">πŸ”Œ</a></td>
181
- <td align="center"><a href="https://blog.limx.dev/"><img src="https://avatars.githubusercontent.com/u/6434137?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WingLim</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=WingLim" title="Documentation">πŸ“–</a> <a href="#translation-WingLim" title="Translation">🌍</a></td>
181
+ <td align="center"><a href="https://blog.limx.dev/"><img src="https://avatars.githubusercontent.com/u/6434137?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WingLim</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=WingLim" title="Documentation">πŸ“–</a> <a href="#translation-WingLim" title="Translation">🌍</a> <a href="https://github.com/grammyjs/grammY/commits?author=WingLim" title="Code">πŸ’»</a> <a href="#plugin-WingLim" title="Plugin/utility libraries">πŸ”Œ</a> <a href="#ideas-WingLim" title="Ideas, Planning, & Feedback">πŸ€”</a></td>
182
182
  </tr>
183
183
  <tr>
184
184
  <td align="center"><a href="https://github.com/taotie111"><img src="https://avatars.githubusercontent.com/u/44166322?v=4?s=100" width="100px;" alt=""/><br /><sub><b>taotie111</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=taotie111" title="Documentation">πŸ“–</a> <a href="#translation-taotie111" title="Translation">🌍</a></td>
185
185
  <td align="center"><a href="https://www.linkedin.com/in/merlin-brandes-42328717a/"><img src="https://avatars.githubusercontent.com/u/14237330?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Merlin</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=FatalMerlin" title="Documentation">πŸ“–</a></td>
186
186
  <td align="center"><a href="https://darve.sh"><img src="https://avatars.githubusercontent.com/u/22394081?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Darvesh</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Adarvesh" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=darvesh" title="Code">πŸ’»</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adarvesh" title="Reviewed Pull Requests">πŸ‘€</a></td>
187
- <td align="center"><a href="http://telegram.me/dcdunkan"><img src="https://avatars.githubusercontent.com/u/70066170?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dcdunkan</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Adcdunkan" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=dcdunkan" title="Code">πŸ’»</a> <a href="#plugin-dcdunkan" title="Plugin/utility libraries">πŸ”Œ</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adcdunkan" title="Reviewed Pull Requests">πŸ‘€</a> <a href="https://github.com/grammyjs/grammY/commits?author=dcdunkan" title="Documentation">πŸ“–</a> <a href="#ideas-dcdunkan" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="#infra-dcdunkan" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a></td>
187
+ <td align="center"><a href="http://telegram.me/dcdunkan"><img src="https://avatars.githubusercontent.com/u/70066170?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dcdunkan</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Adcdunkan" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=dcdunkan" title="Code">πŸ’»</a> <a href="#plugin-dcdunkan" title="Plugin/utility libraries">πŸ”Œ</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adcdunkan" title="Reviewed Pull Requests">πŸ‘€</a> <a href="https://github.com/grammyjs/grammY/commits?author=dcdunkan" title="Documentation">πŸ“–</a> <a href="#ideas-dcdunkan" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="#infra-dcdunkan" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="#tool-dcdunkan" title="Tools">πŸ”§</a></td>
188
188
  <td align="center"><a href="https://xuann.wang/"><img src="https://avatars.githubusercontent.com/u/44045911?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kid</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=kidonng" title="Documentation">πŸ“–</a> <a href="#translation-kidonng" title="Translation">🌍</a></td>
189
189
  <td align="center"><a href="http://slava.fomin.io/"><img src="https://avatars.githubusercontent.com/u/1702725?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Slava Fomin II</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aslavafomin" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=slavafomin" title="Documentation">πŸ“–</a></td>
190
190
  <td align="center"><a href="https://kikobeats.com/"><img src="https://avatars.githubusercontent.com/u/2096101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kiko Beats</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Kikobeats" title="Documentation">πŸ“–</a></td>
@@ -204,7 +204,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
204
204
  <td align="center"><a href="https://github.com/Scrip7"><img src="https://avatars.githubusercontent.com/u/37535505?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hesoyam</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Scrip7" title="Documentation">πŸ“–</a></td>
205
205
  <td align="center"><a href="http://yrz.am"><img src="https://avatars.githubusercontent.com/u/96742416?v=4?s=100" width="100px;" alt=""/><br /><sub><b>yrzam</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ayrzam" title="Bug reports">πŸ›</a></td>
206
206
  <td align="center"><a href="https://github.com/drmikecrowe"><img src="https://avatars.githubusercontent.com/u/90312?v=4?s=100" width="100px;" alt=""/><br /><sub><b>drmikecrowe</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adrmikecrowe" title="Reviewed Pull Requests">πŸ‘€</a></td>
207
- <td align="center"><a href="https://rys.pw"><img src="https://avatars.githubusercontent.com/u/1641362?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Martin</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=C0rn3j" title="Documentation">πŸ“–</a></td>
207
+ <td align="center"><a href="https://rys.pw"><img src="https://avatars.githubusercontent.com/u/1641362?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Martin</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=C0rn3j" title="Documentation">πŸ“–</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3AC0rn3j" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AC0rn3j" title="Reviewed Pull Requests">πŸ‘€</a></td>
208
208
  <td align="center"><a href="http://pavelpolyakov.com/"><img src="https://avatars.githubusercontent.com/u/839290?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pavel</b></sub></a><br /><a href="#example-PavelPolyakov" title="Examples">πŸ’‘</a></td>
209
209
  </tr>
210
210
  <tr>
@@ -217,7 +217,13 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
217
217
  <td align="center"><a href="https://oott123.com"><img src="https://avatars.githubusercontent.com/u/905663?v=4?s=100" width="100px;" alt=""/><br /><sub><b>δΈ‰δΈ‰</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aoott123" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=oott123" title="Code">πŸ’»</a></td>
218
218
  </tr>
219
219
  <tr>
220
- <td align="center"><a href="http://roz.ninja"><img src="https://avatars.githubusercontent.com/u/3948961?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Roz</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aroziscoding" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=roziscoding" title="Code">πŸ’»</a></td>
220
+ <td align="center"><a href="http://roz.ninja"><img src="https://avatars.githubusercontent.com/u/3948961?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Roz</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aroziscoding" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=roziscoding" title="Code">πŸ’»</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Aroziscoding" title="Reviewed Pull Requests">πŸ‘€</a></td>
221
+ <td align="center"><a href="https://github.com/daniharo"><img src="https://avatars.githubusercontent.com/u/47931084?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dani Haro</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=daniharo" title="Code">πŸ’»</a> <a href="#plugin-daniharo" title="Plugin/utility libraries">πŸ”Œ</a> <a href="https://github.com/grammyjs/grammY/commits?author=daniharo" title="Documentation">πŸ“–</a></td>
222
+ <td align="center"><a href="https://github.com/Ryukaizen"><img src="https://avatars.githubusercontent.com/u/55140313?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ryukaizen</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Ryukaizen" title="Documentation">πŸ“–</a></td>
223
+ <td align="center"><a href="https://github.com/mcpeblocker"><img src="https://avatars.githubusercontent.com/u/59408255?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alisher Ortiqov</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=mcpeblocker" title="Documentation">πŸ“–</a></td>
224
+ <td align="center"><a href="https://github.com/tonytkachenko"><img src="https://avatars.githubusercontent.com/u/103267335?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tony Tkachenko</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=tonytkachenko" title="Documentation">πŸ“–</a></td>
225
+ <td align="center"><a href="https://github.com/rainrisa"><img src="https://avatars.githubusercontent.com/u/108156134?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ra</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=rainrisa" title="Code">πŸ’»</a></td>
226
+ <td align="center"><a href="https://github.com/sartoshi-foot-dao"><img src="https://avatars.githubusercontent.com/u/99770068?v=4?s=100" width="100px;" alt=""/><br /><sub><b>sartoshi-foot-dao</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=sartoshi-foot-dao" title="Documentation">πŸ“–</a></td>
221
227
  </tr>
222
228
  </table>
223
229
 
package/out/bot.d.ts CHANGED
@@ -2,7 +2,7 @@ import { BotError, Composer } from "./composer.js";
2
2
  import { Context } from "./context.js";
3
3
  import { Api } from "./core/api.js";
4
4
  import { type ApiClientOptions, type WebhookReplyEnvelope } from "./core/client.js";
5
- import { type Update, type UserFromGetMe } from "./platform.node.js";
5
+ import { type Update, type UserFromGetMe } from "./types.js";
6
6
  /**
7
7
  * Options that can be specified when running the bot via simple long polling.
8
8
  */
@@ -150,7 +150,7 @@ export declare class Bot<C extends Context = Context, A extends Api = Api> exten
150
150
  * unless a manual value is already set.
151
151
  *
152
152
  * Note that the recommended way to set a custom bot information object is
153
- * to pass it to the configuration object of the `new Bot()` instatiation,
153
+ * to pass it to the configuration object of the `new Bot()` instantiation,
154
154
  * rather than assigning this property.
155
155
  */
156
156
  set botInfo(botInfo: UserFromGetMe);
package/out/bot.js CHANGED
@@ -85,7 +85,7 @@ class Bot extends composer_js_1.Composer {
85
85
  * unless a manual value is already set.
86
86
  *
87
87
  * Note that the recommended way to set a custom bot information object is
88
- * to pass it to the configuration object of the `new Bot()` instatiation,
88
+ * to pass it to the configuration object of the `new Bot()` instantiation,
89
89
  * rather than assigning this property.
90
90
  */
91
91
  set botInfo(botInfo) {
package/out/composer.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import { type AliasProps, type Context } from "./context.js";
1
+ import { type CallbackQueryContext, type ChatTypeContext, type CommandContext, Context, type GameQueryContext, type HearsContext, type InlineQueryContext, type MaybeArray, type StringWithSuggestions } from "./context.js";
2
2
  import { type Filter, type FilterQuery } from "./filter.js";
3
- import { type Chat } from "./platform.node.js";
3
+ import { type Chat } from "./types.js";
4
4
  declare type MaybePromise<T> = T | Promise<T>;
5
- declare type MaybeArray<T> = T | T[];
6
- declare type StringWithSuggestions<S extends string> = (string & {}) | S;
7
5
  /**
8
6
  * A function of this type is passed as the second parameter to all middleware.
9
7
  * Invoke it to call the downstream middleware and pass on the control flow.
@@ -311,7 +309,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
311
309
  * ```ts
312
310
  * bot.on('callback_query:data', ctx => { ... })
313
311
  * ```
314
- * but it also allows you match the query data agains a given text or
312
+ * but it also allows you to match the query data against a given text or
315
313
  * regular expression.
316
314
  *
317
315
  * ```ts
@@ -352,7 +350,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
352
350
  * ```ts
353
351
  * bot.on('callback_query:game_short_name', ctx => { ... })
354
352
  * ```
355
- * but it also allows you match the query data agains a given text or
353
+ * but it also allows you to match the query data against a given text or
356
354
  * regular expression.
357
355
  *
358
356
  * You can pass an array of triggers. Your middleware will be executed if at
@@ -395,7 +393,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
395
393
  * skipped and the next middleware will be executed.
396
394
  *
397
395
  * This method has two signatures. The first one is straightforward, it is
398
- * the one described above. Note that the predicate may be asyncronous, i.e.
396
+ * the one described above. Note that the predicate may be asynchronous, i.e.
399
397
  * it can return a Promise of a boolean.
400
398
  *
401
399
  * Alternatively, you can pass a function that has a type predicate as
@@ -431,7 +429,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
431
429
  * other words, the middleware will only be executed if the given predicate
432
430
  * returns `false` for the given context object. Otherwise, it will be
433
431
  * skipped and the next middleware will be executed. Note that the predicate
434
- * may be asyncronous, i.e. it can return a Promise of a boolean.
432
+ * may be asynchronous, i.e. it can return a Promise of a boolean.
435
433
  *
436
434
  * This method is the same using `filter` (normal usage) with a negated
437
435
  * predicate.
@@ -522,7 +520,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
522
520
  * middleware if your route function returns `undefined`, or if the key
523
521
  * returned by your router has no middleware associated with it.
524
522
  *
525
- * This method may need less setup than first instanciating a `Router`, but
523
+ * This method may need less setup than first instantiating a `Router`, but
526
524
  * for more complex setups, having a `Router` may be more readable.
527
525
  *
528
526
  * @param router The routing function to use
@@ -538,7 +536,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
538
536
  * This method takes a predicate function that is tested once per context
539
537
  * object. If it returns `true`, the first supplied middleware is executed.
540
538
  * If it returns `false`, the second supplied middleware is executed. Note
541
- * that the predicate may be asyncronous, i.e. it can return a Promise of a
539
+ * that the predicate may be asynchronous, i.e. it can return a Promise of a
542
540
  * boolean.
543
541
  *
544
542
  * @param predicate The predicate to check
@@ -586,27 +584,58 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
586
584
  */
587
585
  errorBoundary(errorHandler: (error: BotError<C>, next: NextFunction) => MaybePromise<unknown>, ...middleware: Array<Middleware<C>>): Composer<C>;
588
586
  }
589
- export declare type HearsContext<C extends Context> = Filter<Omit<C, "match"> & {
590
- match: Extract<C["match"], string | RegExpMatchArray>;
591
- }, ":text" | ":caption">;
592
- export declare type CommandContext<C extends Context> = Filter<Omit<C, "match"> & {
593
- match: Extract<C["match"], string>;
594
- }, ":entities:bot_command">;
595
- export declare type CallbackQueryContext<C extends Context> = Filter<C, "callback_query:data">;
596
- export declare type GameQueryContext<C extends Context> = Filter<C, "callback_query:game_short_name">;
597
- export declare type InlineQueryContext<C extends Context> = Filter<C, "inline_query">;
598
- export declare type ChatTypeContext<C extends Context, T extends Chat["type"]> = C & Record<"update", ChatTypeUpdate<T>> & ChatType<T> & ChatTypeRecord<"msg", T> & AliasProps<ChatTypeUpdate<T>>;
599
- declare type ChatTypeUpdate<T extends Chat["type"]> = ChatTypeRecord<"message" | "edited_message" | "channel_post" | "edited_channel_post" | "my_chat_member" | "chat_member" | "chat_join_request", T> & Partial<Record<"callback_query", ChatTypeRecord<"message", T>>>;
600
- declare type ChatTypeRecord<K extends string, T extends Chat["type"]> = Partial<Record<K, ChatType<T>>>;
601
- interface ChatType<T extends Chat["type"]> {
602
- chat: {
603
- type: T;
604
- };
605
- }
587
+ /**
588
+ * Type of the middleware that can be passed to `bot.hears`.
589
+ *
590
+ * This helper type can be used to annotate middleware functions that are
591
+ * defined in one place, so that they have the correct type when passed to
592
+ * `bot.hears` in a different place. For instance, this allows for more modular
593
+ * code where handlers are defined in separate files.
594
+ */
606
595
  export declare type HearsMiddleware<C extends Context> = Middleware<HearsContext<C>>;
596
+ /**
597
+ * Type of the middleware that can be passed to `bot.command`.
598
+ *
599
+ * This helper type can be used to annotate middleware functions that are
600
+ * defined in one place, so that they have the correct type when passed to
601
+ * `bot.command` in a different place. For instance, this allows for more
602
+ * modular code where handlers are defined in separate files.
603
+ */
607
604
  export declare type CommandMiddleware<C extends Context> = Middleware<CommandContext<C>>;
605
+ /**
606
+ * Type of the middleware that can be passed to `bot.callbackQuery`.
607
+ *
608
+ * This helper type can be used to annotate middleware functions that are
609
+ * defined in one place, so that they have the correct type when passed to
610
+ * `bot.callbackQuery` in a different place. For instance, this allows for more
611
+ * modular code where handlers are defined in separate files.
612
+ */
608
613
  export declare type CallbackQueryMiddleware<C extends Context> = Middleware<CallbackQueryContext<C>>;
614
+ /**
615
+ * Type of the middleware that can be passed to `bot.gameQuery`.
616
+ *
617
+ * This helper type can be used to annotate middleware functions that are
618
+ * defined in one place, so that they have the correct type when passed to
619
+ * `bot.gameQuery` in a different place. For instance, this allows for more
620
+ * modular code where handlers are defined in separate files.
621
+ */
609
622
  export declare type GameQueryMiddleware<C extends Context> = Middleware<GameQueryContext<C>>;
623
+ /**
624
+ * Type of the middleware that can be passed to `bot.inlineQuery`.
625
+ *
626
+ * This helper type can be used to annotate middleware functions that are
627
+ * defined in one place, so that they have the correct type when passed to
628
+ * `bot.inlineQuery` in a different place. For instance, this allows for more
629
+ * modular code where handlers are defined in separate files.
630
+ */
610
631
  export declare type InlineQueryMiddleware<C extends Context> = Middleware<InlineQueryContext<C>>;
632
+ /**
633
+ * Type of the middleware that can be passed to `bot.chatType`.
634
+ *
635
+ * This helper type can be used to annotate middleware functions that are
636
+ * defined in one place, so that they have the correct type when passed to
637
+ * `bot.chatType` in a different place. For instance, this allows for more
638
+ * modular code where handlers are defined in separate files.
639
+ */
611
640
  export declare type ChatTypeMiddleware<C extends Context, T extends Chat["type"]> = Middleware<ChatTypeContext<C, T>>;
612
641
  export {};
package/out/composer.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Composer = exports.run = exports.BotError = void 0;
4
- const filter_js_1 = require("./filter.js");
4
+ const context_js_1 = require("./context.js");
5
5
  // === Middleware errors
6
6
  /**
7
7
  * This error is thrown when middleware throws. It simply wraps the original
@@ -181,7 +181,7 @@ class Composer {
181
181
  * @param middleware The middleware to register behind the given filter
182
182
  */
183
183
  on(filter, ...middleware) {
184
- return this.filter((0, filter_js_1.matchFilter)(filter), ...middleware);
184
+ return this.filter(context_js_1.Context.has.filterQuery(filter), ...middleware);
185
185
  }
186
186
  /**
187
187
  * Registers some middleware that will only be executed when the message
@@ -215,13 +215,7 @@ class Composer {
215
215
  * @param middleware The middleware to register
216
216
  */
217
217
  hears(trigger, ...middleware) {
218
- const trg = triggerFn(trigger);
219
- return this.on([":text", ":caption"]).filter((ctx) => {
220
- var _a, _b;
221
- const msg = (_a = ctx.message) !== null && _a !== void 0 ? _a : ctx.channelPost;
222
- const txt = (_b = msg.text) !== null && _b !== void 0 ? _b : msg.caption;
223
- return match(ctx, txt, trg);
224
- }, ...middleware);
218
+ return this.filter(context_js_1.Context.has.text(trigger), ...middleware);
225
219
  }
226
220
  /**
227
221
  * Registers some middleware that will only be executed when a certain
@@ -279,43 +273,7 @@ class Composer {
279
273
  * @param middleware The middleware to register
280
274
  */
281
275
  command(command, ...middleware) {
282
- const atCommands = new Set();
283
- const noAtCommands = new Set();
284
- toArray(command).forEach((cmd) => {
285
- if (cmd.startsWith("/")) {
286
- throw new Error(`Do not include '/' when registering command handlers (use '${cmd.substring(1)}' not '${cmd}')`);
287
- }
288
- const set = cmd.indexOf("@") === -1 ? noAtCommands : atCommands;
289
- set.add(cmd);
290
- });
291
- return this.on(":entities:bot_command").filter((ctx) => {
292
- var _a;
293
- const msg = (_a = ctx.message) !== null && _a !== void 0 ? _a : ctx.channelPost;
294
- const txt = msg.text;
295
- return msg.entities.some((e) => {
296
- if (e.type !== "bot_command")
297
- return false;
298
- if (e.offset !== 0)
299
- return false;
300
- const cmd = txt.substring(1, e.length);
301
- if (noAtCommands.has(cmd) || atCommands.has(cmd)) {
302
- ctx.match = txt.substring(cmd.length + 1).trimStart();
303
- return true;
304
- }
305
- const index = cmd.indexOf("@");
306
- if (index === -1)
307
- return false;
308
- const atTarget = cmd.substring(index + 1);
309
- if (atTarget !== ctx.me.username)
310
- return false;
311
- const atCommand = cmd.substring(0, index);
312
- if (noAtCommands.has(atCommand)) {
313
- ctx.match = txt.substring(cmd.length + 1).trimStart();
314
- return true;
315
- }
316
- return false;
317
- });
318
- }, ...middleware);
276
+ return this.filter(context_js_1.Context.has.command(command), ...middleware);
319
277
  }
320
278
  /**
321
279
  * Registers some middleware for certain chat types only. For example, you
@@ -349,8 +307,7 @@ class Composer {
349
307
  * @param middleware The middleware to register
350
308
  */
351
309
  chatType(chatType, ...middleware) {
352
- const set = new Set(toArray(chatType));
353
- return this.filter((ctx) => { var _a; return ((_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.type) !== undefined && set.has(ctx.chat.type); }, ...middleware);
310
+ return this.filter(context_js_1.Context.has.chatType(chatType), ...middleware);
354
311
  }
355
312
  /**
356
313
  * Registers some middleware for callback queries, i.e. the updates that
@@ -361,7 +318,7 @@ class Composer {
361
318
  * ```ts
362
319
  * bot.on('callback_query:data', ctx => { ... })
363
320
  * ```
364
- * but it also allows you match the query data agains a given text or
321
+ * but it also allows you to match the query data against a given text or
365
322
  * regular expression.
366
323
  *
367
324
  * ```ts
@@ -393,8 +350,7 @@ class Composer {
393
350
  * @param middleware The middleware to register
394
351
  */
395
352
  callbackQuery(trigger, ...middleware) {
396
- const trg = triggerFn(trigger);
397
- return this.on("callback_query:data").filter((ctx) => match(ctx, ctx.callbackQuery.data, trg), ...middleware);
353
+ return this.filter(context_js_1.Context.has.callbackQuery(trigger), ...middleware);
398
354
  }
399
355
  /**
400
356
  * Registers some middleware for game queries, i.e. the updates that
@@ -405,7 +361,7 @@ class Composer {
405
361
  * ```ts
406
362
  * bot.on('callback_query:game_short_name', ctx => { ... })
407
363
  * ```
408
- * but it also allows you match the query data agains a given text or
364
+ * but it also allows you to match the query data against a given text or
409
365
  * regular expression.
410
366
  *
411
367
  * You can pass an array of triggers. Your middleware will be executed if at
@@ -415,8 +371,7 @@ class Composer {
415
371
  * @param middleware The middleware to register
416
372
  */
417
373
  gameQuery(trigger, ...middleware) {
418
- const trg = triggerFn(trigger);
419
- return this.on("callback_query:game_short_name").filter((ctx) => match(ctx, ctx.callbackQuery.game_short_name, trg), ...middleware);
374
+ return this.filter(context_js_1.Context.has.gameQuery(trigger), ...middleware);
420
375
  }
421
376
  /**
422
377
  * Registers middleware for inline queries. Telegram sends an inline query
@@ -441,8 +396,7 @@ class Composer {
441
396
  * @param middleware The middleware to register
442
397
  */
443
398
  inlineQuery(trigger, ...middleware) {
444
- const trg = triggerFn(trigger);
445
- return this.on("inline_query").filter((ctx) => match(ctx, ctx.inlineQuery.query, trg), ...middleware);
399
+ return this.filter(context_js_1.Context.has.inlineQuery(trigger), ...middleware);
446
400
  }
447
401
  filter(predicate, ...middleware) {
448
402
  const composer = new Composer(...middleware);
@@ -457,7 +411,7 @@ class Composer {
457
411
  * other words, the middleware will only be executed if the given predicate
458
412
  * returns `false` for the given context object. Otherwise, it will be
459
413
  * skipped and the next middleware will be executed. Note that the predicate
460
- * may be asyncronous, i.e. it can return a Promise of a boolean.
414
+ * may be asynchronous, i.e. it can return a Promise of a boolean.
461
415
  *
462
416
  * This method is the same using `filter` (normal usage) with a negated
463
417
  * predicate.
@@ -525,7 +479,7 @@ class Composer {
525
479
  lazy(middlewareFactory) {
526
480
  return this.use(async (ctx, next) => {
527
481
  const middleware = await middlewareFactory(ctx);
528
- const arr = toArray(middleware);
482
+ const arr = Array.isArray(middleware) ? middleware : [middleware];
529
483
  await flatten(new Composer(...arr))(ctx, next);
530
484
  });
531
485
  }
@@ -561,7 +515,7 @@ class Composer {
561
515
  * middleware if your route function returns `undefined`, or if the key
562
516
  * returned by your router has no middleware associated with it.
563
517
  *
564
- * This method may need less setup than first instanciating a `Router`, but
518
+ * This method may need less setup than first instantiating a `Router`, but
565
519
  * for more complex setups, having a `Router` may be more readable.
566
520
  *
567
521
  * @param router The routing function to use
@@ -585,7 +539,7 @@ class Composer {
585
539
  * This method takes a predicate function that is tested once per context
586
540
  * object. If it returns `true`, the first supplied middleware is executed.
587
541
  * If it returns `false`, the second supplied middleware is executed. Note
588
- * that the predicate may be asyncronous, i.e. it can return a Promise of a
542
+ * that the predicate may be asynchronous, i.e. it can return a Promise of a
589
543
  * boolean.
590
544
  *
591
545
  * @param predicate The predicate to check
@@ -653,22 +607,3 @@ class Composer {
653
607
  }
654
608
  }
655
609
  exports.Composer = Composer;
656
- // === Util functions
657
- function triggerFn(trigger) {
658
- return toArray(trigger).map((t) => typeof t === "string"
659
- ? (txt) => (txt === t ? t : null)
660
- : (txt) => txt.match(t));
661
- }
662
- function match(ctx, content, triggers) {
663
- for (const t of triggers) {
664
- const res = t(content);
665
- if (res) {
666
- ctx.match = res;
667
- return true;
668
- }
669
- }
670
- return false;
671
- }
672
- function toArray(e) {
673
- return Array.isArray(e) ? e : [e];
674
- }