php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

Debugging with webhook #204

Closed Sogl closed 8 years ago

Sogl commented 8 years ago

Hello!

How to debug commands using webhook? Logging enabled:

Longman\TelegramBot\Logger::initialize(getcwd() . '/TelegramException.log');
$telegram->setLogRequests(true);
$telegram->setLogPath(getcwd() . '/mybot.log');
$telegram->setLogVerbosity(3);

But I want to see php variables in output. How can I add vars to *.log?

MBoretto commented 8 years ago

Log are not inteded to store variable so far. I suggest you to exploit getUpdates.php to develop where you can print vars. When everything works move to webhook.

monster3d commented 8 years ago

I debug custom POST request to webhook through the Postman (Google APP), send JSON with a settings and applay with php xdebug.

noplanman commented 8 years ago

You can also just use the static Logger::logException method for now. (When Monolog is merged into develop, then you can use that)

Logger::initialize('filename.log');
Logger::logException($whats_in_me);
Sogl commented 8 years ago

@Monster3D Can you add some Postman JSON examples? I'm already have configured xdebug with my ide_key.

monster3d commented 8 years ago

@Sogl i used this JSON


{
    "update_id":160070181,
    "message":{
        "message_id":181,
        "from":{
            "id":91535236,
            "first_name":"\u041d\u0438\u043a\u043e\u043b\u0430\u0439",
            "last_name":"\u0411\u0430\u0435\u0432",
            "username":"NikolayBaev"},"chat":{
                "id":00000000000,
                "first_name":"\u041d\u0438\u043a\u043e\u043b\u0430\u0439",
                "last_name":"\u0411\u0430\u0435\u0432",
                "username":"NikolayBaev",
                "type":"private"

            },
        "date":1459232407,
        "text":"\/help"

     }
}

where 000000000, my chat ID. send this request to local server. (use http POST request) my link: telegram.loc/telegrambot/hook?XDEBUG_SESSION_START=PHPSTORM