feat!(): add custom execution context

This commit is contained in:
Morb0
2021-01-03 01:30:57 +03:00
parent 85bb916709
commit af632ea471
64 changed files with 899 additions and 69 deletions

View File

@@ -0,0 +1,23 @@
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;
}
}
}