mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-23 22:52:59 +03:00
43816099a6
This reverts commit 2d23eba148
.
34 lines
914 B
TypeScript
34 lines
914 B
TypeScript
import { ContextType, ExecutionContext } from '@nestjs/common';
|
|
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
|
import { TgArgumentsHost } from './tg-arguments-host.interface';
|
|
|
|
export type TelegrafContextType = 'telegraf' | ContextType;
|
|
|
|
export class TelegrafExecutionContext
|
|
extends ExecutionContextHost
|
|
implements TgArgumentsHost
|
|
{
|
|
static create(context: ExecutionContext): TelegrafExecutionContext {
|
|
const type = context.getType();
|
|
const tgContext = new TelegrafExecutionContext(
|
|
context.getArgs(),
|
|
context.getClass(),
|
|
context.getHandler(),
|
|
);
|
|
tgContext.setType(type);
|
|
return tgContext;
|
|
}
|
|
|
|
getType<TContext extends string = TelegrafContextType>(): TContext {
|
|
return super.getType();
|
|
}
|
|
|
|
getContext<T = any>(): T {
|
|
return this.getArgByIndex(0);
|
|
}
|
|
|
|
getNext<T = any>(): T {
|
|
return this.getArgByIndex(1);
|
|
}
|
|
}
|