Giter VIP home page Giter VIP logo

Comments (6)

Daniyar111 avatar Daniyar111 commented on May 16, 2024 2

@lasthead Hi!

app.module.ts:

@Module({
  imports: [
    ...,
    TelegrafModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      botName: 'admin',
      useFactory: async (config: ConfigService) => {
        return {
          middlewares: [adminSessions.middleware()],
          token: config.get<string>('BOT_ADMIN_TOKEN'),
          include: [AdminBotModule]
        }
      }
    }),
    TelegrafModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      botName: 'client',
      useFactory: async (config: ConfigService) => {
        return {
          middlewares: [clientSessions.middleware()],
          token: config.get<string>('BOT_CLIENT_TOKEN'),
          include: [ClientBotModule]
        }
      }
    }),
    AdminBotModule,
    ClientBotModule
  ],
  providers: [],
})
export class AppModule {}

client-bot.module.ts:

@Module({
  providers: [
    ClientBotUpdate,
    ClientBotService
  ],
  imports: []
})
export class ClientBotModule {}

admin-bot.module.ts:

@Module({
  providers: [
    AdminBotUpdate,
    AdminBotService
  ],
  imports: []
})
export class AdminBotModule {}

from nestjs-telegraf.

Daniyar111 avatar Daniyar111 commented on May 16, 2024

Solved it by dividing into 2 modules: AdminBotModule, ClientBotModule. And include: [AdminBotModule] to admin TelegrafModule.forRootAsync(), and include: [ClientBotModule] to client TelegrafModule.forRootAsync()

from nestjs-telegraf.

lasthead avatar lasthead commented on May 16, 2024

@Daniyar111 , Hi! Could you share a more detailed code of your main app.module and AdminBotModule? I trying add a second Bot to my app, but it doesn't work :(

from nestjs-telegraf.

lasthead avatar lasthead commented on May 16, 2024

@Daniyar111 , many thanks! However, I don't quite understand what to specify in middleware to divided requests from each other?

For example:
in app1.app.update.ts
@Start() async startCommand(ctx: Context) { await ctx.reply('test') }

in app2.app.update.ts i have the same method and they conflict with each other

I think I misunderstand the concept and... maybe this check needs to be implemented inside the app.update.ts

from nestjs-telegraf.

Daniyar111 avatar Daniyar111 commented on May 16, 2024

@lasthead If you did app.module and bot1.module, bot2.module as I wrote, it must not conflict with each other.. could you share your more detailed code?

I don't quite understand what to specify in middleware to divided requests from each other

Nothing need to add there.. I added just sessions to middleware, it doesn't affect to requests

maybe this check needs to be implemented inside the app.update.ts

no check needed..

just divide your code structure to

-- bot1
---- bot1.service (for working with db and etc)
---- bot1.update (for Telegram requests)
---- bot1.module (for moduling bot1)
-- bot2
---- bot2.service (for working with db and etc)
---- bot2.update (for Telegram requests)
---- bot2.module (for moduling bot2)
-- app.module

So they must work independent of each other

from nestjs-telegraf.

lasthead avatar lasthead commented on May 16, 2024

@Daniyar111 , After your comment, I rechecked my code again and... found my error. I just missed row: imports: [bot.module], to TelegrafModule.forRootAsync({ ... }) that's all 🙂. Now it works correctly.
Thank you for your help!

from nestjs-telegraf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.