mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-25 07:24:39 +03:00
feat(sample-app): add multi bot instace
This commit is contained in:
parent
46249cf7ba
commit
82a9c259f6
@ -1 +1,2 @@
|
||||
export const HELLO_SCENE_ID = 'HELLO_SCENE_ID';
|
||||
export const SUPPORT_BOT_NAME = 'support';
|
||||
|
@ -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],
|
||||
}),
|
||||
],
|
||||
|
@ -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<any>, // TODO: fix any
|
||||
private readonly defaultBot: Telegraf<Context>,
|
||||
@InjectBot(SUPPORT_BOT_NAME)
|
||||
private readonly supportBot: Telegraf<Context>,
|
||||
private readonly echoService: EchoService,
|
||||
) {}
|
||||
|
||||
@Start()
|
||||
async onStart(ctx: Context): Promise<void> {
|
||||
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<void> {
|
||||
const me = await this.supportBot.telegram.getMe();
|
||||
await ctx.reply(`Greetings from ${me.first_name}`);
|
||||
}
|
||||
|
||||
@Command('scene')
|
||||
async onSceneCommand(ctx: Context): Promise<void> {
|
||||
await ctx.scene.enter(HELLO_SCENE_ID);
|
||||
|
Loading…
Reference in New Issue
Block a user