<?php
namespace App\Controller;
use App\Form\ContactFormType;
use App\Service\TelegramService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
class ContactController extends AbstractController
{
/*
// ==============================
// ИНИЦИАЛИЗАЦИЯ TelegramService
// (СЕЙЧАС ОТКЛЮЧЕНА)
// ==============================
private $telegramService;
public function __construct()
{
$telegramToken = '6182021373:AAFhsm39Y-enN9vjT1pXIEeToCw1DbOnfqM';
$telegramChatId = '-721778259';
$this->telegramService = new TelegramService($telegramToken, $telegramChatId);
}
*/
/**
* @Route("/contact", name="contact", methods={"GET", "POST"})
*/
public function contact(Request $request): Response
{
/*
// ======================================
// ОБРАБОТКА POST И ОТПРАВКА В TELEGRAM
// (СЕЙЧАС ОТКЛЮЧЕНО)
// ======================================
if ($request->isMethod('POST')) {
// Обработка отправленных данных формы
$text = $request->request->get('text');
$phone = $request->request->get('phone');
// и так далее
// Отправка сообщения в Telegram
$message = 'Новое сообщение из формы обратной связи:';
$message .= "\nТекст: " . $text;
$message .= "\nНомер телефона: " . $phone;
// и так далее
$this->telegramService->sendMessage($message);
// Возвращаем JSON-ответ в случае AJAX-запроса
if ($request->isXmlHttpRequest()) {
$responseData = [
'success' => true,
'message' => 'Сообщение удачно отправлено',
];
return new JsonResponse($responseData);
}
// Возвращаем полную HTML-страницу в случае не-AJAX-запроса
return $this->redirectToRoute('contact'); // или другой редирект
}
*/
// Сейчас просто отображаем страницу без обработки формы
return $this->render('contact/contact.html.twig');
}
}