diff --git a/lib/decorators/index.ts b/lib/decorators/index.ts index 8bc9e67..340866c 100644 --- a/lib/decorators/index.ts +++ b/lib/decorators/index.ts @@ -12,3 +12,4 @@ export * from './telegraf-hashtag.decorator'; export * from './telegraf-cashtag.decorator'; export * from './telegraf-action.decorator'; export * from './telegraf-inline-query.decorator'; +export * from './telegraf-game-query.decorator'; diff --git a/lib/decorators/telegraf-game-query.decorator.ts b/lib/decorators/telegraf-game-query.decorator.ts new file mode 100644 index 0000000..8439345 --- /dev/null +++ b/lib/decorators/telegraf-game-query.decorator.ts @@ -0,0 +1,11 @@ +import { SetMetadata } from '@nestjs/common'; +import { DECORATORS } from '../telegraf.constants'; + +/** + * Registers middleware for handling callback_data actions with game query. + * + * https://telegraf.js.org/#/?id=inlinequery + */ +export function TelegrafGameQuery(): MethodDecorator { + return SetMetadata(DECORATORS.GAME_QUERY, {}); +} diff --git a/lib/telegraf-metadata.accessor.ts b/lib/telegraf-metadata.accessor.ts index 94eb7d9..b4da7bc 100644 --- a/lib/telegraf-metadata.accessor.ts +++ b/lib/telegraf-metadata.accessor.ts @@ -144,4 +144,11 @@ export class TelegrafMetadataAccessor { getTelegrafInlineQueryMetadata(target: Type | Function) { return this.reflector.get(DECORATORS.INLINE_QUERY, target); } + + isTelegrafGameQuery(target: Type | Function): boolean { + if (!target) { + return false; + } + return !!this.reflector.get(DECORATORS.GAME_QUERY, target); + } } diff --git a/lib/telegraf.constants.ts b/lib/telegraf.constants.ts index e86ca9a..c70b4b9 100644 --- a/lib/telegraf.constants.ts +++ b/lib/telegraf.constants.ts @@ -17,4 +17,5 @@ export const DECORATORS = { CASHTAG: `${DECORATORS_PREFIX}/CASHTAG`, ACTION: `${DECORATORS_PREFIX}/ACTION`, INLINE_QUERY: `${DECORATORS_PREFIX}/INLINE_QUERY`, + GAME_QUERY: `${DECORATORS_PREFIX}/GAME_QUERY`, }; diff --git a/lib/telegraf.explorer.ts b/lib/telegraf.explorer.ts index 2148959..26af964 100644 --- a/lib/telegraf.explorer.ts +++ b/lib/telegraf.explorer.ts @@ -99,6 +99,8 @@ export class TelegrafExplorer implements OnModuleInit { instance[key], ); this.handleTelegrafInlineQuery(instance, key, telegraf, metadata); + } else if (this.metadataAccessor.isTelegrafGameQuery(instance[key])) { + this.handleTelegrafGameQuery(instance, key, telegraf); } }, ); @@ -233,4 +235,12 @@ export class TelegrafExplorer implements OnModuleInit { // @ts-ignore telegraf.inlineQuery(metadata.triggers, instance[key].bind(instance)); } + + handleTelegrafGameQuery( + instance: object, + key: string, + telegraf: Telegraf, + ) { + telegraf.gameQuery(instance[key].bind(instance)); + } }