From fcaa89d09707b5cf2d12bef32a6e926c8422697d Mon Sep 17 00:00:00 2001 From: Morb0 Date: Wed, 6 Jan 2021 20:51:26 +0300 Subject: [PATCH] feat(listeners-explorer): convert callback return data to string and reply --- lib/services/listeners-explorer.service.ts | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/services/listeners-explorer.service.ts b/lib/services/listeners-explorer.service.ts index fa7ef5d..ad9aade 100644 --- a/lib/services/listeners-explorer.service.ts +++ b/lib/services/listeners-explorer.service.ts @@ -5,7 +5,7 @@ import { MetadataScanner } from '@nestjs/core/metadata-scanner'; import { Module } from '@nestjs/core/injector/module'; 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, Context, Stage, Telegraf } from 'telegraf'; import { MetadataAccessorService } from './metadata-accessor.service'; import { @@ -132,20 +132,19 @@ export class ListenersExplorerService ); const { method, args } = metadata; - composer[method](...args, listenerCallbackFn); + + /* Basic callback */ + // composer[method](...args, listenerCallbackFn); /* Complex callback return value handing */ - // composer[method]( - // ...args, - // async (ctx: Context, next: Function): Promise => { - // const result = await listenerCallbackFn(ctx, next); - // - // // TODO: Add more supported return types - // if (typeof result === 'string') { - // await ctx.reply(result); - // } - // }, - // ); + composer[method]( + ...args, + async (ctx: Context, next: Function): Promise => { + const result = await listenerCallbackFn(ctx, next); + await ctx.reply(String(result)); + // TODO-Possible-Feature: Add more supported return types + }, + ); } createContextCallback>(