gramio 0.6.2 → 0.8.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 +1 -1
- package/dist/index.cjs +300 -23
- package/dist/index.d.cts +239 -21
- package/dist/index.d.ts +239 -21
- package/dist/index.js +296 -24
- package/dist/{utils-DqK73ALI.js → utils-1ejkKLIB.js} +8 -1
- package/dist/{utils-DCXj-tb5.cjs → utils-BKLnNOBm.cjs} +8 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -2,17 +2,147 @@ import * as _gramio_callback_data from '@gramio/callback-data';
|
|
|
2
2
|
import { CallbackData } from '@gramio/callback-data';
|
|
3
3
|
export * from '@gramio/callback-data';
|
|
4
4
|
import * as _gramio_contexts from '@gramio/contexts';
|
|
5
|
-
import { Context, ContextsMapping, BotLike,
|
|
5
|
+
import { UpdateName, MessageEventName, CustomEventName, Context, ContextsMapping, BotLike, ContextType, Attachment, AttachmentsMapping, Dice, MessageOriginUser, MessageOriginChat, MessageOriginChannel, MessageOriginHiddenUser, Message, MessageEntity, TextQuote, User, LinkPreviewOptions, ExternalReplyInfo, Chat, Giveaway, PaidMediaInfo, Game, StoryAttachment, Venue, MessageContext } from '@gramio/contexts';
|
|
6
6
|
export * from '@gramio/contexts';
|
|
7
7
|
export * from '@gramio/files';
|
|
8
8
|
export * from '@gramio/format';
|
|
9
9
|
export * from '@gramio/keyboards';
|
|
10
10
|
import * as _gramio_types from '@gramio/types';
|
|
11
|
-
import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramReactionTypeEmojiEmoji, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramMessageEntity } from '@gramio/types';
|
|
11
|
+
import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramReactionTypeEmojiEmoji, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramBotCommandScope, TelegramMessageEntity } from '@gramio/types';
|
|
12
12
|
export * from '@gramio/types';
|
|
13
13
|
import * as _gramio_composer from '@gramio/composer';
|
|
14
|
-
import { ComposerLike, MacroDefinitions, EventContextOf, EventComposer, MacroDef, Next, EventQueue, HandlerOptions, DeriveFromOptions } from '@gramio/composer';
|
|
15
|
-
export { ContextCallback, DeriveFromOptions, EventComposer, EventQueue, HandlerOptions, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, Middleware, Next, WithCtx, buildFromOptions, compose, noopNext, skip, stop } from '@gramio/composer';
|
|
14
|
+
import { ComposerLike, MacroDefinitions, CommandMeta, EventContextOf, EventComposer, MacroDef, Next, EventQueue, HandlerOptions, DeriveFromOptions } from '@gramio/composer';
|
|
15
|
+
export { CommandMeta, ContextCallback, DeriveFromOptions, EventComposer, EventQueue, HandlerOptions, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, Middleware, Next, ScopeShorthand, WithCtx, buildFromOptions, compose, noopNext, skip, stop } from '@gramio/composer';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Telegram Bot API top-level update type name.
|
|
19
|
+
* Valid values for `allowed_updates` in `getUpdates` / `setWebhook`.
|
|
20
|
+
*/
|
|
21
|
+
type AllowedUpdateName = Exclude<UpdateName, MessageEventName | CustomEventName>;
|
|
22
|
+
/** The 3 types Telegram excludes by default (must be explicitly requested). */
|
|
23
|
+
declare const OPT_IN_TYPES: readonly AllowedUpdateName[];
|
|
24
|
+
/**
|
|
25
|
+
* Maps any event name to the `AllowedUpdateName` values needed in `allowed_updates`.
|
|
26
|
+
*
|
|
27
|
+
* - Top-level update names → themselves
|
|
28
|
+
* - Sub-message events (MessageEventName) → all 5 message-carrying parent types
|
|
29
|
+
* - Unknown names (filter names like "text") → `undefined` (skipped)
|
|
30
|
+
*/
|
|
31
|
+
declare function mapEventToAllowedUpdates(event: string): readonly AllowedUpdateName[] | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Detect which of the 3 opt-in types have handlers registered.
|
|
34
|
+
* Used by `bot.start()` for default auto opt-in behavior.
|
|
35
|
+
*/
|
|
36
|
+
declare function detectOptInUpdates(registeredEvents: Set<string>): AllowedUpdateName[];
|
|
37
|
+
/**
|
|
38
|
+
* Fluent, immutable builder for the Telegram Bot API `allowed_updates` list.
|
|
39
|
+
*
|
|
40
|
+
* Instances directly extend `Array<AllowedUpdateName>`, so they can be passed
|
|
41
|
+
* wherever `allowedUpdates` is expected without any conversion.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { AllowedUpdatesFilter } from "gramio";
|
|
46
|
+
*
|
|
47
|
+
* // All updates (opt-in types included: chat_member, message_reaction, message_reaction_count)
|
|
48
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.all });
|
|
49
|
+
*
|
|
50
|
+
* // Telegram's default set (opt-in types excluded)
|
|
51
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.default });
|
|
52
|
+
*
|
|
53
|
+
* // Explicit list
|
|
54
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.only("message", "callback_query") });
|
|
55
|
+
*
|
|
56
|
+
* // All except poll events
|
|
57
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.all.except("poll", "poll_answer") });
|
|
58
|
+
*
|
|
59
|
+
* // Default + opt-in to chat_member
|
|
60
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.default.add("chat_member") });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare class AllowedUpdatesFilter extends Array<AllowedUpdateName> {
|
|
64
|
+
/** @internal use static factory methods instead */
|
|
65
|
+
constructor(updates: readonly AllowedUpdateName[]);
|
|
66
|
+
/**
|
|
67
|
+
* All update types, including the opt-in ones:
|
|
68
|
+
* `chat_member`, `message_reaction`, and `message_reaction_count`.
|
|
69
|
+
*/
|
|
70
|
+
static get all(): AllowedUpdatesFilter;
|
|
71
|
+
/**
|
|
72
|
+
* Telegram's **default** update set.
|
|
73
|
+
*
|
|
74
|
+
* Receive all updates _except_ `chat_member`, `message_reaction`, and
|
|
75
|
+
* `message_reaction_count` — the three types that Telegram requires to be
|
|
76
|
+
* explicitly listed in `allowed_updates`.
|
|
77
|
+
*
|
|
78
|
+
* This matches what Telegram does when `allowed_updates` is omitted or
|
|
79
|
+
* passed as an empty array.
|
|
80
|
+
*/
|
|
81
|
+
static get default(): AllowedUpdatesFilter;
|
|
82
|
+
/**
|
|
83
|
+
* Create a filter with **exactly** the specified update types.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* AllowedUpdatesFilter.only("message", "callback_query", "inline_query")
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
static only(...types: AllowedUpdateName[]): AllowedUpdatesFilter;
|
|
91
|
+
/**
|
|
92
|
+
* Return a new filter with the given types **added**.
|
|
93
|
+
* Already-present types are silently deduplicated.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* AllowedUpdatesFilter.default.add("chat_member", "message_reaction")
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
add(...types: AllowedUpdateName[]): AllowedUpdatesFilter;
|
|
101
|
+
/**
|
|
102
|
+
* Return a new filter with the given types **removed**.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* AllowedUpdatesFilter.all.except("poll", "poll_answer", "chosen_inline_result")
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
except(...types: AllowedUpdateName[]): AllowedUpdatesFilter;
|
|
110
|
+
/** Convert to a plain `AllowedUpdateName[]` array. */
|
|
111
|
+
toArray(): AllowedUpdateName[];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build an {@link AllowedUpdatesFilter} automatically from a bot's registered
|
|
115
|
+
* `.on()` handlers (including handlers from extended plugins).
|
|
116
|
+
*
|
|
117
|
+
* Returns **only** the update types that handlers explicitly register for.
|
|
118
|
+
* Use this for strict filtering — Telegram will only send these update types.
|
|
119
|
+
*
|
|
120
|
+
* **Note:** filter-only `.on(filterFn, handler)` and `.use()` middleware
|
|
121
|
+
* do not declare specific events and are not included.
|
|
122
|
+
* Manually `.add()` additional types if needed.
|
|
123
|
+
*
|
|
124
|
+
* Call after all handlers/plugins are registered (or after `bot.init()`).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const bot = new Bot(token)
|
|
129
|
+
* .command("start", handler)
|
|
130
|
+
* .callbackQuery("data", handler);
|
|
131
|
+
*
|
|
132
|
+
* bot.start({ allowedUpdates: buildAllowedUpdates(bot) });
|
|
133
|
+
* // → allowed_updates: ["message", "business_message", "callback_query"]
|
|
134
|
+
*
|
|
135
|
+
* // With customization:
|
|
136
|
+
* bot.start({ allowedUpdates: buildAllowedUpdates(bot).add("poll") });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function buildAllowedUpdates(bot: {
|
|
140
|
+
updates: {
|
|
141
|
+
composer: {
|
|
142
|
+
registeredEvents(): Set<string>;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
}): AllowedUpdatesFilter;
|
|
16
146
|
|
|
17
147
|
/** Symbol to determine which error kind is it */
|
|
18
148
|
declare const ErrorKind: symbol;
|
|
@@ -44,6 +174,7 @@ type Ctx<K extends keyof ContextsMapping<AnyBot>> = InstanceType<ContextsMapping
|
|
|
44
174
|
type GramIOLike<T> = ComposerLike<T> & {
|
|
45
175
|
"~": {
|
|
46
176
|
macros: MacroDefinitions;
|
|
177
|
+
commandsMeta: Map<string, CommandMeta>;
|
|
47
178
|
Derives?: Record<string, object>;
|
|
48
179
|
};
|
|
49
180
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): T;
|
|
@@ -52,6 +183,7 @@ type GramIOLike<T> = ComposerLike<T> & {
|
|
|
52
183
|
declare module "@gramio/composer" {
|
|
53
184
|
interface EventComposer<TBase, TEventMap, TIn, TOut, TExposed, TDerives, TMethods, TMacros> {
|
|
54
185
|
extend<P extends AnyPlugin>(plugin: P): EventComposer<TBase, TEventMap, TIn, TOut & P["_"]["Derives"]["global"], TExposed, TDerives & Omit<P["_"]["Derives"], "global">, TMethods, TMacros & P["_"]["Macros"]>;
|
|
186
|
+
registeredEvents(): Set<string>;
|
|
55
187
|
}
|
|
56
188
|
}
|
|
57
189
|
declare const Composer: _gramio_composer.EventComposerConstructor<Context<AnyBot>, TelegramEventMap, {
|
|
@@ -72,9 +204,11 @@ declare const Composer: _gramio_composer.EventComposerConstructor<Context<AnyBot
|
|
|
72
204
|
hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
|
|
73
205
|
args: RegExpMatchArray | null;
|
|
74
206
|
} & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
75
|
-
command<TThis extends GramIOLike<TThis>>(this: TThis, command: MaybeArray<string>,
|
|
207
|
+
command<TThis extends GramIOLike<TThis>>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: Ctx<"message"> & {
|
|
76
208
|
args: string | null;
|
|
77
|
-
} & EventContextOf<TThis, "message">) => unknown,
|
|
209
|
+
} & EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: Ctx<"message"> & {
|
|
210
|
+
args: string | null;
|
|
211
|
+
} & EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
|
|
78
212
|
startParameter<TThis extends GramIOLike<TThis>>(this: TThis, parameter: RegExp | MaybeArray<string>, handler: Handler<Ctx<"message"> & {
|
|
79
213
|
rawStartPayload: string;
|
|
80
214
|
} & EventContextOf<TThis, "message">>, macroOptions?: Record<string, unknown>): TThis;
|
|
@@ -214,6 +348,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
214
348
|
reaction<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
215
349
|
"~": {
|
|
216
350
|
macros: MacroDefinitions;
|
|
351
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
217
352
|
Derives?: Record<string, object>;
|
|
218
353
|
};
|
|
219
354
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -221,6 +356,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
221
356
|
callbackQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
222
357
|
"~": {
|
|
223
358
|
macros: MacroDefinitions;
|
|
359
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
224
360
|
Derives?: Record<string, object>;
|
|
225
361
|
};
|
|
226
362
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -230,6 +366,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
230
366
|
chosenInlineResult<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
231
367
|
"~": {
|
|
232
368
|
macros: MacroDefinitions;
|
|
369
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
233
370
|
Derives?: Record<string, object>;
|
|
234
371
|
};
|
|
235
372
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -239,6 +376,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
239
376
|
inlineQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
240
377
|
"~": {
|
|
241
378
|
macros: MacroDefinitions;
|
|
379
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
242
380
|
Derives?: Record<string, object>;
|
|
243
381
|
};
|
|
244
382
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -252,6 +390,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
252
390
|
hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
253
391
|
"~": {
|
|
254
392
|
macros: MacroDefinitions;
|
|
393
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
255
394
|
Derives?: Record<string, object>;
|
|
256
395
|
};
|
|
257
396
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -261,15 +400,19 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
261
400
|
command<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
262
401
|
"~": {
|
|
263
402
|
macros: MacroDefinitions;
|
|
403
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
264
404
|
Derives?: Record<string, object>;
|
|
265
405
|
};
|
|
266
406
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
267
|
-
}>(this: TThis, command: MaybeArray<string>,
|
|
407
|
+
}>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
268
408
|
args: string | null;
|
|
269
|
-
} & _gramio_composer.EventContextOf<TThis, "message">) => unknown,
|
|
409
|
+
} & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | _gramio_composer.CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
410
|
+
args: string | null;
|
|
411
|
+
} & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
|
|
270
412
|
startParameter<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
271
413
|
"~": {
|
|
272
414
|
macros: MacroDefinitions;
|
|
415
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
273
416
|
Derives?: Record<string, object>;
|
|
274
417
|
};
|
|
275
418
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -280,6 +423,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
280
423
|
reaction<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
281
424
|
"~": {
|
|
282
425
|
macros: MacroDefinitions;
|
|
426
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
283
427
|
Derives?: Record<string, object>;
|
|
284
428
|
};
|
|
285
429
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -287,6 +431,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
287
431
|
callbackQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
288
432
|
"~": {
|
|
289
433
|
macros: MacroDefinitions;
|
|
434
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
290
435
|
Derives?: Record<string, object>;
|
|
291
436
|
};
|
|
292
437
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -296,6 +441,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
296
441
|
chosenInlineResult<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
297
442
|
"~": {
|
|
298
443
|
macros: MacroDefinitions;
|
|
444
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
299
445
|
Derives?: Record<string, object>;
|
|
300
446
|
};
|
|
301
447
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -305,6 +451,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
305
451
|
inlineQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
306
452
|
"~": {
|
|
307
453
|
macros: MacroDefinitions;
|
|
454
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
308
455
|
Derives?: Record<string, object>;
|
|
309
456
|
};
|
|
310
457
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -318,6 +465,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
318
465
|
hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
319
466
|
"~": {
|
|
320
467
|
macros: MacroDefinitions;
|
|
468
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
321
469
|
Derives?: Record<string, object>;
|
|
322
470
|
};
|
|
323
471
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -327,15 +475,19 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
327
475
|
command<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
328
476
|
"~": {
|
|
329
477
|
macros: MacroDefinitions;
|
|
478
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
330
479
|
Derives?: Record<string, object>;
|
|
331
480
|
};
|
|
332
481
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
333
|
-
}>(this: TThis, command: MaybeArray<string>,
|
|
482
|
+
}>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
334
483
|
args: string | null;
|
|
335
|
-
} & _gramio_composer.EventContextOf<TThis, "message">) => unknown,
|
|
484
|
+
} & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | _gramio_composer.CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
485
|
+
args: string | null;
|
|
486
|
+
} & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
|
|
336
487
|
startParameter<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
337
488
|
"~": {
|
|
338
489
|
macros: MacroDefinitions;
|
|
490
|
+
commandsMeta: Map<string, _gramio_composer.CommandMeta>;
|
|
339
491
|
Derives?: Record<string, object>;
|
|
340
492
|
};
|
|
341
493
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
@@ -494,7 +646,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
494
646
|
* import { Bot } from "gramio";
|
|
495
647
|
*
|
|
496
648
|
* const bot = new Bot(process.env.TOKEN!).onStart(
|
|
497
|
-
* ({ plugins, info, updatesFrom }) => {
|
|
649
|
+
* ({ plugins, info, updatesFrom, bot }) => {
|
|
498
650
|
* console.log(`plugin list - ${plugins.join(", ")}`);
|
|
499
651
|
* console.log(`bot username is @${info.username}`);
|
|
500
652
|
* console.log(`updates from ${updatesFrom}`);
|
|
@@ -515,7 +667,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
515
667
|
* import { Bot } from "gramio";
|
|
516
668
|
*
|
|
517
669
|
* const bot = new Bot(process.env.TOKEN!).onStop(
|
|
518
|
-
* ({ plugins, info,
|
|
670
|
+
* ({ plugins, info, bot }) => {
|
|
519
671
|
* console.log(`plugin list - ${plugins.join(", ")}`);
|
|
520
672
|
* console.log(`bot username is @${info.username}`);
|
|
521
673
|
* }
|
|
@@ -720,7 +872,7 @@ declare namespace Hooks {
|
|
|
720
872
|
* import { Bot } from "gramio";
|
|
721
873
|
*
|
|
722
874
|
* const bot = new Bot(process.env.TOKEN!).onStart(
|
|
723
|
-
* ({ plugins, info, updatesFrom }) => {
|
|
875
|
+
* ({ plugins, info, updatesFrom, bot }) => {
|
|
724
876
|
* console.log(`plugin list - ${plugins.join(", ")}`);
|
|
725
877
|
* console.log(`bot username is @${info.username}`);
|
|
726
878
|
* console.log(`updates from ${updatesFrom}`);
|
|
@@ -736,6 +888,7 @@ declare namespace Hooks {
|
|
|
736
888
|
plugins: string[];
|
|
737
889
|
info: TelegramUser;
|
|
738
890
|
updatesFrom: "webhook" | "long-polling";
|
|
891
|
+
bot: BotLike;
|
|
739
892
|
}) => unknown;
|
|
740
893
|
/**
|
|
741
894
|
* Type for `onStop` hook
|
|
@@ -745,7 +898,7 @@ declare namespace Hooks {
|
|
|
745
898
|
* import { Bot } from "gramio";
|
|
746
899
|
*
|
|
747
900
|
* const bot = new Bot(process.env.TOKEN!).onStop(
|
|
748
|
-
* ({ plugins, info,
|
|
901
|
+
* ({ plugins, info, bot }) => {
|
|
749
902
|
* console.log(`plugin list - ${plugins.join(", ")}`);
|
|
750
903
|
* console.log(`bot username is @${info.username}`);
|
|
751
904
|
* }
|
|
@@ -760,6 +913,7 @@ declare namespace Hooks {
|
|
|
760
913
|
type OnStop = (context: {
|
|
761
914
|
plugins: string[];
|
|
762
915
|
info: TelegramUser;
|
|
916
|
+
bot: BotLike;
|
|
763
917
|
}) => unknown;
|
|
764
918
|
/**
|
|
765
919
|
* Type for `onResponseError` hook
|
|
@@ -823,13 +977,53 @@ interface BotStartOptions {
|
|
|
823
977
|
webhook?: BotStartOptionsWebhook;
|
|
824
978
|
longPolling?: BotStartOptionsLongPolling;
|
|
825
979
|
dropPendingUpdates?: boolean;
|
|
826
|
-
|
|
980
|
+
/**
|
|
981
|
+
* Which update types to receive from Telegram.
|
|
982
|
+
*
|
|
983
|
+
* - **`undefined`** (default) — Telegram's default set, plus automatic opt-in
|
|
984
|
+
* for `chat_member`, `message_reaction`, and `message_reaction_count` if
|
|
985
|
+
* the bot has handlers registered for them.
|
|
986
|
+
* - **`"strict"`** — only receive update types that handlers explicitly
|
|
987
|
+
* register for via `.on()`. Equivalent to `AllowedUpdatesFilter.from(bot)`.
|
|
988
|
+
* Filter-only `.on()` and `.use()` are not included.
|
|
989
|
+
* - **`AllowedUpdatesFilter` / array** — explicit list of update types.
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```typescript
|
|
993
|
+
* // Auto opt-in (default): Telegram default + auto chat_member/reaction if needed
|
|
994
|
+
* bot.start();
|
|
995
|
+
*
|
|
996
|
+
* // Strict: only registered events
|
|
997
|
+
* bot.start({ allowedUpdates: "strict" });
|
|
998
|
+
*
|
|
999
|
+
* // Manual
|
|
1000
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.all });
|
|
1001
|
+
*
|
|
1002
|
+
* // Strict + customize
|
|
1003
|
+
* bot.start({ allowedUpdates: AllowedUpdatesFilter.from(bot).add("poll") });
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
allowedUpdates?: AllowedUpdates | "strict";
|
|
827
1007
|
deleteWebhook?: boolean | "on-conflict-with-polling";
|
|
828
1008
|
}
|
|
829
1009
|
interface PollingStartOptions {
|
|
830
1010
|
dropPendingUpdates?: boolean;
|
|
831
1011
|
deleteWebhookOnConflict?: boolean;
|
|
832
1012
|
}
|
|
1013
|
+
/** Minimal key-value storage interface compatible with `@gramio/storage` */
|
|
1014
|
+
interface SyncStorage {
|
|
1015
|
+
get(key: string): string | undefined | Promise<string | undefined>;
|
|
1016
|
+
set(key: string, value: string): void | Promise<void>;
|
|
1017
|
+
}
|
|
1018
|
+
/** Options for {@link Bot.syncCommands} */
|
|
1019
|
+
interface SyncCommandsOptions {
|
|
1020
|
+
/** Storage for caching sync hashes. When provided, only changed groups trigger API calls. */
|
|
1021
|
+
storage?: SyncStorage;
|
|
1022
|
+
/** Delete commands for scopes not declared by any command. @default false */
|
|
1023
|
+
cleanUnusedScopes?: boolean;
|
|
1024
|
+
/** Command names to exclude from syncing (in addition to commands with `hide: true`) */
|
|
1025
|
+
exclude?: string[];
|
|
1026
|
+
}
|
|
833
1027
|
|
|
834
1028
|
declare class Updates {
|
|
835
1029
|
private readonly bot;
|
|
@@ -1043,7 +1237,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1043
1237
|
* import { Bot } from "gramio";
|
|
1044
1238
|
*
|
|
1045
1239
|
* const bot = new Bot(process.env.TOKEN!).onStart(
|
|
1046
|
-
* ({ plugins, info, updatesFrom }) => {
|
|
1240
|
+
* ({ plugins, info, updatesFrom, bot }) => {
|
|
1047
1241
|
* console.log(`plugin list - ${plugins.join(", ")}`);
|
|
1048
1242
|
* console.log(`bot username is @${info.username}`);
|
|
1049
1243
|
* console.log(`updates from ${updatesFrom}`);
|
|
@@ -1064,7 +1258,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1064
1258
|
* import { Bot } from "gramio";
|
|
1065
1259
|
*
|
|
1066
1260
|
* const bot = new Bot(process.env.TOKEN!).onStop(
|
|
1067
|
-
* ({ plugins, info,
|
|
1261
|
+
* ({ plugins, info, bot }) => {
|
|
1068
1262
|
* console.log(`plugin list - ${plugins.join(", ")}`);
|
|
1069
1263
|
* console.log(`bot username is @${info.username}`);
|
|
1070
1264
|
* }
|
|
@@ -1280,10 +1474,22 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1280
1474
|
* return context.send(`You message is /start ${context.args}`);
|
|
1281
1475
|
* });
|
|
1282
1476
|
* ```
|
|
1477
|
+
*
|
|
1478
|
+
* @example
|
|
1479
|
+
* ```ts
|
|
1480
|
+
* // With metadata — description will be synced via syncCommands()
|
|
1481
|
+
* new Bot().command("start", {
|
|
1482
|
+
* description: "Start the bot",
|
|
1483
|
+
* locales: { ru: "Запустить бота" },
|
|
1484
|
+
* }, (context) => context.send("Hello!"));
|
|
1485
|
+
* ```
|
|
1283
1486
|
*/
|
|
1284
1487
|
command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
|
|
1285
1488
|
args: string | null;
|
|
1286
|
-
} & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): this;
|
|
1489
|
+
} & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): typeof this;
|
|
1490
|
+
command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, meta: CommandMeta<TelegramBotCommandScope>, handler: (context: ContextType<typeof this, "message"> & {
|
|
1491
|
+
args: string | null;
|
|
1492
|
+
} & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): typeof this;
|
|
1287
1493
|
/**
|
|
1288
1494
|
* Register handler to `start` command when start parameter is matched
|
|
1289
1495
|
*
|
|
@@ -1301,6 +1507,18 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1301
1507
|
} & DeriveFromOptions<Macros, TOptions>>, options?: TOptions): this;
|
|
1302
1508
|
/** Currently not isolated!!! */
|
|
1303
1509
|
group(grouped: (bot: typeof this) => AnyBot): typeof this;
|
|
1510
|
+
/**
|
|
1511
|
+
* Sync registered command metadata with the Telegram API.
|
|
1512
|
+
*
|
|
1513
|
+
* Groups commands by `{scope, language_code}` and calls `setMyCommands` for each group.
|
|
1514
|
+
* When a `storage` is provided, hashes each payload and skips unchanged groups.
|
|
1515
|
+
*
|
|
1516
|
+
* @example
|
|
1517
|
+
* ```ts
|
|
1518
|
+
* bot.onStart(() => bot.syncCommands());
|
|
1519
|
+
* ```
|
|
1520
|
+
*/
|
|
1521
|
+
syncCommands(options?: SyncCommandsOptions): Promise<void>;
|
|
1304
1522
|
/**
|
|
1305
1523
|
* Init bot. Call it manually only if you doesn't use {@link Bot.start}
|
|
1306
1524
|
*/
|
|
@@ -1319,7 +1537,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1319
1537
|
* bot.start();
|
|
1320
1538
|
* ```
|
|
1321
1539
|
*/
|
|
1322
|
-
start({ webhook, longPolling, dropPendingUpdates, allowedUpdates, deleteWebhook: deleteWebhookRaw, }?: BotStartOptions): Promise<TelegramUser>;
|
|
1540
|
+
start({ webhook, longPolling, dropPendingUpdates, allowedUpdates: allowedUpdatesRaw, deleteWebhook: deleteWebhookRaw, }?: BotStartOptions): Promise<TelegramUser>;
|
|
1323
1541
|
/**
|
|
1324
1542
|
* Stops receiving events via long-polling or webhook
|
|
1325
1543
|
* */
|
|
@@ -1710,5 +1928,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1710
1928
|
response: () => any;
|
|
1711
1929
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1712
1930
|
|
|
1713
|
-
export { Bot, Composer, ErrorKind, Hooks, Plugin, TelegramError, Updates, filters, webhookHandler };
|
|
1714
|
-
export type { AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, DeriveDefinitions, ErrorDefinitions, Filter, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
|
|
1931
|
+
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1932
|
+
export type { AllowedUpdateName, AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, DeriveDefinitions, ErrorDefinitions, Filter, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, SyncCommandsOptions, SyncStorage, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
|