2020-12-29 22:41:06 +03:00
|
|
|
import { SceneContext, Telegraf } from 'telegraf';
|
|
|
|
import { Command, Help, InjectBot, On, Start, Update } from '../lib';
|
2020-12-26 16:48:04 +03:00
|
|
|
import { EchoService } from './echo.service';
|
2020-12-29 22:41:06 +03:00
|
|
|
import { HELLO_SCENE_ID } from './app.constants';
|
|
|
|
import { Context } from './interfaces/context.interface';
|
2020-12-26 16:23:54 +03:00
|
|
|
|
|
|
|
@Update()
|
|
|
|
export class AppUpdate {
|
2020-12-26 16:48:04 +03:00
|
|
|
constructor(
|
|
|
|
@InjectBot()
|
2020-12-29 22:41:06 +03:00
|
|
|
private readonly bot: Telegraf<SceneContext>,
|
2020-12-26 16:48:04 +03:00
|
|
|
private readonly echoService: EchoService,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
@Start()
|
|
|
|
async onStart(ctx: Context): Promise<void> {
|
|
|
|
const me = await this.bot.telegram.getMe();
|
|
|
|
await ctx.reply(`Hey, I'm ${me.first_name}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Help()
|
|
|
|
async onHelp(ctx: Context): Promise<void> {
|
|
|
|
await ctx.reply('Send me any text');
|
|
|
|
}
|
|
|
|
|
2020-12-29 22:41:06 +03:00
|
|
|
@Command('scene')
|
|
|
|
async onSceneCommand(ctx: Context): Promise<void> {
|
|
|
|
await ctx.scene.enter(HELLO_SCENE_ID);
|
|
|
|
}
|
|
|
|
|
2020-12-26 16:23:54 +03:00
|
|
|
@On('message')
|
2020-12-26 16:48:04 +03:00
|
|
|
async onMessage(ctx: Context): Promise<void> {
|
2020-12-26 16:23:54 +03:00
|
|
|
console.log('New message received');
|
2020-12-26 16:48:04 +03:00
|
|
|
|
|
|
|
if ('text' in ctx.message) {
|
|
|
|
const messageText = ctx.message.text;
|
|
|
|
const echoText = this.echoService.echo(messageText);
|
|
|
|
await ctx.reply(echoText);
|
|
|
|
} else {
|
|
|
|
await ctx.reply('Only text messages');
|
|
|
|
}
|
2020-12-26 16:23:54 +03:00
|
|
|
}
|
|
|
|
}
|