nest-telegram
nest-telegram copied to clipboard
Error while starting app
Hi. When i try use your module i get error while app starting.
My module:
import { Module, NestModule } from '@nestjs/common';
import { TelegramModule as TM, TelegramBot } from 'nest-telegram';
import TelegramOptionsFactory from '../telegram';
import { ModuleRef } from '@nestjs/core';
@Module({
imports: [
TM.fromFactory({
useClass: TelegramOptionsFactory,
}),
],
})
export class TelegramModule {
constructor(
private readonly moduleRef: ModuleRef,
private readonly telegramBot: TelegramBot,
) {}
onModuleInit() {
this.telegramBot.init(this.moduleRef, true);
// this.telegramBot.startPolling();
}
}
telegram.ts:
import { TelegramModuleOptions, TelegramModuleOptionsFactory } from 'nest-telegram';
export default class TelegramOptionsFactory implements TelegramModuleOptionsFactory {
createOptions(): TelegramModuleOptions {
return {
token: process.env.TELEGRAM_TOKEN,
};
}
}
[0] [nodemon] starting `node dist/main`
[0] [Nest] 15988 - 2019-10-15 12:49:44 [NestFactory] Starting Nest application...
[0] [Nest] 15988 - 2019-10-15 12:49:44 [InstanceLoader] TelegramModule dependencies initialized +54ms
[Nest] 15988 - 2019-10-15 12:49:44 [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 15988 - 2019-10-15 12:49:44 [InstanceLoader] TelegramModule dependencies initialized +3ms
[0] [Nest] 15988 - 2019-10-15 12:49:44 [RoutesResolver] AppController {/}: +36ms
[0] [Nest] 15988 - 2019-10-15 12:49:44 [RouterExplorer] Mapped {/, GET} route +15ms
[0] (node:15988) UnhandledPromiseRejectionWarning: Error
[0] at TelegramBot.setupOnStart (C:\_DEV\_iisystem\telegram\node_modules\nest-telegram\dist\TelegramBot.js:72:19)
[0] at TelegramBot.init (C:\_DEV\_iisystem\telegram\node_modules\nest-telegram\dist\TelegramBot.js:39:14)
[0] at TelegramModule.onModuleInit (C:\_DEV\_iisystem\telegram\dist\telegram\telegram.module.js:22:26)
[0] at Object.callModuleInitHook (C:\_DEV\_iisystem\telegram\node_modules\@nestjs\core\hooks\on-module-init.hook.js:42:35)
[0] at processTicksAndRejections (internal/process/task_queues.js:85:5)
[0] at async NestApplication.callInitHook (C:\_DEV\_iisystem\telegram\node_modules\@nestjs\core\nest-application-context.js:142:13)
[0] at async NestApplication.init (C:\_DEV\_iisystem\telegram\node_modules\@nestjs\core\nest-application.js:88:9)
[0] at async NestApplication.listen (C:\_DEV\_iisystem\telegram\node_modules\@nestjs\core\nest-application.js:140:33)
[0] (node:15988) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
[0] (node:15988) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[0] [nodemon] clean exit - waiting for changes before restart
Nest.JS version: 6.8.3
Hello, thanks for reporting!
I will start investigating after my vacation and will try fix it quickly.
Deal with the problem. We have not identified any TelegramActionHandler.
The application was launched, but the bot does not respond to / start.
import { Injectable } from '@nestjs/common';
import { Context, TelegramActionHandler } from 'nest-telegram';
@Injectable()
export class BotActions {
@TelegramActionHandler({ onStart: true })
async start(ctx: Context) {
console.log('onStart');
await ctx.reply('Hello!');
}
}
It is possible that you need to specify a proxy for the bot. How to do it?
We have a SocksAgent, but we cannot specify when importing a TelegramModule.
Hello! Sorry for very long delay. Actually, I just forgot about this repo. But, now, I am here.
I release 0.6.2, with human-readable error for this issue — application must have exactly one onStart
-handler.
By the way, we can discuss this behavior, may be I made the wrong decision.
About your second question. I have never thought about it. May be, we can extend TelegramOptions and add proxy config? Actually, I don't mark this feature as musthave and maybe implement it later (before 1.0.0, of course). You can research it and make a PR, if you need this feature right now. I will be grateful. 😇