nestjs-telegraf/lib/factories/telegraf-params-factory.ts

24 lines
678 B
TypeScript
Raw Normal View History

2021-01-03 01:30:57 +03:00
import { TelegrafParamtype } from '../enums/telegraf-paramtype.enum';
export class TelegrafParamsFactory {
exchangeKeyForValue<
TContext extends Record<string, any> = any,
TResult = any
>(type: number, ctx: TContext, next: Function): TResult {
switch (type as TelegrafParamtype) {
case TelegrafParamtype.CONTEXT:
return ctx as any;
case TelegrafParamtype.NEXT:
return next as any;
case TelegrafParamtype.SENDER:
return ctx.from;
case TelegrafParamtype.MESSAGE:
return ctx.message;
case TelegrafParamtype.MESSAGE_TEXT:
return ctx.message.text;
default:
return null;
}
}
}