mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
feat(listeners-explorer): remove callback return value handling
This commit is contained in:
parent
31008b04c9
commit
2030f086bf
@ -4,6 +4,7 @@ import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|||||||
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
|
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
|
||||||
import { Module } from '@nestjs/core/injector/module';
|
import { Module } from '@nestjs/core/injector/module';
|
||||||
import { ParamMetadata } from '@nestjs/core/helpers/interfaces';
|
import { ParamMetadata } from '@nestjs/core/helpers/interfaces';
|
||||||
|
import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
|
||||||
import { BaseScene, Composer, Stage, Telegraf } from 'telegraf';
|
import { BaseScene, Composer, Stage, Telegraf } from 'telegraf';
|
||||||
|
|
||||||
import { MetadataAccessorService } from './metadata-accessor.service';
|
import { MetadataAccessorService } from './metadata-accessor.service';
|
||||||
@ -13,9 +14,8 @@ import {
|
|||||||
TELEGRAF_MODULE_OPTIONS,
|
TELEGRAF_MODULE_OPTIONS,
|
||||||
} from '../telegraf.constants';
|
} from '../telegraf.constants';
|
||||||
import { BaseExplorerService } from './base-explorer.service';
|
import { BaseExplorerService } from './base-explorer.service';
|
||||||
import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
|
|
||||||
import { TelegrafParamsFactory } from '../factories/telegraf-params-factory';
|
import { TelegrafParamsFactory } from '../factories/telegraf-params-factory';
|
||||||
import { TelegrafContextType } from '../execution-context/telegraf-execution-context';
|
import { TelegrafContextType } from '../execution-context';
|
||||||
import { TelegrafModuleOptions } from '../interfaces';
|
import { TelegrafModuleOptions } from '../interfaces';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -132,46 +132,20 @@ export class ListenersExplorerService
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { method, args } = metadata;
|
const { method, args } = metadata;
|
||||||
composer[method](...args, (ctx: unknown, next: Function) => {
|
composer[method](...args, listenerCallbackFn);
|
||||||
const deferredResult = listenerCallbackFn(ctx, next);
|
|
||||||
console.log(deferredResult);
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
/* Complex callback return value handing */
|
||||||
this.telegraf[method](
|
// composer[method](
|
||||||
...args,
|
// ...args,
|
||||||
async (ctx: Context, next: () => Promise<void>) => {
|
// async (ctx: Context, next: Function): Promise<void> => {
|
||||||
const defferedResult = contextHandlerFn.call(instance, ctx, next);
|
// const result = await listenerCallbackFn(ctx, next);
|
||||||
const result = this.pickResult(defferedResult);
|
//
|
||||||
fromPromise(result)
|
// // TODO: Add more supported return types
|
||||||
.pipe(
|
// if (typeof result === 'string') {
|
||||||
mergeAll(),
|
// await ctx.reply(result);
|
||||||
filter((response: any) => !isNil(response)),
|
// }
|
||||||
)
|
// },
|
||||||
.subscribe((text) => {
|
// );
|
||||||
// TODO: More processing method return logic (files, images, etc)
|
|
||||||
// Example: https://github.com/nestjs/nest/blob/01dc358aade27d3d7ca510506696aa62bfb1cc43/packages/platform-socket.io/adapters/io-adapter.ts#L56
|
|
||||||
return ctx.reply(text);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
private async pickResult(
|
|
||||||
defferedResult: Promise<any>,
|
|
||||||
): Promise<Observable<any>> {
|
|
||||||
const result = await defferedResult;
|
|
||||||
|
|
||||||
if (result && isFunction(result.subscribe)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result instanceof Promise) {
|
|
||||||
return fromPromise(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return of(result);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createContextCallback<T extends Record<string, unknown>>(
|
createContextCallback<T extends Record<string, unknown>>(
|
||||||
|
Loading…
Reference in New Issue
Block a user