grammy 1.12.0 β†’ 1.12.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 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-6.2-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-6.3-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-)
@@ -237,6 +237,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
237
237
  <td align="center"><a href="http://xditya.me/"><img src="https://avatars.githubusercontent.com/u/58950863?v=4?s=100" width="100px;" alt="Aditya"/><br /><sub><b>Aditya</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Axditya" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Axditya" title="Reviewed Pull Requests">πŸ‘€</a></td>
238
238
  <td align="center"><a href="http://uditkaro.de"><img src="https://avatars.githubusercontent.com/u/30829387?v=4?s=100" width="100px;" alt="Udit Karode"/><br /><sub><b>Udit Karode</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Auditkarode" title="Reviewed Pull Requests">πŸ‘€</a></td>
239
239
  <td align="center"><a href="https://rockett.pw"><img src="https://avatars.githubusercontent.com/u/4586280?v=4?s=100" width="100px;" alt="Mike RockΓ©tt"/><br /><sub><b>Mike RockΓ©tt</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Amikerockett" title="Reviewed Pull Requests">πŸ‘€</a></td>
240
+ <td align="center"><a href="https://github.com/MrVSiK"><img src="https://avatars.githubusercontent.com/u/79159341?v=4?s=100" width="100px;" alt="Srinivasa IK Varanasi"/><br /><sub><b>Srinivasa IK Varanasi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=MrVSiK" title="Code">πŸ’»</a></td>
241
+ <td align="center"><a href="https://github.com/abdoo9"><img src="https://avatars.githubusercontent.com/u/63903814?v=4?s=100" width="100px;" alt="abdoo9"/><br /><sub><b>abdoo9</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aabdoo9" title="Bug reports">πŸ›</a> <a href="https://github.com/grammyjs/grammY/commits?author=abdoo9" title="Code">πŸ’»</a></td>
242
+ </tr>
243
+ <tr>
244
+ <td align="center"><a href="http://ak4zh.com"><img src="https://avatars.githubusercontent.com/u/26350053?v=4?s=100" width="100px;" alt="ak4zh"/><br /><sub><b>ak4zh</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Aak4zh" title="Reviewed Pull Requests">πŸ‘€</a> <a href="#ideas-ak4zh" title="Ideas, Planning, & Feedback">πŸ€”</a> <a href="https://github.com/grammyjs/grammY/commits?author=ak4zh" title="Code">πŸ’»</a></td>
245
+ <td align="center"><a href="https://github.com/nlapshin"><img src="https://avatars.githubusercontent.com/u/39495311?v=4?s=100" width="100px;" alt="Nikolay Lapshin"/><br /><sub><b>Nikolay Lapshin</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=nlapshin" title="Code">πŸ’»</a></td>
240
246
  </tr>
241
247
  </tbody>
242
248
  </table>
package/out/bot.d.ts CHANGED
@@ -49,7 +49,7 @@ export { BotError };
49
49
  * Error handler that can be installed on a bot to catch error thrown by
50
50
  * middleware.
51
51
  */
52
- export declare type ErrorHandler<C extends Context = Context> = (error: BotError<C>) => unknown;
52
+ export type ErrorHandler<C extends Context = Context> = (error: BotError<C>) => unknown;
53
53
  /**
54
54
  * Options to pass to the bot when creating it.
55
55
  */
package/out/bot.js CHANGED
@@ -287,8 +287,8 @@ you can circumvent this protection against memory leaks.`);
287
287
  this.pollingRunning = false;
288
288
  (_a = this.pollingAbortController) === null || _a === void 0 ? void 0 : _a.abort();
289
289
  const offset = this.lastTriedUpdateId + 1;
290
- await this.api.getUpdates({ offset, limit: 1 });
291
- this.pollingAbortController = undefined;
290
+ await this.api.getUpdates({ offset, limit: 1 })
291
+ .finally(() => this.pollingAbortController = undefined);
292
292
  }
293
293
  else {
294
294
  debug("Bot is not running!");
package/out/composer.d.ts CHANGED
@@ -1,7 +1,7 @@
1
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
3
  import { type Chat } from "./types.js";
4
- declare type MaybePromise<T> = T | Promise<T>;
4
+ type MaybePromise<T> = T | Promise<T>;
5
5
  /**
6
6
  * A function of this type is passed as the second parameter to all middleware.
7
7
  * Invoke it to call the downstream middleware and pass on the control flow.
@@ -13,11 +13,11 @@ declare type MaybePromise<T> = T | Promise<T>;
13
13
  * Once the `Promise` returned by this function resolves, the downstream
14
14
  * middleware is done executing, hence returning the control.
15
15
  */
16
- export declare type NextFunction = () => Promise<void>;
16
+ export type NextFunction = () => Promise<void>;
17
17
  /**
18
18
  * Middleware in the form of a function.
19
19
  */
20
- export declare type MiddlewareFn<C extends Context = Context> = (ctx: C, next: NextFunction) => MaybePromise<unknown>;
20
+ export type MiddlewareFn<C extends Context = Context> = (ctx: C, next: NextFunction) => MaybePromise<unknown>;
21
21
  /**
22
22
  * Middleware in the form of a container for a function.
23
23
  */
@@ -67,7 +67,7 @@ export interface MiddlewareObj<C extends Context = Context> {
67
67
  * more advanced things about middleware, check out the
68
68
  * [documentation](https://grammy.dev/guide/middleware.html) on the website.
69
69
  */
70
- export declare type Middleware<C extends Context = Context> = MiddlewareFn<C> | MiddlewareObj<C>;
70
+ export type Middleware<C extends Context = Context> = MiddlewareFn<C> | MiddlewareObj<C>;
71
71
  /**
72
72
  * This error is thrown when middleware throws. It simply wraps the original
73
73
  * error (accessible via the `error` property), but also provides access to the
@@ -592,7 +592,7 @@ export declare class Composer<C extends Context> implements MiddlewareObj<C> {
592
592
  * `bot.hears` in a different place. For instance, this allows for more modular
593
593
  * code where handlers are defined in separate files.
594
594
  */
595
- export declare type HearsMiddleware<C extends Context> = Middleware<HearsContext<C>>;
595
+ export type HearsMiddleware<C extends Context> = Middleware<HearsContext<C>>;
596
596
  /**
597
597
  * Type of the middleware that can be passed to `bot.command`.
598
598
  *
@@ -601,7 +601,7 @@ export declare type HearsMiddleware<C extends Context> = Middleware<HearsContext
601
601
  * `bot.command` in a different place. For instance, this allows for more
602
602
  * modular code where handlers are defined in separate files.
603
603
  */
604
- export declare type CommandMiddleware<C extends Context> = Middleware<CommandContext<C>>;
604
+ export type CommandMiddleware<C extends Context> = Middleware<CommandContext<C>>;
605
605
  /**
606
606
  * Type of the middleware that can be passed to `bot.callbackQuery`.
607
607
  *
@@ -610,7 +610,7 @@ export declare type CommandMiddleware<C extends Context> = Middleware<CommandCon
610
610
  * `bot.callbackQuery` in a different place. For instance, this allows for more
611
611
  * modular code where handlers are defined in separate files.
612
612
  */
613
- export declare type CallbackQueryMiddleware<C extends Context> = Middleware<CallbackQueryContext<C>>;
613
+ export type CallbackQueryMiddleware<C extends Context> = Middleware<CallbackQueryContext<C>>;
614
614
  /**
615
615
  * Type of the middleware that can be passed to `bot.gameQuery`.
616
616
  *
@@ -619,7 +619,7 @@ export declare type CallbackQueryMiddleware<C extends Context> = Middleware<Call
619
619
  * `bot.gameQuery` in a different place. For instance, this allows for more
620
620
  * modular code where handlers are defined in separate files.
621
621
  */
622
- export declare type GameQueryMiddleware<C extends Context> = Middleware<GameQueryContext<C>>;
622
+ export type GameQueryMiddleware<C extends Context> = Middleware<GameQueryContext<C>>;
623
623
  /**
624
624
  * Type of the middleware that can be passed to `bot.inlineQuery`.
625
625
  *
@@ -628,7 +628,7 @@ export declare type GameQueryMiddleware<C extends Context> = Middleware<GameQuer
628
628
  * `bot.inlineQuery` in a different place. For instance, this allows for more
629
629
  * modular code where handlers are defined in separate files.
630
630
  */
631
- export declare type InlineQueryMiddleware<C extends Context> = Middleware<InlineQueryContext<C>>;
631
+ export type InlineQueryMiddleware<C extends Context> = Middleware<InlineQueryContext<C>>;
632
632
  /**
633
633
  * Type of the middleware that can be passed to `bot.chatType`.
634
634
  *
@@ -637,5 +637,5 @@ export declare type InlineQueryMiddleware<C extends Context> = Middleware<Inline
637
637
  * `bot.chatType` in a different place. For instance, this allows for more
638
638
  * modular code where handlers are defined in separate files.
639
639
  */
640
- export declare type ChatTypeMiddleware<C extends Context, T extends Chat["type"]> = Middleware<ChatTypeContext<C, T>>;
640
+ export type ChatTypeMiddleware<C extends Context, T extends Chat["type"]> = Middleware<ChatTypeContext<C, T>>;
641
641
  export {};
package/out/context.d.ts CHANGED
@@ -2,14 +2,14 @@ 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
4
  import { type Chat, type ChatPermissions, type InlineQueryResult, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type LabeledPrice, type Message, type PassportElementError, type Update, type User, type UserFromGetMe } from "./types.js";
5
- export declare type MaybeArray<T> = T | T[];
6
- export declare type StringWithSuggestions<S extends string> = (string & {}) | S;
7
- declare type Other<M extends Methods<RawApi>, X extends string = never> = OtherApi<RawApi, M, X>;
8
- declare type SnakeToCamelCase<S extends string> = S extends `${infer L}_${infer R}` ? `${L}${Capitalize<SnakeToCamelCase<R>>}` : S;
9
- export declare type AliasProps<U> = {
5
+ export type MaybeArray<T> = T | T[];
6
+ export type StringWithSuggestions<S extends string> = (string & {}) | S;
7
+ type Other<M extends Methods<RawApi>, X extends string = never> = OtherApi<RawApi, M, X>;
8
+ type SnakeToCamelCase<S extends string> = S extends `${infer L}_${infer R}` ? `${L}${Capitalize<SnakeToCamelCase<R>>}` : S;
9
+ export type AliasProps<U> = {
10
10
  [K in string & keyof U as SnakeToCamelCase<K>]: U[K];
11
11
  };
12
- declare type RenamedUpdate = AliasProps<Omit<Update, "update_id">>;
12
+ type RenamedUpdate = AliasProps<Omit<Update, "update_id">>;
13
13
  interface StaticHas {
14
14
  /**
15
15
  * Generates a predicate function that can test context objects for matching
@@ -470,7 +470,7 @@ export declare class Context implements RenamedUpdate {
470
470
  *
471
471
  * **Official reference:** https://core.telegram.org/bots/api#sendchataction
472
472
  */
473
- replyWithChatAction(action: "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_voice" | "upload_document" | "find_location" | "record_video_note" | "upload_video_note", signal?: AbortSignal): Promise<true>;
473
+ replyWithChatAction(action: "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_voice" | "upload_document" | "choose_sticker" | "find_location" | "record_video_note" | "upload_video_note", signal?: AbortSignal): Promise<true>;
474
474
  /**
475
475
  * Context-aware alias for `api.getUserProfilePhotos`. Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
476
476
  *
@@ -804,12 +804,12 @@ export declare class Context implements RenamedUpdate {
804
804
  *
805
805
  * **Official reference:** https://core.telegram.org/bots/api#createforumtopic
806
806
  */
807
- createForumTopic(name: string, other?: Other<"createForumTopic", "chat_id" | "name">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ForumTopic[]>;
807
+ createForumTopic(name: string, other?: Other<"createForumTopic", "chat_id" | "name">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ForumTopic>;
808
808
  /**
809
809
  * Context-aware alias for `api.editForumTopic`. Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
810
810
  *
811
811
  * @param name New topic name, 1-128 characters
812
- * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers
812
+ * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
813
813
  * @param signal Optional `AbortSignal` to cancel the request
814
814
  *
815
815
  * **Official reference:** https://core.telegram.org/bots/api#editforumtopic
@@ -1045,7 +1045,7 @@ export declare class Context implements RenamedUpdate {
1045
1045
  */
1046
1046
  replyWithGame(game_short_name: string, other?: Other<"sendGame", "chat_id" | "game_short_name">, signal?: AbortSignal): Promise<Message.GameMessage>;
1047
1047
  }
1048
- declare type HearsContextCore = FilterCore<":text" | ":caption"> & NarrowMatchCore<string | RegExpMatchArray>;
1048
+ type HearsContextCore = FilterCore<":text" | ":caption"> & NarrowMatchCore<string | RegExpMatchArray>;
1049
1049
  /**
1050
1050
  * Type of the context object that is available inside the handlers for
1051
1051
  * `bot.hears`.
@@ -1056,8 +1056,8 @@ declare type HearsContextCore = FilterCore<":text" | ":caption"> & NarrowMatchCo
1056
1056
  * the correct type automatically. That way, handlers can be defined in separate
1057
1057
  * files and still have the correct types.
1058
1058
  */
1059
- export declare type HearsContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, ":text" | ":caption">;
1060
- declare type CommandContextCore = FilterCore<":entities:bot_command"> & NarrowMatchCore<string>;
1059
+ export type HearsContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, ":text" | ":caption">;
1060
+ type CommandContextCore = FilterCore<":entities:bot_command"> & NarrowMatchCore<string>;
1061
1061
  /**
1062
1062
  * Type of the context object that is available inside the handlers for
1063
1063
  * `bot.command`.
@@ -1068,14 +1068,14 @@ declare type CommandContextCore = FilterCore<":entities:bot_command"> & NarrowMa
1068
1068
  * the correct type automatically. That way, handlers can be defined in separate
1069
1069
  * files and still have the correct types.
1070
1070
  */
1071
- export declare type CommandContext<C extends Context> = Filter<NarrowMatch<C, string>, ":entities:bot_command">;
1072
- declare type NarrowMatchCore<T extends Context["match"]> = {
1071
+ export type CommandContext<C extends Context> = Filter<NarrowMatch<C, string>, ":entities:bot_command">;
1072
+ type NarrowMatchCore<T extends Context["match"]> = {
1073
1073
  match: T;
1074
1074
  };
1075
- declare type NarrowMatch<C extends Context, T extends C["match"]> = {
1075
+ type NarrowMatch<C extends Context, T extends C["match"]> = {
1076
1076
  [K in keyof C]: K extends "match" ? (T extends C[K] ? T : never) : C[K];
1077
1077
  };
1078
- declare type CallbackQueryContextCore = FilterCore<"callback_query:data">;
1078
+ type CallbackQueryContextCore = FilterCore<"callback_query:data">;
1079
1079
  /**
1080
1080
  * Type of the context object that is available inside the handlers for
1081
1081
  * `bot.callbackQuery`.
@@ -1086,8 +1086,8 @@ declare type CallbackQueryContextCore = FilterCore<"callback_query:data">;
1086
1086
  * inferring the correct type automatically. That way, handlers can be defined
1087
1087
  * in separate files and still have the correct types.
1088
1088
  */
1089
- export declare type CallbackQueryContext<C extends Context> = Filter<C, "callback_query:data">;
1090
- declare type GameQueryContextCore = FilterCore<"callback_query:game_short_name">;
1089
+ export type CallbackQueryContext<C extends Context> = Filter<NarrowMatch<C, string | RegExpMatchArray>, "callback_query:data">;
1090
+ type GameQueryContextCore = FilterCore<"callback_query:game_short_name">;
1091
1091
  /**
1092
1092
  * Type of the context object that is available inside the handlers for
1093
1093
  * `bot.gameQuery`.
@@ -1098,8 +1098,8 @@ declare type GameQueryContextCore = FilterCore<"callback_query:game_short_name">
1098
1098
  * inferring the correct type automatically. That way, handlers can be defined
1099
1099
  * in separate files and still have the correct types.
1100
1100
  */
1101
- export declare type GameQueryContext<C extends Context> = Filter<C, "callback_query:game_short_name">;
1102
- declare type InlineQueryContextCore = FilterCore<"inline_query">;
1101
+ export type GameQueryContext<C extends Context> = Filter<C, "callback_query:game_short_name">;
1102
+ type InlineQueryContextCore = FilterCore<"inline_query">;
1103
1103
  /**
1104
1104
  * Type of the context object that is available inside the handlers for
1105
1105
  * `bot.inlineQuery`.
@@ -1110,8 +1110,8 @@ declare type InlineQueryContextCore = FilterCore<"inline_query">;
1110
1110
  * inferring the correct type automatically. That way, handlers can be defined
1111
1111
  * in separate files and still have the correct types.
1112
1112
  */
1113
- export declare type InlineQueryContext<C extends Context> = Filter<C, "inline_query">;
1114
- declare type ChatTypeContextCore<T extends Chat["type"]> = Record<"update", ChatTypeUpdate<T>> & ChatType<T> & ChatTypeRecord<"msg", T> & AliasProps<ChatTypeUpdate<T>>;
1113
+ export type InlineQueryContext<C extends Context> = Filter<C, "inline_query">;
1114
+ type ChatTypeContextCore<T extends Chat["type"]> = Record<"update", ChatTypeUpdate<T>> & ChatType<T> & ChatTypeRecord<"msg", T> & AliasProps<ChatTypeUpdate<T>>;
1115
1115
  /**
1116
1116
  * Type of the context object that is available inside the handlers for
1117
1117
  * `bot.chatType`.
@@ -1122,12 +1122,12 @@ declare type ChatTypeContextCore<T extends Chat["type"]> = Record<"update", Chat
1122
1122
  * the correct type automatically. That way, handlers can be defined in separate
1123
1123
  * files and still have the correct types.
1124
1124
  */
1125
- export declare type ChatTypeContext<C extends Context, T extends Chat["type"]> = C & ChatTypeContextCore<T>;
1126
- 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>>> & ConstrainUpdatesByChatType<T>;
1127
- declare type ConstrainUpdatesByChatType<T extends Chat["type"]> = Record<[
1125
+ export type ChatTypeContext<C extends Context, T extends Chat["type"]> = C & ChatTypeContextCore<T>;
1126
+ 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>>> & ConstrainUpdatesByChatType<T>;
1127
+ type ConstrainUpdatesByChatType<T extends Chat["type"]> = Record<[
1128
1128
  T
1129
1129
  ] extends ["channel"] ? "message" | "edited_message" : "channel_post" | "edited_channel_post", undefined>;
1130
- declare type ChatTypeRecord<K extends string, T extends Chat["type"]> = Partial<Record<K, ChatType<T>>>;
1130
+ type ChatTypeRecord<K extends string, T extends Chat["type"]> = Partial<Record<K, ChatType<T>>>;
1131
1131
  interface ChatType<T extends Chat["type"]> {
1132
1132
  chat: {
1133
1133
  type: T;
package/out/context.js CHANGED
@@ -980,7 +980,7 @@ class Context {
980
980
  * Context-aware alias for `api.editForumTopic`. Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
981
981
  *
982
982
  * @param name New topic name, 1-128 characters
983
- * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers
983
+ * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
984
984
  * @param signal Optional `AbortSignal` to cancel the request
985
985
  *
986
986
  * **Official reference:** https://core.telegram.org/bots/api#editforumtopic
@@ -22,6 +22,21 @@ export declare const adapters: {
22
22
  respond: (json: string) => any;
23
23
  unauthorized: () => any;
24
24
  };
25
+ "std/http": (req: Request) => {
26
+ update: Promise<any>;
27
+ header: string | undefined;
28
+ end: () => void;
29
+ respond: (json: string) => void;
30
+ unauthorized: () => void;
31
+ handlerReturn: Promise<unknown>;
32
+ };
33
+ oak: (ctx: any) => {
34
+ update: any;
35
+ header: any;
36
+ end: () => number;
37
+ respond: (json: string) => void;
38
+ unauthorized: () => void;
39
+ };
25
40
  http: (req: IncomingMessage, res: ServerResponse) => {
26
41
  update: Promise<any>;
27
42
  header: string | undefined;
@@ -67,5 +82,15 @@ export declare const adapters: {
67
82
  respond: (json: string) => any;
68
83
  unauthorized: () => any;
69
84
  };
85
+ sveltekit: ({ request }: {
86
+ request: Request;
87
+ }) => {
88
+ update: Promise<any>;
89
+ header: string | undefined;
90
+ end: () => void;
91
+ respond: (json: string) => void;
92
+ unauthorized: () => void;
93
+ handlerReturn: Promise<unknown>;
94
+ };
70
95
  };
71
96
  export declare const defaultAdapter = "express";
@@ -65,6 +65,38 @@ const nextJs = (req, res) => ({
65
65
  respond: (json) => res.status(200).json(json),
66
66
  unauthorized: () => res.status(401).send("secret token is wrong"),
67
67
  });
68
+ /** Sveltekit Serverless Functions */
69
+ const sveltekit = ({ request }) => {
70
+ var _a;
71
+ let resolveResponse;
72
+ return {
73
+ update: Promise.resolve(request.json()),
74
+ header: (_a = request.headers.get(frameworks_shared_js_1.SECRET_HEADER)) !== null && _a !== void 0 ? _a : undefined,
75
+ end: () => {
76
+ if (resolveResponse)
77
+ resolveResponse(new Response());
78
+ },
79
+ respond: (json) => {
80
+ if (resolveResponse) {
81
+ const res = new Response(json, {
82
+ headers: { "Content-Type": "application/json" },
83
+ });
84
+ resolveResponse(res);
85
+ }
86
+ },
87
+ unauthorized: () => {
88
+ if (resolveResponse) {
89
+ const res = new Response("secret token is wrong", {
90
+ status: 401,
91
+ });
92
+ resolveResponse(res);
93
+ }
94
+ },
95
+ handlerReturn: new Promise((resolve) => {
96
+ resolveResponse = resolve;
97
+ }),
98
+ };
99
+ };
68
100
  // please open a PR if you want to add another
69
101
  exports.adapters = {
70
102
  http,
@@ -73,6 +105,7 @@ exports.adapters = {
73
105
  "aws-lambda": awsLambda,
74
106
  azure,
75
107
  "next-js": nextJs,
108
+ sveltekit,
76
109
  ...frameworks_shared_js_1.adapters,
77
110
  };
78
111
  exports.defaultAdapter = "express";
@@ -21,4 +21,19 @@ export declare const adapters: {
21
21
  respond: (json: string) => any;
22
22
  unauthorized: () => any;
23
23
  };
24
+ "std/http": (req: Request) => {
25
+ update: Promise<any>;
26
+ header: string | undefined;
27
+ end: () => void;
28
+ respond: (json: string) => void;
29
+ unauthorized: () => void;
30
+ handlerReturn: Promise<unknown>;
31
+ };
32
+ oak: (ctx: any) => {
33
+ update: any;
34
+ header: any;
35
+ end: () => number;
36
+ respond: (json: string) => void;
37
+ unauthorized: () => void;
38
+ };
24
39
  };
@@ -39,8 +39,54 @@ const fastify = (req, reply) => ({
39
39
  respond: (json) => reply.send(json),
40
40
  unauthorized: () => reply.code(401).send("secret token is wrong"),
41
41
  });
42
+ /** std/http web server */
43
+ const stdHttp = (req) => {
44
+ let resolveResponse;
45
+ return {
46
+ update: req.json(),
47
+ header: req.headers.get(exports.SECRET_HEADER) || undefined,
48
+ end: () => {
49
+ if (resolveResponse)
50
+ resolveResponse(new Response());
51
+ },
52
+ respond: (json) => {
53
+ if (resolveResponse) {
54
+ const res = new Response(json, {
55
+ headers: { "Content-Type": "application/json" },
56
+ });
57
+ resolveResponse(res);
58
+ }
59
+ },
60
+ unauthorized: () => {
61
+ if (resolveResponse) {
62
+ const res = new Response("secret token is wrong", {
63
+ status: 401,
64
+ });
65
+ resolveResponse(res);
66
+ }
67
+ },
68
+ handlerReturn: new Promise((resolve) => {
69
+ resolveResponse = resolve;
70
+ }),
71
+ };
72
+ };
73
+ /** oak web framework */
74
+ const oak = (ctx) => ({
75
+ update: ctx.request.body({ type: "json" }).value,
76
+ header: ctx.request.headers.get(exports.SECRET_HEADER) || undefined,
77
+ end: () => (ctx.response.status = 200),
78
+ respond: (json) => {
79
+ ctx.response.type = "json";
80
+ ctx.response.body = json;
81
+ },
82
+ unauthorized: () => {
83
+ ctx.response.status = 401;
84
+ },
85
+ });
42
86
  exports.adapters = {
43
87
  express,
44
88
  koa,
45
89
  fastify,
90
+ "std/http": stdHttp,
91
+ oak,
46
92
  };
@@ -0,0 +1 @@
1
+ export declare const adapters: {};
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adapters = void 0;
4
+ exports.adapters = {};
@@ -1,6 +1,6 @@
1
1
  import { type MiddlewareFn } from "../composer.js";
2
2
  import { type Context } from "../context.js";
3
- declare type MaybePromise<T> = Promise<T> | T;
3
+ type MaybePromise<T> = Promise<T> | T;
4
4
  /**
5
5
  * A session flavor is a context flavor that holds session data under
6
6
  * `ctx.session`.
@@ -124,10 +124,10 @@ export interface SessionOptions<S> {
124
124
  * Options for session middleware if multi sessions are used. Specify `"type":
125
125
  * "multi"` in the options to use multi sessions.
126
126
  */
127
- export declare type MultiSessionOptions<S> = S extends Record<string, any> ? {
127
+ export type MultiSessionOptions<S> = S extends Record<string, any> ? {
128
128
  type: "multi";
129
129
  } & MultiSessionOptionsRecord<S> : never;
130
- declare type MultiSessionOptionsRecord<S extends Record<string, unknown>> = {
130
+ type MultiSessionOptionsRecord<S extends Record<string, unknown>> = {
131
131
  [K in keyof S]: SessionOptions<S[K]>;
132
132
  };
133
133
  /**
@@ -25,6 +25,21 @@ declare const adapters: {
25
25
  respond: (json: string) => any;
26
26
  unauthorized: () => any;
27
27
  };
28
+ "std/http": (req: Request) => {
29
+ update: Promise<any>;
30
+ header: string | undefined;
31
+ end: () => void;
32
+ respond: (json: string) => void;
33
+ unauthorized: () => void;
34
+ handlerReturn: Promise<unknown>;
35
+ };
36
+ oak: (ctx: any) => {
37
+ update: any;
38
+ header: any;
39
+ end: () => number;
40
+ respond: (json: string) => void;
41
+ unauthorized: () => void;
42
+ };
28
43
  http: (req: import("http").IncomingMessage, res: import("http").ServerResponse) => {
29
44
  update: Promise<any>;
30
45
  header: string | undefined;
@@ -70,12 +85,22 @@ declare const adapters: {
70
85
  respond: (json: string) => any;
71
86
  unauthorized: () => any;
72
87
  };
88
+ sveltekit: ({ request }: {
89
+ request: Request;
90
+ }) => {
91
+ update: Promise<any>;
92
+ header: string | undefined;
93
+ end: () => void;
94
+ respond: (json: string) => void;
95
+ unauthorized: () => void;
96
+ handlerReturn: Promise<unknown>;
97
+ };
73
98
  };
74
99
  /**
75
100
  * HTTP Web frameworks for which grammY provides compatible callback out of the
76
101
  * box.
77
102
  */
78
- declare type SupportedFrameworks = keyof typeof adapters;
103
+ type SupportedFrameworks = keyof typeof adapters;
79
104
  /**
80
105
  * Abstraction over a request-response cycle, providing access to the update, as
81
106
  * well as a mechanism for responding to the request and to end it.
@@ -116,7 +141,7 @@ interface ReqResHandler {
116
141
  * Middleware for a web framework. Creates a request-response handler for a
117
142
  * request. The handler will be used to integrate with the compatible framework.
118
143
  */
119
- export declare type FrameworkAdapter = (...args: any[]) => ReqResHandler;
144
+ export type FrameworkAdapter = (...args: any[]) => ReqResHandler;
120
145
  export interface WebhookOptions {
121
146
  /** An optional strategy to handle timeouts (default: 'throw') */
122
147
  onTimeout?: "throw" | "return" | ((...args: any[]) => unknown);
package/out/core/api.d.ts CHANGED
@@ -4,7 +4,7 @@ import { type ApiClientOptions, type Methods, type Payload, type RawApi, type Tr
4
4
  * Helper type to derive remaining properties of a given API method call M,
5
5
  * given that some properties X have already been specified.
6
6
  */
7
- export declare type Other<R extends RawApi, M extends Methods<R>, X extends string = never> = Omit<Payload<M, R>, X>;
7
+ export type Other<R extends RawApi, M extends Methods<R>, X extends string = never> = Omit<Payload<M, R>, X>;
8
8
  /**
9
9
  * This class provides access to the full Telegram Bot API. All methods of the
10
10
  * API have an equivalent on this class, with the most important parameters
@@ -378,7 +378,7 @@ export declare class Api<R extends RawApi = RawApi> {
378
378
  *
379
379
  * **Official reference:** https://core.telegram.org/bots/api#sendchataction
380
380
  */
381
- sendChatAction(chat_id: number | string, action: "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_voice" | "upload_document" | "find_location" | "record_video_note" | "upload_video_note", signal?: AbortSignal): Promise<true>;
381
+ sendChatAction(chat_id: number | string, action: "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_voice" | "upload_document" | "choose_sticker" | "find_location" | "record_video_note" | "upload_video_note", signal?: AbortSignal): Promise<true>;
382
382
  /**
383
383
  * Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
384
384
  *
@@ -705,14 +705,14 @@ export declare class Api<R extends RawApi = RawApi> {
705
705
  *
706
706
  * **Official reference:** https://core.telegram.org/bots/api#createforumtopic
707
707
  */
708
- createForumTopic(chat_id: number | string, name: string, other?: Other<R, "createForumTopic", "chat_id" | "name">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ForumTopic[]>;
708
+ createForumTopic(chat_id: number | string, name: string, other?: Other<R, "createForumTopic", "chat_id" | "name">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ForumTopic>;
709
709
  /**
710
710
  * Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
711
711
  *
712
712
  * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
713
713
  * @param message_thread_id Unique identifier for the target message thread of the forum topic
714
714
  * @param name New topic name, 1-128 characters
715
- * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers
715
+ * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
716
716
  * @param signal Optional `AbortSignal` to cancel the request
717
717
  *
718
718
  * **Official reference:** https://core.telegram.org/bots/api#editforumtopic
@@ -1195,4 +1195,4 @@ export declare class Api<R extends RawApi = RawApi> {
1195
1195
  */
1196
1196
  getGameHighScoresInline(inline_message_id: string, user_id: number, signal?: AbortSignal): Promise<import("@grammyjs/types/message.js").GameHighScore[]>;
1197
1197
  }
1198
- import { AbortSignal } from "../shim.node.js";
1198
+ import { AbortSignal } from "./../shim.node.js";
package/out/core/api.js CHANGED
@@ -805,7 +805,7 @@ class Api {
805
805
  * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
806
806
  * @param message_thread_id Unique identifier for the target message thread of the forum topic
807
807
  * @param name New topic name, 1-128 characters
808
- * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers
808
+ * @param icon_custom_emoji_id New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
809
809
  * @param signal Optional `AbortSignal` to cancel the request
810
810
  *
811
811
  * **Official reference:** https://core.telegram.org/bots/api#editforumtopic
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node-fetch" />
2
2
  import { type ApiMethods as Telegram, type ApiResponse, type Opts } from "../types.js";
3
- export declare type Methods<R extends RawApi> = string & keyof R;
3
+ export type Methods<R extends RawApi> = string & keyof R;
4
4
  /**
5
5
  * Represents the raw Telegram Bot API with all methods specified 1:1 as
6
6
  * documented on the website (https://core.telegram.org/bots/api).
@@ -8,10 +8,10 @@ export declare type Methods<R extends RawApi> = string & keyof R;
8
8
  * Every method takes an optional `AbortSignal` object that allows to cancel the
9
9
  * API call if desired.
10
10
  */
11
- export declare type RawApi = {
11
+ export type RawApi = {
12
12
  [M in keyof Telegram]: Parameters<Telegram[M]>[0] extends undefined ? (signal?: AbortSignal) => Promise<ReturnType<Telegram[M]>> : (args: Opts<M>, signal?: AbortSignal) => Promise<ReturnType<Telegram[M]>>;
13
13
  };
14
- export declare type Payload<M extends Methods<R>, R extends RawApi> = M extends unknown ? R[M] extends (signal?: AbortSignal) => unknown ? {} : R[M] extends (args: any, signal?: AbortSignal) => unknown ? Parameters<R[M]>[0] : never : never;
14
+ export type Payload<M extends Methods<R>, R extends RawApi> = M extends unknown ? R[M] extends (signal?: AbortSignal) => unknown ? {} : R[M] extends (args: any, signal?: AbortSignal) => unknown ? Parameters<R[M]>[0] : never : never;
15
15
  /**
16
16
  * Small utility interface that abstracts from webhook reply calls of different
17
17
  * web frameworks.
@@ -22,8 +22,8 @@ export interface WebhookReplyEnvelope {
22
22
  /**
23
23
  * Type of a function that can perform an API call. Used for Transformers.
24
24
  */
25
- export declare type ApiCallFn<R extends RawApi = RawApi> = <M extends Methods<R>>(method: M, payload: Payload<M, R>, signal?: AbortSignal) => Promise<ApiResponse<ApiCallResult<M, R>>>;
26
- declare type ApiCallResult<M extends Methods<R>, R extends RawApi> = R[M] extends (...args: unknown[]) => unknown ? Awaited<ReturnType<R[M]>> : never;
25
+ export type ApiCallFn<R extends RawApi = RawApi> = <M extends Methods<R>>(method: M, payload: Payload<M, R>, signal?: AbortSignal) => Promise<ApiResponse<ApiCallResult<M, R>>>;
26
+ type ApiCallResult<M extends Methods<R>, R extends RawApi> = R[M] extends (...args: unknown[]) => unknown ? Awaited<ReturnType<R[M]>> : never;
27
27
  /**
28
28
  * API call transformers are functions that can access and modify the method and
29
29
  * payload of an API call on the fly. This can be useful if you want to
@@ -33,8 +33,8 @@ declare type ApiCallResult<M extends Methods<R>, R extends RawApi> = R[M] extend
33
33
  * [documentation](https://grammy.dev/advanced/transformers.html) to read more
34
34
  * about how to use transformers.
35
35
  */
36
- export declare type Transformer<R extends RawApi = RawApi> = <M extends Methods<R>>(prev: ApiCallFn<R>, method: M, payload: Payload<M, R>, signal?: AbortSignal) => Promise<ApiResponse<ApiCallResult<M, R>>>;
37
- export declare type TransformerConsumer<R extends RawApi = RawApi> = TransformableApi<R>["use"];
36
+ export type Transformer<R extends RawApi = RawApi> = <M extends Methods<R>>(prev: ApiCallFn<R>, method: M, payload: Payload<M, R>, signal?: AbortSignal) => Promise<ApiResponse<ApiCallResult<M, R>>>;
37
+ export type TransformerConsumer<R extends RawApi = RawApi> = TransformableApi<R>["use"];
38
38
  /**
39
39
  * A transformable API enhances the `RawApi` type by transformers.
40
40
  */
@@ -159,5 +159,5 @@ export interface ApiClientOptions {
159
159
  * @param webhookReplyEnvelope The webhook reply envelope that will be used
160
160
  */
161
161
  export declare function createRawApi<R extends RawApi>(token: string, options?: ApiClientOptions, webhookReplyEnvelope?: WebhookReplyEnvelope): TransformableApi<R>;
162
- import { AbortSignal, fetch } from "../shim.node.js";
162
+ import { AbortSignal, fetch } from "./../shim.node.js";
163
163
  export {};
@@ -177,4 +177,4 @@ function createAbortControllerFromSignal(signal) {
177
177
  sig.addEventListener("abort", abort);
178
178
  return { abort, signal: abortController.signal };
179
179
  }
180
- const shim_node_js_1 = require("../shim.node.js");
180
+ const shim_node_js_1 = require("./../shim.node.js");