mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
refactor(): reply switch with dynamic telegraf method call
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
export * from './on.decorator';
|
||||
export * from './update.decorator';
|
||||
export * from './use.decorator';
|
||||
export * from './inject-bot.decorator';
|
||||
|
4
lib/decorators/core/inject-bot.decorator.ts
Normal file
4
lib/decorators/core/inject-bot.decorator.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { TelegrafProvider } from '../../telegraf.provider';
|
||||
|
||||
export const InjectBot = (): ParameterDecorator => Inject(TelegrafProvider);
|
@@ -1,25 +0,0 @@
|
||||
import { applyDecorators, SetMetadata } from '@nestjs/common';
|
||||
import {
|
||||
UPDATE_LISTENER_OPTIONS_METADATA,
|
||||
UPDATE_LISTENER_TYPE_METADATA,
|
||||
} from '../../telegraf.constants';
|
||||
import { ListenerType } from '../../enums/listener-type.enum';
|
||||
import { TelegrafUpdateType } from '../../telegraf.types';
|
||||
|
||||
export interface OnOptions {
|
||||
updateTypes: TelegrafUpdateType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers middleware for provided update type.
|
||||
*
|
||||
* @see https://telegraf.js.org/#/?id=on
|
||||
*/
|
||||
export const On = (updateTypes: TelegrafUpdateType): MethodDecorator => {
|
||||
return applyDecorators(
|
||||
SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.On),
|
||||
SetMetadata(UPDATE_LISTENER_OPTIONS_METADATA, {
|
||||
updateTypes,
|
||||
} as OnOptions),
|
||||
);
|
||||
};
|
@@ -1,12 +0,0 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { UPDATE_LISTENER_TYPE_METADATA } from '../../telegraf.constants';
|
||||
import { ListenerType } from '../../enums/listener-type.enum';
|
||||
|
||||
/**
|
||||
* Registers a middleware.
|
||||
*
|
||||
* @see https://telegraf.js.org/#/?id=use
|
||||
*/
|
||||
export const Use = (): MethodDecorator => {
|
||||
return SetMetadata(UPDATE_LISTENER_TYPE_METADATA, ListenerType.Use);
|
||||
};
|
Reference in New Issue
Block a user