mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
feat!(): add custom execution context
This commit is contained in:
23
lib/factories/telegraf-params-factory.ts
Normal file
23
lib/factories/telegraf-params-factory.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user