diff --git a/lib/execution-context/index.ts b/lib/execution-context/index.ts index 6d91739..4150b50 100644 --- a/lib/execution-context/index.ts +++ b/lib/execution-context/index.ts @@ -1,3 +1,3 @@ export * from './tg-arguments-host.interace'; export * from './telegraf-arguments-host'; -export * from './telegraf-arguments-host'; +export * from './telegraf-execution-context'; diff --git a/lib/index.ts b/lib/index.ts index ef6e2ba..620f652 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -2,5 +2,8 @@ export * from './decorators'; export * from './interfaces'; export * from './utils'; export * from './types'; +export * from './services'; +export * from './errors'; +export * from './execution-context'; export * from './telegraf.constants'; export * from './telegraf.module'; diff --git a/lib/services/listeners-explorer.service.ts b/lib/services/listeners-explorer.service.ts index e3201a7..4f436a6 100644 --- a/lib/services/listeners-explorer.service.ts +++ b/lib/services/listeners-explorer.service.ts @@ -131,7 +131,47 @@ export class ListenersExplorerService methodName, ); - // TODO: Add callback to middleware and handle return data + const { method, args } = metadata; + composer[method](...args, (ctx: unknown, next: Function) => { + const deferredResult = listenerCallbackFn(ctx, next); + console.log(deferredResult); + }); + + /* + this.telegraf[method]( + ...args, + async (ctx: Context, next: () => Promise) => { + const defferedResult = contextHandlerFn.call(instance, ctx, next); + const result = this.pickResult(defferedResult); + fromPromise(result) + .pipe( + mergeAll(), + 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, + ): Promise> { + const result = await defferedResult; + + if (result && isFunction(result.subscribe)) { + return result; + } + + if (result instanceof Promise) { + return fromPromise(result); + } + + return of(result); + } + */ } createContextCallback>(