import { Body, Controller, ForbiddenException, Headers, Post } from '@nestjs/common'; import { TelegramService } from './telegram.service'; @Controller('telegram') export class TelegramController { constructor(private readonly telegramService: TelegramService) {} @Post('webhook') handleWebhook( @Headers('x-telegram-bot-api-secret-token') secretToken: string | undefined, @Body() update: Record ) { if (!this.telegramService.isValidWebhookSecret(secretToken)) { throw new ForbiddenException('Invalid Telegram webhook secret token'); } this.telegramService.processWebhookUpdate(update); return { ok: true }; } }