HEX
Server: Apache
System: Linux server3230.server-vps.com 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64
User: lzgqnjwu (1002)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //proc/1124/cwd/frontend/controllers/NewBotController.php
<?php

namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\services\TelegramService;

class BotController extends Controller
{
    public $enableCsrfValidation = false; // для вебхуков CSRF не нужен

    protected TelegramService $telegramService;

    public function __construct($id, $module, $config = [])
    {
        parent::__construct($id, $module, $config);
        $this->telegramService = new TelegramService();
    }

    /**
     * Вебхук для Telegram
     * @param int|null $id ID бота
     */
    public function actionIndex($id = null)
    {
        if (!$id) {
            return 'ok'; // защита от случайного захода
        }

        try {
            // Принимаем и обрабатываем сообщение
            $this->telegramService->handleUpdate($id);
        } catch (\Throwable $e) {
            // Логируем ошибку
            file_put_contents(Yii::getAlias('@web_path') . '/tg_log.txt', date('Y-m-d H:i:s') . " - " ."Telegram webhook error: " . $e->getMessage() . "\n" . $e->getTraceAsString(), FILE_APPEND);
        }

        return 'ok';
    }
}