gramio 0.8.3 → 0.10.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/dist/index.cjs +38 -39
- package/dist/index.d.cts +86 -5
- package/dist/index.d.ts +86 -5
- package/dist/index.js +38 -39
- package/package.json +15 -12
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,9 @@ const ALL_NAMES = [
|
|
|
34
34
|
"chat_member",
|
|
35
35
|
"chat_join_request",
|
|
36
36
|
"chat_boost",
|
|
37
|
-
"removed_chat_boost"
|
|
37
|
+
"removed_chat_boost",
|
|
38
|
+
"managed_bot",
|
|
39
|
+
"guest_message"
|
|
38
40
|
];
|
|
39
41
|
const MESSAGE_PARENT_TYPES = [
|
|
40
42
|
"message",
|
|
@@ -203,7 +205,9 @@ const methods = composer.defineComposerMethods({
|
|
|
203
205
|
return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
|
|
204
206
|
});
|
|
205
207
|
},
|
|
206
|
-
inlineQuery(
|
|
208
|
+
inlineQuery(triggerOrHandler, maybeHandler, options = {}) {
|
|
209
|
+
const trigger = maybeHandler === void 0 ? (() => true) : triggerOrHandler;
|
|
210
|
+
const handler = maybeHandler ?? triggerOrHandler;
|
|
207
211
|
if (options.onResult) this.chosenInlineResult(trigger, options.onResult);
|
|
208
212
|
const { onResult: _, ...macroOptions } = options;
|
|
209
213
|
const hasMacros = Object.keys(macroOptions).length > 0;
|
|
@@ -228,6 +232,32 @@ const methods = composer.defineComposerMethods({
|
|
|
228
232
|
return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
|
|
229
233
|
});
|
|
230
234
|
},
|
|
235
|
+
guestQuery(triggerOrHandler, maybeHandler, macroOptions) {
|
|
236
|
+
const trigger = maybeHandler === void 0 ? (() => true) : triggerOrHandler;
|
|
237
|
+
const handler = maybeHandler ?? triggerOrHandler;
|
|
238
|
+
const macroHandler = macroOptions ? composer.buildFromOptions(this["~"].macros, macroOptions, handler) : null;
|
|
239
|
+
if (typeof trigger === "string") {
|
|
240
|
+
return this.on("guest_message", (context, next) => {
|
|
241
|
+
const text = context.text ?? context.caption;
|
|
242
|
+
if (text !== trigger) return next();
|
|
243
|
+
context.args = null;
|
|
244
|
+
return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
if (trigger instanceof RegExp) {
|
|
248
|
+
return this.on("guest_message", (context, next) => {
|
|
249
|
+
const text = context.text ?? context.caption;
|
|
250
|
+
if (!text || !trigger.test(text)) return next();
|
|
251
|
+
context.args = text.match(trigger);
|
|
252
|
+
return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return this.on("guest_message", (context, next) => {
|
|
256
|
+
if (!trigger(context)) return next();
|
|
257
|
+
context.args = null;
|
|
258
|
+
return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
|
|
259
|
+
});
|
|
260
|
+
},
|
|
231
261
|
hears(trigger, handler, macroOptions) {
|
|
232
262
|
const macroHandler = macroOptions ? composer.buildFromOptions(this["~"].macros, macroOptions, handler) : null;
|
|
233
263
|
if (typeof trigger === "string") {
|
|
@@ -1282,49 +1312,18 @@ class Bot {
|
|
|
1282
1312
|
);
|
|
1283
1313
|
return this;
|
|
1284
1314
|
}
|
|
1285
|
-
|
|
1286
|
-
* Register handler to `inline_query` update
|
|
1287
|
-
*
|
|
1288
|
-
* @example
|
|
1289
|
-
* ```ts
|
|
1290
|
-
* new Bot().inlineQuery(
|
|
1291
|
-
* /regular expression with (.*)/i,
|
|
1292
|
-
* async (context) => {
|
|
1293
|
-
* if (context.args) {
|
|
1294
|
-
* await context.answer(
|
|
1295
|
-
* [
|
|
1296
|
-
* InlineQueryResult.article(
|
|
1297
|
-
* "id-1",
|
|
1298
|
-
* context.args[1],
|
|
1299
|
-
* InputMessageContent.text("some"),
|
|
1300
|
-
* {
|
|
1301
|
-
* reply_markup: new InlineKeyboard().text(
|
|
1302
|
-
* "some",
|
|
1303
|
-
* "callback-data"
|
|
1304
|
-
* ),
|
|
1305
|
-
* }
|
|
1306
|
-
* ),
|
|
1307
|
-
* ],
|
|
1308
|
-
* {
|
|
1309
|
-
* cache_time: 0,
|
|
1310
|
-
* }
|
|
1311
|
-
* );
|
|
1312
|
-
* }
|
|
1313
|
-
* },
|
|
1314
|
-
* {
|
|
1315
|
-
* onResult: (context) => context.editText("Message edited!"),
|
|
1316
|
-
* }
|
|
1317
|
-
* );
|
|
1318
|
-
* ```
|
|
1319
|
-
* */
|
|
1320
|
-
inlineQuery(trigger, handler, options) {
|
|
1315
|
+
inlineQuery(triggerOrHandler, handler, options) {
|
|
1321
1316
|
this.updates.composer.inlineQuery(
|
|
1322
|
-
|
|
1317
|
+
triggerOrHandler,
|
|
1323
1318
|
handler,
|
|
1324
1319
|
options
|
|
1325
1320
|
);
|
|
1326
1321
|
return this;
|
|
1327
1322
|
}
|
|
1323
|
+
guestQuery(triggerOrHandler, handler, options) {
|
|
1324
|
+
this.updates.composer.guestQuery(triggerOrHandler, handler, options);
|
|
1325
|
+
return this;
|
|
1326
|
+
}
|
|
1328
1327
|
/**
|
|
1329
1328
|
* Register handler to `message` and `business_message` event
|
|
1330
1329
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -187,13 +187,20 @@ declare const methods: {
|
|
|
187
187
|
chosenInlineResult<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"chosen_inline_result">) => boolean), handler: (context: Ctx<"chosen_inline_result"> & {
|
|
188
188
|
args: RegExpMatchArray | null;
|
|
189
189
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
190
|
-
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis,
|
|
190
|
+
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"inline_query">) => boolean) | ((context: Ctx<"inline_query"> & {
|
|
191
|
+
args: RegExpMatchArray | null;
|
|
192
|
+
} & EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: Ctx<"inline_query"> & {
|
|
191
193
|
args: RegExpMatchArray | null;
|
|
192
194
|
} & EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
193
195
|
onResult?: (context: Ctx<"chosen_inline_result"> & {
|
|
194
196
|
args: RegExpMatchArray | null;
|
|
195
197
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
196
198
|
} & Record<string, unknown>): TThis;
|
|
199
|
+
guestQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"guest_message">) => boolean) | ((context: Ctx<"guest_message"> & {
|
|
200
|
+
args: RegExpMatchArray | null;
|
|
201
|
+
} & EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: Ctx<"guest_message"> & {
|
|
202
|
+
args: RegExpMatchArray | null;
|
|
203
|
+
} & EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
197
204
|
hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
|
|
198
205
|
args: RegExpMatchArray | null;
|
|
199
206
|
} & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
@@ -216,6 +223,7 @@ declare module "@gramio/composer" {
|
|
|
216
223
|
hears: (typeof methods)["hears"];
|
|
217
224
|
reaction: (typeof methods)["reaction"];
|
|
218
225
|
inlineQuery: (typeof methods)["inlineQuery"];
|
|
226
|
+
guestQuery: (typeof methods)["guestQuery"];
|
|
219
227
|
chosenInlineResult: (typeof methods)["chosenInlineResult"];
|
|
220
228
|
startParameter: (typeof methods)["startParameter"];
|
|
221
229
|
}
|
|
@@ -228,13 +236,20 @@ declare const Composer: _gramio_composer.EventComposerConstructor<Context<AnyBot
|
|
|
228
236
|
chosenInlineResult<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"chosen_inline_result">) => boolean), handler: (context: Ctx<"chosen_inline_result"> & {
|
|
229
237
|
args: RegExpMatchArray | null;
|
|
230
238
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
231
|
-
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis,
|
|
239
|
+
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"inline_query">) => boolean) | ((context: Ctx<"inline_query"> & {
|
|
240
|
+
args: RegExpMatchArray | null;
|
|
241
|
+
} & EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: Ctx<"inline_query"> & {
|
|
232
242
|
args: RegExpMatchArray | null;
|
|
233
243
|
} & EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
234
244
|
onResult?: (context: Ctx<"chosen_inline_result"> & {
|
|
235
245
|
args: RegExpMatchArray | null;
|
|
236
246
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
237
247
|
} & Record<string, unknown>): TThis;
|
|
248
|
+
guestQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"guest_message">) => boolean) | ((context: Ctx<"guest_message"> & {
|
|
249
|
+
args: RegExpMatchArray | null;
|
|
250
|
+
} & EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: Ctx<"guest_message"> & {
|
|
251
|
+
args: RegExpMatchArray | null;
|
|
252
|
+
} & EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
238
253
|
hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
|
|
239
254
|
args: RegExpMatchArray | null;
|
|
240
255
|
} & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
@@ -316,6 +331,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
316
331
|
invoice: _gramio_contexts.InvoiceContext<AnyBot>;
|
|
317
332
|
left_chat_member: _gramio_contexts.LeftChatMemberContext<AnyBot>;
|
|
318
333
|
location: _gramio_contexts.LocationContext<AnyBot>;
|
|
334
|
+
managed_bot: _gramio_contexts.ManagedBotContext<AnyBot>;
|
|
335
|
+
managed_bot_created: _gramio_contexts.ManagedBotCreatedContext<AnyBot>;
|
|
319
336
|
message_auto_delete_timer_changed: _gramio_contexts.MessageAutoDeleteTimerChangedContext<AnyBot>;
|
|
320
337
|
message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
321
338
|
channel_post: _gramio_contexts.MessageContext<AnyBot>;
|
|
@@ -323,6 +340,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
323
340
|
edited_channel_post: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
324
341
|
business_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
325
342
|
edited_business_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
343
|
+
guest_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
326
344
|
deleted_business_messages: _gramio_contexts.BusinessMessagesDeletedContext<AnyBot>;
|
|
327
345
|
business_connection: _gramio_contexts.BusinessConnectionContext<AnyBot>;
|
|
328
346
|
migrate_from_chat_id: _gramio_contexts.MigrateFromChatIdContext<AnyBot>;
|
|
@@ -333,6 +351,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
333
351
|
passport_data: _gramio_contexts.PassportDataContext<AnyBot>;
|
|
334
352
|
pinned_message: _gramio_contexts.PinnedMessageContext<AnyBot>;
|
|
335
353
|
poll_answer: _gramio_contexts.PollAnswerContext<AnyBot>;
|
|
354
|
+
poll_option_added: _gramio_contexts.PollOptionAddedContext<AnyBot>;
|
|
355
|
+
poll_option_deleted: _gramio_contexts.PollOptionDeletedContext<AnyBot>;
|
|
336
356
|
poll: _gramio_contexts.PollContext<AnyBot>;
|
|
337
357
|
pre_checkout_query: _gramio_contexts.PreCheckoutQueryContext<AnyBot>;
|
|
338
358
|
proximity_alert_triggered: _gramio_contexts.ProximityAlertTriggeredContext<AnyBot>;
|
|
@@ -414,13 +434,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
414
434
|
Derives?: Record<string, object>;
|
|
415
435
|
};
|
|
416
436
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
417
|
-
}>(this: TThis,
|
|
437
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean) | ((context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
438
|
+
args: RegExpMatchArray | null;
|
|
439
|
+
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
418
440
|
args: RegExpMatchArray | null;
|
|
419
441
|
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
420
442
|
onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
|
|
421
443
|
args: RegExpMatchArray | null;
|
|
422
444
|
} & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
423
445
|
} & Record<string, unknown>): TThis;
|
|
446
|
+
guestQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
447
|
+
"~": {
|
|
448
|
+
macros: MacroDefinitions;
|
|
449
|
+
commandsMeta?: Map<string, unknown>;
|
|
450
|
+
Derives?: Record<string, object>;
|
|
451
|
+
};
|
|
452
|
+
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
453
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) => boolean) | ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
454
|
+
args: RegExpMatchArray | null;
|
|
455
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
456
|
+
args: RegExpMatchArray | null;
|
|
457
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
424
458
|
hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
425
459
|
"~": {
|
|
426
460
|
macros: MacroDefinitions;
|
|
@@ -489,13 +523,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
489
523
|
Derives?: Record<string, object>;
|
|
490
524
|
};
|
|
491
525
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
492
|
-
}>(this: TThis,
|
|
526
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean) | ((context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
527
|
+
args: RegExpMatchArray | null;
|
|
528
|
+
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
493
529
|
args: RegExpMatchArray | null;
|
|
494
530
|
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
495
531
|
onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
|
|
496
532
|
args: RegExpMatchArray | null;
|
|
497
533
|
} & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
498
534
|
} & Record<string, unknown>): TThis;
|
|
535
|
+
guestQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
536
|
+
"~": {
|
|
537
|
+
macros: MacroDefinitions;
|
|
538
|
+
commandsMeta?: Map<string, unknown>;
|
|
539
|
+
Derives?: Record<string, object>;
|
|
540
|
+
};
|
|
541
|
+
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
542
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) => boolean) | ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
543
|
+
args: RegExpMatchArray | null;
|
|
544
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
545
|
+
args: RegExpMatchArray | null;
|
|
546
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
499
547
|
hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
500
548
|
"~": {
|
|
501
549
|
macros: MacroDefinitions;
|
|
@@ -746,6 +794,8 @@ interface Plugin<Errors, Derives, Macros> {
|
|
|
746
794
|
reaction: (typeof methods)["reaction"];
|
|
747
795
|
/** Register inline query handler */
|
|
748
796
|
inlineQuery: (typeof methods)["inlineQuery"];
|
|
797
|
+
/** Register guest query (`guest_message`) handler */
|
|
798
|
+
guestQuery: (typeof methods)["guestQuery"];
|
|
749
799
|
/** Register chosen inline result handler */
|
|
750
800
|
chosenInlineResult: (typeof methods)["chosenInlineResult"];
|
|
751
801
|
/** Register deep-link parameter handler */
|
|
@@ -1513,6 +1563,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1513
1563
|
* );
|
|
1514
1564
|
* ```
|
|
1515
1565
|
* */
|
|
1566
|
+
inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(handler: (context: Ctx & {
|
|
1567
|
+
args: RegExpMatchArray | null;
|
|
1568
|
+
}) => unknown): this;
|
|
1516
1569
|
inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
|
|
1517
1570
|
args: RegExpMatchArray | null;
|
|
1518
1571
|
}) => unknown, options?: HandlerOptions<Ctx, Macros> & {
|
|
@@ -1520,6 +1573,34 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1520
1573
|
args: RegExpMatchArray | null;
|
|
1521
1574
|
}) => unknown;
|
|
1522
1575
|
}): this;
|
|
1576
|
+
/**
|
|
1577
|
+
* Register handler to `guest_message` update — a message sent to the bot
|
|
1578
|
+
* from a chat where the bot is not a member, via a guest query.
|
|
1579
|
+
*
|
|
1580
|
+
* Reply with {@link MessageContext.answerGuestQuery `context.answerGuestQuery()`}
|
|
1581
|
+
* (NOT `context.send`/`context.reply`, which target a chat the bot can't post to).
|
|
1582
|
+
*
|
|
1583
|
+
* @example
|
|
1584
|
+
* ```ts
|
|
1585
|
+
* new Bot().guestQuery(/^find (.*)/i, async (context) => {
|
|
1586
|
+
* await context.answerGuestQuery({
|
|
1587
|
+
* type: "text",
|
|
1588
|
+
* text: `Looking up ${context.args?.[1]}…`,
|
|
1589
|
+
* });
|
|
1590
|
+
* });
|
|
1591
|
+
*
|
|
1592
|
+
* // No-trigger form — match any guest message:
|
|
1593
|
+
* new Bot().guestQuery(async (context) => {
|
|
1594
|
+
* await context.answerGuestQuery({ type: "text", text: "Hi!" });
|
|
1595
|
+
* });
|
|
1596
|
+
* ```
|
|
1597
|
+
* */
|
|
1598
|
+
guestQuery<Ctx = ContextType<typeof this, "guest_message">>(handler: (context: Ctx & {
|
|
1599
|
+
args: RegExpMatchArray | null;
|
|
1600
|
+
}) => unknown): this;
|
|
1601
|
+
guestQuery<Ctx = ContextType<typeof this, "guest_message">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
|
|
1602
|
+
args: RegExpMatchArray | null;
|
|
1603
|
+
}) => unknown, options?: HandlerOptions<Ctx, Macros>): this;
|
|
1523
1604
|
/**
|
|
1524
1605
|
* Register handler to `message` and `business_message` event
|
|
1525
1606
|
*
|
|
@@ -1992,7 +2073,7 @@ interface WebhookHandlerOptions {
|
|
|
1992
2073
|
* });
|
|
1993
2074
|
* ```
|
|
1994
2075
|
*/
|
|
1995
|
-
declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
2076
|
+
declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: AnyBot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
|
|
1996
2077
|
response: () => any;
|
|
1997
2078
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1998
2079
|
|
package/dist/index.d.ts
CHANGED
|
@@ -187,13 +187,20 @@ declare const methods: {
|
|
|
187
187
|
chosenInlineResult<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"chosen_inline_result">) => boolean), handler: (context: Ctx<"chosen_inline_result"> & {
|
|
188
188
|
args: RegExpMatchArray | null;
|
|
189
189
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
190
|
-
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis,
|
|
190
|
+
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"inline_query">) => boolean) | ((context: Ctx<"inline_query"> & {
|
|
191
|
+
args: RegExpMatchArray | null;
|
|
192
|
+
} & EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: Ctx<"inline_query"> & {
|
|
191
193
|
args: RegExpMatchArray | null;
|
|
192
194
|
} & EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
193
195
|
onResult?: (context: Ctx<"chosen_inline_result"> & {
|
|
194
196
|
args: RegExpMatchArray | null;
|
|
195
197
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
196
198
|
} & Record<string, unknown>): TThis;
|
|
199
|
+
guestQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"guest_message">) => boolean) | ((context: Ctx<"guest_message"> & {
|
|
200
|
+
args: RegExpMatchArray | null;
|
|
201
|
+
} & EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: Ctx<"guest_message"> & {
|
|
202
|
+
args: RegExpMatchArray | null;
|
|
203
|
+
} & EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
197
204
|
hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
|
|
198
205
|
args: RegExpMatchArray | null;
|
|
199
206
|
} & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
@@ -216,6 +223,7 @@ declare module "@gramio/composer" {
|
|
|
216
223
|
hears: (typeof methods)["hears"];
|
|
217
224
|
reaction: (typeof methods)["reaction"];
|
|
218
225
|
inlineQuery: (typeof methods)["inlineQuery"];
|
|
226
|
+
guestQuery: (typeof methods)["guestQuery"];
|
|
219
227
|
chosenInlineResult: (typeof methods)["chosenInlineResult"];
|
|
220
228
|
startParameter: (typeof methods)["startParameter"];
|
|
221
229
|
}
|
|
@@ -228,13 +236,20 @@ declare const Composer: _gramio_composer.EventComposerConstructor<Context<AnyBot
|
|
|
228
236
|
chosenInlineResult<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"chosen_inline_result">) => boolean), handler: (context: Ctx<"chosen_inline_result"> & {
|
|
229
237
|
args: RegExpMatchArray | null;
|
|
230
238
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
231
|
-
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis,
|
|
239
|
+
inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"inline_query">) => boolean) | ((context: Ctx<"inline_query"> & {
|
|
240
|
+
args: RegExpMatchArray | null;
|
|
241
|
+
} & EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: Ctx<"inline_query"> & {
|
|
232
242
|
args: RegExpMatchArray | null;
|
|
233
243
|
} & EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
234
244
|
onResult?: (context: Ctx<"chosen_inline_result"> & {
|
|
235
245
|
args: RegExpMatchArray | null;
|
|
236
246
|
} & EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
237
247
|
} & Record<string, unknown>): TThis;
|
|
248
|
+
guestQuery<TThis extends GramIOLike<TThis>>(this: TThis, triggerOrHandler: RegExp | string | ((context: Ctx<"guest_message">) => boolean) | ((context: Ctx<"guest_message"> & {
|
|
249
|
+
args: RegExpMatchArray | null;
|
|
250
|
+
} & EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: Ctx<"guest_message"> & {
|
|
251
|
+
args: RegExpMatchArray | null;
|
|
252
|
+
} & EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
238
253
|
hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
|
|
239
254
|
args: RegExpMatchArray | null;
|
|
240
255
|
} & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
@@ -316,6 +331,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
316
331
|
invoice: _gramio_contexts.InvoiceContext<AnyBot>;
|
|
317
332
|
left_chat_member: _gramio_contexts.LeftChatMemberContext<AnyBot>;
|
|
318
333
|
location: _gramio_contexts.LocationContext<AnyBot>;
|
|
334
|
+
managed_bot: _gramio_contexts.ManagedBotContext<AnyBot>;
|
|
335
|
+
managed_bot_created: _gramio_contexts.ManagedBotCreatedContext<AnyBot>;
|
|
319
336
|
message_auto_delete_timer_changed: _gramio_contexts.MessageAutoDeleteTimerChangedContext<AnyBot>;
|
|
320
337
|
message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
321
338
|
channel_post: _gramio_contexts.MessageContext<AnyBot>;
|
|
@@ -323,6 +340,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
323
340
|
edited_channel_post: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
324
341
|
business_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
325
342
|
edited_business_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
343
|
+
guest_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
326
344
|
deleted_business_messages: _gramio_contexts.BusinessMessagesDeletedContext<AnyBot>;
|
|
327
345
|
business_connection: _gramio_contexts.BusinessConnectionContext<AnyBot>;
|
|
328
346
|
migrate_from_chat_id: _gramio_contexts.MigrateFromChatIdContext<AnyBot>;
|
|
@@ -333,6 +351,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
333
351
|
passport_data: _gramio_contexts.PassportDataContext<AnyBot>;
|
|
334
352
|
pinned_message: _gramio_contexts.PinnedMessageContext<AnyBot>;
|
|
335
353
|
poll_answer: _gramio_contexts.PollAnswerContext<AnyBot>;
|
|
354
|
+
poll_option_added: _gramio_contexts.PollOptionAddedContext<AnyBot>;
|
|
355
|
+
poll_option_deleted: _gramio_contexts.PollOptionDeletedContext<AnyBot>;
|
|
336
356
|
poll: _gramio_contexts.PollContext<AnyBot>;
|
|
337
357
|
pre_checkout_query: _gramio_contexts.PreCheckoutQueryContext<AnyBot>;
|
|
338
358
|
proximity_alert_triggered: _gramio_contexts.ProximityAlertTriggeredContext<AnyBot>;
|
|
@@ -414,13 +434,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
414
434
|
Derives?: Record<string, object>;
|
|
415
435
|
};
|
|
416
436
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
417
|
-
}>(this: TThis,
|
|
437
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean) | ((context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
438
|
+
args: RegExpMatchArray | null;
|
|
439
|
+
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
418
440
|
args: RegExpMatchArray | null;
|
|
419
441
|
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
420
442
|
onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
|
|
421
443
|
args: RegExpMatchArray | null;
|
|
422
444
|
} & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
423
445
|
} & Record<string, unknown>): TThis;
|
|
446
|
+
guestQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
447
|
+
"~": {
|
|
448
|
+
macros: MacroDefinitions;
|
|
449
|
+
commandsMeta?: Map<string, unknown>;
|
|
450
|
+
Derives?: Record<string, object>;
|
|
451
|
+
};
|
|
452
|
+
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
453
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) => boolean) | ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
454
|
+
args: RegExpMatchArray | null;
|
|
455
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
456
|
+
args: RegExpMatchArray | null;
|
|
457
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
424
458
|
hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
425
459
|
"~": {
|
|
426
460
|
macros: MacroDefinitions;
|
|
@@ -489,13 +523,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
489
523
|
Derives?: Record<string, object>;
|
|
490
524
|
};
|
|
491
525
|
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
492
|
-
}>(this: TThis,
|
|
526
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean) | ((context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
527
|
+
args: RegExpMatchArray | null;
|
|
528
|
+
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown), maybeHandler?: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
|
|
493
529
|
args: RegExpMatchArray | null;
|
|
494
530
|
} & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
|
|
495
531
|
onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
|
|
496
532
|
args: RegExpMatchArray | null;
|
|
497
533
|
} & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
|
|
498
534
|
} & Record<string, unknown>): TThis;
|
|
535
|
+
guestQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
536
|
+
"~": {
|
|
537
|
+
macros: MacroDefinitions;
|
|
538
|
+
commandsMeta?: Map<string, unknown>;
|
|
539
|
+
Derives?: Record<string, object>;
|
|
540
|
+
};
|
|
541
|
+
chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
|
|
542
|
+
}>(this: TThis, triggerOrHandler: RegExp | string | ((context: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) => boolean) | ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
543
|
+
args: RegExpMatchArray | null;
|
|
544
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown), maybeHandler?: (context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
|
|
545
|
+
args: RegExpMatchArray | null;
|
|
546
|
+
} & _gramio_composer.EventContextOf<TThis, "guest_message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
|
|
499
547
|
hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
|
|
500
548
|
"~": {
|
|
501
549
|
macros: MacroDefinitions;
|
|
@@ -746,6 +794,8 @@ interface Plugin<Errors, Derives, Macros> {
|
|
|
746
794
|
reaction: (typeof methods)["reaction"];
|
|
747
795
|
/** Register inline query handler */
|
|
748
796
|
inlineQuery: (typeof methods)["inlineQuery"];
|
|
797
|
+
/** Register guest query (`guest_message`) handler */
|
|
798
|
+
guestQuery: (typeof methods)["guestQuery"];
|
|
749
799
|
/** Register chosen inline result handler */
|
|
750
800
|
chosenInlineResult: (typeof methods)["chosenInlineResult"];
|
|
751
801
|
/** Register deep-link parameter handler */
|
|
@@ -1513,6 +1563,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1513
1563
|
* );
|
|
1514
1564
|
* ```
|
|
1515
1565
|
* */
|
|
1566
|
+
inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(handler: (context: Ctx & {
|
|
1567
|
+
args: RegExpMatchArray | null;
|
|
1568
|
+
}) => unknown): this;
|
|
1516
1569
|
inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
|
|
1517
1570
|
args: RegExpMatchArray | null;
|
|
1518
1571
|
}) => unknown, options?: HandlerOptions<Ctx, Macros> & {
|
|
@@ -1520,6 +1573,34 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
1520
1573
|
args: RegExpMatchArray | null;
|
|
1521
1574
|
}) => unknown;
|
|
1522
1575
|
}): this;
|
|
1576
|
+
/**
|
|
1577
|
+
* Register handler to `guest_message` update — a message sent to the bot
|
|
1578
|
+
* from a chat where the bot is not a member, via a guest query.
|
|
1579
|
+
*
|
|
1580
|
+
* Reply with {@link MessageContext.answerGuestQuery `context.answerGuestQuery()`}
|
|
1581
|
+
* (NOT `context.send`/`context.reply`, which target a chat the bot can't post to).
|
|
1582
|
+
*
|
|
1583
|
+
* @example
|
|
1584
|
+
* ```ts
|
|
1585
|
+
* new Bot().guestQuery(/^find (.*)/i, async (context) => {
|
|
1586
|
+
* await context.answerGuestQuery({
|
|
1587
|
+
* type: "text",
|
|
1588
|
+
* text: `Looking up ${context.args?.[1]}…`,
|
|
1589
|
+
* });
|
|
1590
|
+
* });
|
|
1591
|
+
*
|
|
1592
|
+
* // No-trigger form — match any guest message:
|
|
1593
|
+
* new Bot().guestQuery(async (context) => {
|
|
1594
|
+
* await context.answerGuestQuery({ type: "text", text: "Hi!" });
|
|
1595
|
+
* });
|
|
1596
|
+
* ```
|
|
1597
|
+
* */
|
|
1598
|
+
guestQuery<Ctx = ContextType<typeof this, "guest_message">>(handler: (context: Ctx & {
|
|
1599
|
+
args: RegExpMatchArray | null;
|
|
1600
|
+
}) => unknown): this;
|
|
1601
|
+
guestQuery<Ctx = ContextType<typeof this, "guest_message">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
|
|
1602
|
+
args: RegExpMatchArray | null;
|
|
1603
|
+
}) => unknown, options?: HandlerOptions<Ctx, Macros>): this;
|
|
1523
1604
|
/**
|
|
1524
1605
|
* Register handler to `message` and `business_message` event
|
|
1525
1606
|
*
|
|
@@ -1992,7 +2073,7 @@ interface WebhookHandlerOptions {
|
|
|
1992
2073
|
* });
|
|
1993
2074
|
* ```
|
|
1994
2075
|
*/
|
|
1995
|
-
declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
2076
|
+
declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: AnyBot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
|
|
1996
2077
|
response: () => any;
|
|
1997
2078
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1998
2079
|
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,9 @@ const ALL_NAMES = [
|
|
|
36
36
|
"chat_member",
|
|
37
37
|
"chat_join_request",
|
|
38
38
|
"chat_boost",
|
|
39
|
-
"removed_chat_boost"
|
|
39
|
+
"removed_chat_boost",
|
|
40
|
+
"managed_bot",
|
|
41
|
+
"guest_message"
|
|
40
42
|
];
|
|
41
43
|
const MESSAGE_PARENT_TYPES = [
|
|
42
44
|
"message",
|
|
@@ -205,7 +207,9 @@ const methods = defineComposerMethods({
|
|
|
205
207
|
return macroHandler ? macroHandler(context, noopNext) : handler(context);
|
|
206
208
|
});
|
|
207
209
|
},
|
|
208
|
-
inlineQuery(
|
|
210
|
+
inlineQuery(triggerOrHandler, maybeHandler, options = {}) {
|
|
211
|
+
const trigger = maybeHandler === void 0 ? (() => true) : triggerOrHandler;
|
|
212
|
+
const handler = maybeHandler ?? triggerOrHandler;
|
|
209
213
|
if (options.onResult) this.chosenInlineResult(trigger, options.onResult);
|
|
210
214
|
const { onResult: _, ...macroOptions } = options;
|
|
211
215
|
const hasMacros = Object.keys(macroOptions).length > 0;
|
|
@@ -230,6 +234,32 @@ const methods = defineComposerMethods({
|
|
|
230
234
|
return macroHandler ? macroHandler(context, noopNext) : handler(context);
|
|
231
235
|
});
|
|
232
236
|
},
|
|
237
|
+
guestQuery(triggerOrHandler, maybeHandler, macroOptions) {
|
|
238
|
+
const trigger = maybeHandler === void 0 ? (() => true) : triggerOrHandler;
|
|
239
|
+
const handler = maybeHandler ?? triggerOrHandler;
|
|
240
|
+
const macroHandler = macroOptions ? buildFromOptions(this["~"].macros, macroOptions, handler) : null;
|
|
241
|
+
if (typeof trigger === "string") {
|
|
242
|
+
return this.on("guest_message", (context, next) => {
|
|
243
|
+
const text = context.text ?? context.caption;
|
|
244
|
+
if (text !== trigger) return next();
|
|
245
|
+
context.args = null;
|
|
246
|
+
return macroHandler ? macroHandler(context, noopNext) : handler(context);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (trigger instanceof RegExp) {
|
|
250
|
+
return this.on("guest_message", (context, next) => {
|
|
251
|
+
const text = context.text ?? context.caption;
|
|
252
|
+
if (!text || !trigger.test(text)) return next();
|
|
253
|
+
context.args = text.match(trigger);
|
|
254
|
+
return macroHandler ? macroHandler(context, noopNext) : handler(context);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return this.on("guest_message", (context, next) => {
|
|
258
|
+
if (!trigger(context)) return next();
|
|
259
|
+
context.args = null;
|
|
260
|
+
return macroHandler ? macroHandler(context, noopNext) : handler(context);
|
|
261
|
+
});
|
|
262
|
+
},
|
|
233
263
|
hears(trigger, handler, macroOptions) {
|
|
234
264
|
const macroHandler = macroOptions ? buildFromOptions(this["~"].macros, macroOptions, handler) : null;
|
|
235
265
|
if (typeof trigger === "string") {
|
|
@@ -1284,49 +1314,18 @@ class Bot {
|
|
|
1284
1314
|
);
|
|
1285
1315
|
return this;
|
|
1286
1316
|
}
|
|
1287
|
-
|
|
1288
|
-
* Register handler to `inline_query` update
|
|
1289
|
-
*
|
|
1290
|
-
* @example
|
|
1291
|
-
* ```ts
|
|
1292
|
-
* new Bot().inlineQuery(
|
|
1293
|
-
* /regular expression with (.*)/i,
|
|
1294
|
-
* async (context) => {
|
|
1295
|
-
* if (context.args) {
|
|
1296
|
-
* await context.answer(
|
|
1297
|
-
* [
|
|
1298
|
-
* InlineQueryResult.article(
|
|
1299
|
-
* "id-1",
|
|
1300
|
-
* context.args[1],
|
|
1301
|
-
* InputMessageContent.text("some"),
|
|
1302
|
-
* {
|
|
1303
|
-
* reply_markup: new InlineKeyboard().text(
|
|
1304
|
-
* "some",
|
|
1305
|
-
* "callback-data"
|
|
1306
|
-
* ),
|
|
1307
|
-
* }
|
|
1308
|
-
* ),
|
|
1309
|
-
* ],
|
|
1310
|
-
* {
|
|
1311
|
-
* cache_time: 0,
|
|
1312
|
-
* }
|
|
1313
|
-
* );
|
|
1314
|
-
* }
|
|
1315
|
-
* },
|
|
1316
|
-
* {
|
|
1317
|
-
* onResult: (context) => context.editText("Message edited!"),
|
|
1318
|
-
* }
|
|
1319
|
-
* );
|
|
1320
|
-
* ```
|
|
1321
|
-
* */
|
|
1322
|
-
inlineQuery(trigger, handler, options) {
|
|
1317
|
+
inlineQuery(triggerOrHandler, handler, options) {
|
|
1323
1318
|
this.updates.composer.inlineQuery(
|
|
1324
|
-
|
|
1319
|
+
triggerOrHandler,
|
|
1325
1320
|
handler,
|
|
1326
1321
|
options
|
|
1327
1322
|
);
|
|
1328
1323
|
return this;
|
|
1329
1324
|
}
|
|
1325
|
+
guestQuery(triggerOrHandler, handler, options) {
|
|
1326
|
+
this.updates.composer.guestQuery(triggerOrHandler, handler, options);
|
|
1327
|
+
return this;
|
|
1328
|
+
}
|
|
1330
1329
|
/**
|
|
1331
1330
|
* Register handler to `message` and `business_message` event
|
|
1332
1331
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "Powerful, extensible and really type-safe Telegram Bot API framework",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -55,25 +55,28 @@
|
|
|
55
55
|
"author": "kravets",
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "2.4.
|
|
59
|
-
"@gramio/test": "^0.
|
|
60
|
-
"@types/bun": "^1.3.
|
|
61
|
-
"@types/debug": "^4.1.
|
|
58
|
+
"@biomejs/biome": "2.4.14",
|
|
59
|
+
"@gramio/test": "^0.7.0",
|
|
60
|
+
"@types/bun": "^1.3.13",
|
|
61
|
+
"@types/debug": "^4.1.13",
|
|
62
62
|
"expect-type": "^1.3.0",
|
|
63
63
|
"pkgroll": "^2.27.0",
|
|
64
64
|
"typescript": "^5.9.3"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@gramio/callback-data": "^0.1.0",
|
|
68
|
-
"@gramio/composer": "0.4.1",
|
|
69
|
-
"@gramio/contexts": "0.
|
|
70
|
-
"@gramio/files": "^0.
|
|
71
|
-
"@gramio/format": "^0.
|
|
72
|
-
"@gramio/keyboards": "^1.
|
|
73
|
-
"@gramio/types": "^
|
|
68
|
+
"@gramio/composer": "^0.4.1",
|
|
69
|
+
"@gramio/contexts": "^0.7.0",
|
|
70
|
+
"@gramio/files": "^0.5.0",
|
|
71
|
+
"@gramio/format": "^0.8.0",
|
|
72
|
+
"@gramio/keyboards": "^1.4.0",
|
|
73
|
+
"@gramio/types": "^10.0.0",
|
|
74
74
|
"debug": "^4.4.3"
|
|
75
75
|
},
|
|
76
76
|
"files": [
|
|
77
77
|
"dist"
|
|
78
|
-
]
|
|
78
|
+
],
|
|
79
|
+
"overrides": {
|
|
80
|
+
"@gramio/types": "$@gramio/types"
|
|
81
|
+
}
|
|
79
82
|
}
|