gramio 0.9.0 → 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 CHANGED
@@ -35,7 +35,8 @@ const ALL_NAMES = [
35
35
  "chat_join_request",
36
36
  "chat_boost",
37
37
  "removed_chat_boost",
38
- "managed_bot"
38
+ "managed_bot",
39
+ "guest_message"
39
40
  ];
40
41
  const MESSAGE_PARENT_TYPES = [
41
42
  "message",
@@ -204,7 +205,9 @@ const methods = composer.defineComposerMethods({
204
205
  return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
205
206
  });
206
207
  },
207
- inlineQuery(trigger, handler, options = {}) {
208
+ inlineQuery(triggerOrHandler, maybeHandler, options = {}) {
209
+ const trigger = maybeHandler === void 0 ? (() => true) : triggerOrHandler;
210
+ const handler = maybeHandler ?? triggerOrHandler;
208
211
  if (options.onResult) this.chosenInlineResult(trigger, options.onResult);
209
212
  const { onResult: _, ...macroOptions } = options;
210
213
  const hasMacros = Object.keys(macroOptions).length > 0;
@@ -229,6 +232,32 @@ const methods = composer.defineComposerMethods({
229
232
  return macroHandler ? macroHandler(context, composer.noopNext) : handler(context);
230
233
  });
231
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
+ },
232
261
  hears(trigger, handler, macroOptions) {
233
262
  const macroHandler = macroOptions ? composer.buildFromOptions(this["~"].macros, macroOptions, handler) : null;
234
263
  if (typeof trigger === "string") {
@@ -1283,49 +1312,18 @@ class Bot {
1283
1312
  );
1284
1313
  return this;
1285
1314
  }
1286
- /**
1287
- * Register handler to `inline_query` update
1288
- *
1289
- * @example
1290
- * ```ts
1291
- * new Bot().inlineQuery(
1292
- * /regular expression with (.*)/i,
1293
- * async (context) => {
1294
- * if (context.args) {
1295
- * await context.answer(
1296
- * [
1297
- * InlineQueryResult.article(
1298
- * "id-1",
1299
- * context.args[1],
1300
- * InputMessageContent.text("some"),
1301
- * {
1302
- * reply_markup: new InlineKeyboard().text(
1303
- * "some",
1304
- * "callback-data"
1305
- * ),
1306
- * }
1307
- * ),
1308
- * ],
1309
- * {
1310
- * cache_time: 0,
1311
- * }
1312
- * );
1313
- * }
1314
- * },
1315
- * {
1316
- * onResult: (context) => context.editText("Message edited!"),
1317
- * }
1318
- * );
1319
- * ```
1320
- * */
1321
- inlineQuery(trigger, handler, options) {
1315
+ inlineQuery(triggerOrHandler, handler, options) {
1322
1316
  this.updates.composer.inlineQuery(
1323
- trigger,
1317
+ triggerOrHandler,
1324
1318
  handler,
1325
1319
  options
1326
1320
  );
1327
1321
  return this;
1328
1322
  }
1323
+ guestQuery(triggerOrHandler, handler, options) {
1324
+ this.updates.composer.guestQuery(triggerOrHandler, handler, options);
1325
+ return this;
1326
+ }
1329
1327
  /**
1330
1328
  * Register handler to `message` and `business_message` event
1331
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, trigger: RegExp | string | ((context: Ctx<"inline_query">) => boolean), handler: (context: Ctx<"inline_query"> & {
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, trigger: RegExp | string | ((context: Ctx<"inline_query">) => boolean), handler: (context: Ctx<"inline_query"> & {
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;
@@ -325,6 +340,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
325
340
  edited_channel_post: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
326
341
  business_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
327
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">;
328
344
  deleted_business_messages: _gramio_contexts.BusinessMessagesDeletedContext<AnyBot>;
329
345
  business_connection: _gramio_contexts.BusinessConnectionContext<AnyBot>;
330
346
  migrate_from_chat_id: _gramio_contexts.MigrateFromChatIdContext<AnyBot>;
@@ -418,13 +434,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
418
434
  Derives?: Record<string, object>;
419
435
  };
420
436
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
421
- }>(this: TThis, trigger: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean), handler: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
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> & {
422
440
  args: RegExpMatchArray | null;
423
441
  } & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
424
442
  onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
425
443
  args: RegExpMatchArray | null;
426
444
  } & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
427
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;
428
458
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
429
459
  "~": {
430
460
  macros: MacroDefinitions;
@@ -493,13 +523,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
493
523
  Derives?: Record<string, object>;
494
524
  };
495
525
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
496
- }>(this: TThis, trigger: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean), handler: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
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> & {
497
529
  args: RegExpMatchArray | null;
498
530
  } & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
499
531
  onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
500
532
  args: RegExpMatchArray | null;
501
533
  } & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
502
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;
503
547
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
504
548
  "~": {
505
549
  macros: MacroDefinitions;
@@ -750,6 +794,8 @@ interface Plugin<Errors, Derives, Macros> {
750
794
  reaction: (typeof methods)["reaction"];
751
795
  /** Register inline query handler */
752
796
  inlineQuery: (typeof methods)["inlineQuery"];
797
+ /** Register guest query (`guest_message`) handler */
798
+ guestQuery: (typeof methods)["guestQuery"];
753
799
  /** Register chosen inline result handler */
754
800
  chosenInlineResult: (typeof methods)["chosenInlineResult"];
755
801
  /** Register deep-link parameter handler */
@@ -1517,6 +1563,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
1517
1563
  * );
1518
1564
  * ```
1519
1565
  * */
1566
+ inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(handler: (context: Ctx & {
1567
+ args: RegExpMatchArray | null;
1568
+ }) => unknown): this;
1520
1569
  inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
1521
1570
  args: RegExpMatchArray | null;
1522
1571
  }) => unknown, options?: HandlerOptions<Ctx, Macros> & {
@@ -1524,6 +1573,34 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
1524
1573
  args: RegExpMatchArray | null;
1525
1574
  }) => unknown;
1526
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;
1527
1604
  /**
1528
1605
  * Register handler to `message` and `business_message` event
1529
1606
  *
@@ -1996,7 +2073,7 @@ interface WebhookHandlerOptions {
1996
2073
  * });
1997
2074
  * ```
1998
2075
  */
1999
- declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
2076
+ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: AnyBot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
2000
2077
  response: () => any;
2001
2078
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
2002
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, trigger: RegExp | string | ((context: Ctx<"inline_query">) => boolean), handler: (context: Ctx<"inline_query"> & {
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, trigger: RegExp | string | ((context: Ctx<"inline_query">) => boolean), handler: (context: Ctx<"inline_query"> & {
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;
@@ -325,6 +340,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
325
340
  edited_channel_post: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
326
341
  business_message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
327
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">;
328
344
  deleted_business_messages: _gramio_contexts.BusinessMessagesDeletedContext<AnyBot>;
329
345
  business_connection: _gramio_contexts.BusinessConnectionContext<AnyBot>;
330
346
  migrate_from_chat_id: _gramio_contexts.MigrateFromChatIdContext<AnyBot>;
@@ -418,13 +434,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
418
434
  Derives?: Record<string, object>;
419
435
  };
420
436
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
421
- }>(this: TThis, trigger: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean), handler: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
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> & {
422
440
  args: RegExpMatchArray | null;
423
441
  } & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
424
442
  onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
425
443
  args: RegExpMatchArray | null;
426
444
  } & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
427
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;
428
458
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
429
459
  "~": {
430
460
  macros: MacroDefinitions;
@@ -493,13 +523,27 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
493
523
  Derives?: Record<string, object>;
494
524
  };
495
525
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
496
- }>(this: TThis, trigger: RegExp | string | ((context: _gramio_contexts.InlineQueryContext<AnyBot>) => boolean), handler: (context: _gramio_contexts.InlineQueryContext<AnyBot> & {
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> & {
497
529
  args: RegExpMatchArray | null;
498
530
  } & _gramio_composer.EventContextOf<TThis, "inline_query">) => unknown, options?: {
499
531
  onResult?: (context: _gramio_contexts.ChosenInlineResultContext<AnyBot> & {
500
532
  args: RegExpMatchArray | null;
501
533
  } & _gramio_composer.EventContextOf<TThis, "chosen_inline_result">) => unknown;
502
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;
503
547
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
504
548
  "~": {
505
549
  macros: MacroDefinitions;
@@ -750,6 +794,8 @@ interface Plugin<Errors, Derives, Macros> {
750
794
  reaction: (typeof methods)["reaction"];
751
795
  /** Register inline query handler */
752
796
  inlineQuery: (typeof methods)["inlineQuery"];
797
+ /** Register guest query (`guest_message`) handler */
798
+ guestQuery: (typeof methods)["guestQuery"];
753
799
  /** Register chosen inline result handler */
754
800
  chosenInlineResult: (typeof methods)["chosenInlineResult"];
755
801
  /** Register deep-link parameter handler */
@@ -1517,6 +1563,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
1517
1563
  * );
1518
1564
  * ```
1519
1565
  * */
1566
+ inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(handler: (context: Ctx & {
1567
+ args: RegExpMatchArray | null;
1568
+ }) => unknown): this;
1520
1569
  inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
1521
1570
  args: RegExpMatchArray | null;
1522
1571
  }) => unknown, options?: HandlerOptions<Ctx, Macros> & {
@@ -1524,6 +1573,34 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
1524
1573
  args: RegExpMatchArray | null;
1525
1574
  }) => unknown;
1526
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;
1527
1604
  /**
1528
1605
  * Register handler to `message` and `business_message` event
1529
1606
  *
@@ -1996,7 +2073,7 @@ interface WebhookHandlerOptions {
1996
2073
  * });
1997
2074
  * ```
1998
2075
  */
1999
- declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
2076
+ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: AnyBot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
2000
2077
  response: () => any;
2001
2078
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
2002
2079
 
package/dist/index.js CHANGED
@@ -37,7 +37,8 @@ const ALL_NAMES = [
37
37
  "chat_join_request",
38
38
  "chat_boost",
39
39
  "removed_chat_boost",
40
- "managed_bot"
40
+ "managed_bot",
41
+ "guest_message"
41
42
  ];
42
43
  const MESSAGE_PARENT_TYPES = [
43
44
  "message",
@@ -206,7 +207,9 @@ const methods = defineComposerMethods({
206
207
  return macroHandler ? macroHandler(context, noopNext) : handler(context);
207
208
  });
208
209
  },
209
- inlineQuery(trigger, handler, options = {}) {
210
+ inlineQuery(triggerOrHandler, maybeHandler, options = {}) {
211
+ const trigger = maybeHandler === void 0 ? (() => true) : triggerOrHandler;
212
+ const handler = maybeHandler ?? triggerOrHandler;
210
213
  if (options.onResult) this.chosenInlineResult(trigger, options.onResult);
211
214
  const { onResult: _, ...macroOptions } = options;
212
215
  const hasMacros = Object.keys(macroOptions).length > 0;
@@ -231,6 +234,32 @@ const methods = defineComposerMethods({
231
234
  return macroHandler ? macroHandler(context, noopNext) : handler(context);
232
235
  });
233
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
+ },
234
263
  hears(trigger, handler, macroOptions) {
235
264
  const macroHandler = macroOptions ? buildFromOptions(this["~"].macros, macroOptions, handler) : null;
236
265
  if (typeof trigger === "string") {
@@ -1285,49 +1314,18 @@ class Bot {
1285
1314
  );
1286
1315
  return this;
1287
1316
  }
1288
- /**
1289
- * Register handler to `inline_query` update
1290
- *
1291
- * @example
1292
- * ```ts
1293
- * new Bot().inlineQuery(
1294
- * /regular expression with (.*)/i,
1295
- * async (context) => {
1296
- * if (context.args) {
1297
- * await context.answer(
1298
- * [
1299
- * InlineQueryResult.article(
1300
- * "id-1",
1301
- * context.args[1],
1302
- * InputMessageContent.text("some"),
1303
- * {
1304
- * reply_markup: new InlineKeyboard().text(
1305
- * "some",
1306
- * "callback-data"
1307
- * ),
1308
- * }
1309
- * ),
1310
- * ],
1311
- * {
1312
- * cache_time: 0,
1313
- * }
1314
- * );
1315
- * }
1316
- * },
1317
- * {
1318
- * onResult: (context) => context.editText("Message edited!"),
1319
- * }
1320
- * );
1321
- * ```
1322
- * */
1323
- inlineQuery(trigger, handler, options) {
1317
+ inlineQuery(triggerOrHandler, handler, options) {
1324
1318
  this.updates.composer.inlineQuery(
1325
- trigger,
1319
+ triggerOrHandler,
1326
1320
  handler,
1327
1321
  options
1328
1322
  );
1329
1323
  return this;
1330
1324
  }
1325
+ guestQuery(triggerOrHandler, handler, options) {
1326
+ this.updates.composer.guestQuery(triggerOrHandler, handler, options);
1327
+ return this;
1328
+ }
1331
1329
  /**
1332
1330
  * Register handler to `message` and `business_message` event
1333
1331
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.9.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,10 +55,10 @@
55
55
  "author": "kravets",
56
56
  "license": "MIT",
57
57
  "devDependencies": {
58
- "@biomejs/biome": "2.4.4",
59
- "@gramio/test": "^0.5.0",
60
- "@types/bun": "^1.3.9",
61
- "@types/debug": "^4.1.12",
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"
@@ -66,14 +66,17 @@
66
66
  "dependencies": {
67
67
  "@gramio/callback-data": "^0.1.0",
68
68
  "@gramio/composer": "^0.4.1",
69
- "@gramio/contexts": "^0.6.1",
70
- "@gramio/files": "^0.4.0",
71
- "@gramio/format": "^0.7.0",
69
+ "@gramio/contexts": "^0.7.0",
70
+ "@gramio/files": "^0.5.0",
71
+ "@gramio/format": "^0.8.0",
72
72
  "@gramio/keyboards": "^1.4.0",
73
- "@gramio/types": "^9.6.1",
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
  }