mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-01-12 15:11:05 +03:00
feat(decorators): TelegrafInlineQuery added
This commit is contained in:
parent
76e0eee3ad
commit
f65905ed0d
@ -11,3 +11,4 @@ export * from './telegraf-phone.decorator';
|
|||||||
export * from './telegraf-hashtag.decorator';
|
export * from './telegraf-hashtag.decorator';
|
||||||
export * from './telegraf-cashtag.decorator';
|
export * from './telegraf-cashtag.decorator';
|
||||||
export * from './telegraf-action.decorator';
|
export * from './telegraf-action.decorator';
|
||||||
|
export * from './telegraf-inline-query.decorator';
|
||||||
|
14
lib/decorators/telegraf-inline-query.decorator.ts
Normal file
14
lib/decorators/telegraf-inline-query.decorator.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { SetMetadata } from '@nestjs/common';
|
||||||
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
export type Triggers = string | string[] | RegExp | RegExp[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers middleware for handling inline_query actions with regular expressions.
|
||||||
|
* @param triggers Triggers
|
||||||
|
*
|
||||||
|
* https://telegraf.js.org/#/?id=inlinequery
|
||||||
|
*/
|
||||||
|
export function TelegrafInlineQuery(triggers: Triggers): MethodDecorator {
|
||||||
|
return SetMetadata(DECORATORS.INLINE_QUERY, { triggers });
|
||||||
|
}
|
@ -133,4 +133,15 @@ export class TelegrafMetadataAccessor {
|
|||||||
getTelegrafActionMetadata(target: Type<any> | Function) {
|
getTelegrafActionMetadata(target: Type<any> | Function) {
|
||||||
return this.reflector.get(DECORATORS.ACTION, target);
|
return this.reflector.get(DECORATORS.ACTION, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isTelegrafInlineQuery(target: Type<any> | Function): boolean {
|
||||||
|
if (!target) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !!this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTelegrafInlineQueryMetadata(target: Type<any> | Function) {
|
||||||
|
return this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,5 @@ export const DECORATORS = {
|
|||||||
HASHTAG: `${DECORATORS_PREFIX}/HASHTAG`,
|
HASHTAG: `${DECORATORS_PREFIX}/HASHTAG`,
|
||||||
CASHTAG: `${DECORATORS_PREFIX}/CASHTAG`,
|
CASHTAG: `${DECORATORS_PREFIX}/CASHTAG`,
|
||||||
ACTION: `${DECORATORS_PREFIX}/ACTION`,
|
ACTION: `${DECORATORS_PREFIX}/ACTION`,
|
||||||
|
INLINE_QUERY: `${DECORATORS_PREFIX}/INLINE_QUERY`,
|
||||||
};
|
};
|
||||||
|
@ -92,6 +92,13 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance[key],
|
instance[key],
|
||||||
);
|
);
|
||||||
this.handleTelegrafAction(instance, key, telegraf, metadata);
|
this.handleTelegrafAction(instance, key, telegraf, metadata);
|
||||||
|
} else if (
|
||||||
|
this.metadataAccessor.isTelegrafInlineQuery(instance[key])
|
||||||
|
) {
|
||||||
|
const metadata = this.metadataAccessor.getTelegrafInlineQueryMetadata(
|
||||||
|
instance[key],
|
||||||
|
);
|
||||||
|
this.handleTelegrafInlineQuery(instance, key, telegraf, metadata);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -216,4 +223,14 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
) {
|
) {
|
||||||
telegraf.action(metadata.triggers, instance[key].bind(instance));
|
telegraf.action(metadata.triggers, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTelegrafInlineQuery(
|
||||||
|
instance: object,
|
||||||
|
key: string,
|
||||||
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
|
metadata: any,
|
||||||
|
) {
|
||||||
|
// @ts-ignore
|
||||||
|
telegraf.inlineQuery(metadata.triggers, instance[key].bind(instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user