mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-25 23:44:39 +03:00
43816099a6
This reverts commit 2d23eba148
.
29 lines
884 B
TypeScript
29 lines
884 B
TypeScript
import { ParamData } from '@nestjs/common';
|
|
import { ParamsFactory } from '@nestjs/core/helpers/external-context-creator';
|
|
import { Context } from 'telegraf';
|
|
import { TelegrafParamtype } from '../enums/telegraf-paramtype.enum';
|
|
|
|
export class TelegrafParamsFactory implements ParamsFactory {
|
|
exchangeKeyForValue(
|
|
type: TelegrafParamtype,
|
|
data: ParamData,
|
|
args: unknown[],
|
|
): unknown {
|
|
const ctx = args[0] as Context;
|
|
const next = args[1] as Function;
|
|
|
|
switch (type) {
|
|
case TelegrafParamtype.CONTEXT:
|
|
return ctx;
|
|
case TelegrafParamtype.NEXT:
|
|
return next;
|
|
case TelegrafParamtype.SENDER:
|
|
return data && ctx.from ? ctx.from[data as string] : ctx.from;
|
|
case TelegrafParamtype.MESSAGE:
|
|
return data && ctx.message ? ctx.message[data as string] : ctx.message;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
}
|