2021-01-03 01:30:57 +03:00
|
|
|
import { ContextType, ExecutionContext } from '@nestjs/common';
|
|
|
|
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
2021-09-16 21:37:59 +03:00
|
|
|
import { TgArgumentsHost } from './tg-arguments-host.interface';
|
2021-01-03 01:30:57 +03:00
|
|
|
|
|
|
|
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(0);
|
|
|
|
}
|
|
|
|
}
|