import { Body, Controller, Post } from '@nestjs/common';
import { SendMessageParams, TelegramBotService } from './telegram-bot.service';
import {
  BadRequestErrorHandler,
  getOrAppErrorOrThrow,
} from '@app/event-emitter/utils/result';

@Controller('/api/telegram-bot')
export class TelegramBotController {
  constructor(private telegramBotService: TelegramBotService) {}

  @Post('send-message')
  async sendMessage(@Body() params: SendMessageParams): Promise<void> {
    await getOrAppErrorOrThrow(async () => {
      await this.telegramBotService.sendMessageByParams(params);
    }, BadRequestErrorHandler);
  }
}
