File size: 672 Bytes
fb13f0c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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<string, unknown>
) {
if (!this.telegramService.isValidWebhookSecret(secretToken)) {
throw new ForbiddenException('Invalid Telegram webhook secret token');
}
this.telegramService.processWebhookUpdate(update);
return { ok: true };
}
}
|