From 82a9c259f6e00fb1f89ca938f06ebea50d0e0dce Mon Sep 17 00:00:00 2001 From: Morb0 Date: Sun, 3 Jan 2021 13:50:04 +0300 Subject: [PATCH] feat(sample-app): add multi bot instace --- sample/app.constants.ts | 1 + sample/app.module.ts | 8 +++++++- sample/app.update.ts | 14 +++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sample/app.constants.ts b/sample/app.constants.ts index b9cfdda..c68d247 100644 --- a/sample/app.constants.ts +++ b/sample/app.constants.ts @@ -1 +1,2 @@ export const HELLO_SCENE_ID = 'HELLO_SCENE_ID'; +export const SUPPORT_BOT_NAME = 'support'; diff --git a/sample/app.module.ts b/sample/app.module.ts index 2d177de..c7e7230 100644 --- a/sample/app.module.ts +++ b/sample/app.module.ts @@ -4,11 +4,17 @@ import { EchoService } from './echo.service'; import { AppUpdate } from './app.update'; import { HelloScene } from './scenes/hello.scene'; import { sessionMiddleware } from './middleware/session.middleware'; +import { SUPPORT_BOT_NAME } from './app.constants'; @Module({ imports: [ TelegrafModule.forRoot({ - token: '1467731595:AAHCvH65H9VQYKF9jE-E8c2rXsQBVAYseg8', // Don't steal >:( + token: '1417509321:AAEHz8a2QSAP4cTHh4Z6-ulePysFaUx4SjY', // Don't steal >:( + middlewares: [sessionMiddleware], + }), + TelegrafModule.forRoot({ + name: SUPPORT_BOT_NAME, + token: '1435922623:AAHmBmnyqroHxDbuK6OKsLV8Y_oB_Lf9E6E', // Don't steal >:( middlewares: [sessionMiddleware], }), ], diff --git a/sample/app.update.ts b/sample/app.update.ts index f3c5022..8c35359 100644 --- a/sample/app.update.ts +++ b/sample/app.update.ts @@ -1,20 +1,22 @@ import { Telegraf } from 'telegraf'; import { Command, Help, InjectBot, On, Start, Update } from '../lib'; import { EchoService } from './echo.service'; -import { HELLO_SCENE_ID } from './app.constants'; +import { HELLO_SCENE_ID, SUPPORT_BOT_NAME } from './app.constants'; import { Context } from './interfaces/context.interface'; @Update() export class AppUpdate { constructor( @InjectBot() - private readonly bot: Telegraf, // TODO: fix any + private readonly defaultBot: Telegraf, + @InjectBot(SUPPORT_BOT_NAME) + private readonly supportBot: Telegraf, private readonly echoService: EchoService, ) {} @Start() async onStart(ctx: Context): Promise { - const me = await this.bot.telegram.getMe(); + const me = await this.defaultBot.telegram.getMe(); await ctx.reply(`Hey, I'm ${me.first_name}`); } @@ -23,6 +25,12 @@ export class AppUpdate { await ctx.reply('Send me any text'); } + @Command('support') + async onSupportCommand(ctx: Context): Promise { + const me = await this.supportBot.telegram.getMe(); + await ctx.reply(`Greetings from ${me.first_name}`); + } + @Command('scene') async onSceneCommand(ctx: Context): Promise { await ctx.scene.enter(HELLO_SCENE_ID);