nest-telegram icon indicating copy to clipboard operation
nest-telegram copied to clipboard

Error while starting app

Open lmorningstar116 opened this issue 4 years ago • 4 comments

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

lmorningstar116 avatar Oct 15 '19 10:10 lmorningstar116

Nest.JS version: 6.8.3

lmorningstar116 avatar Oct 15 '19 11:10 lmorningstar116

Hello, thanks for reporting!

I will start investigating after my vacation and will try fix it quickly.

igorkamyshev avatar Oct 28 '19 01:10 igorkamyshev

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.

lmorningstar116 avatar Nov 14 '19 09:11 lmorningstar116

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. 😇

igorkamyshev avatar May 16 '20 14:05 igorkamyshev