Given:

Made a helloworld bot. I can send him a message, he pulls the telegram, the telegram pulls the php script, which sends the message back to the user (also by pulling the telegram).

Task:

I want to see (conveniently and realtime) those json who sends me telegrams and which I send him back.

Possible Solution:

At the moment, I am either writing the necessary data from a php script to a file and uploading it manually from the server to the IDE (or just a file on the PC) after each request. It works, but hell is not convenient.

Question:

How do I best arrange debugging? I'm used to concluding Java in the console sout th)

  • one
    tail -f /path/to/log.log - etki
  • @Etki, and how and where to drive it in? .. - Yuriy SPb
  • on the server where the code is executed. will output you a log file as it is updated - etki
  • @Etki, if I have a paid host, this can also be done? .. I mean, I don’t have, as far as I know, full access to everything. Site host, database, PHP, like everything ... - YuriySPb
  • This is a question to the hoster. But I suspect that a hoster is more expensive than vps on the same vscale - etki

2 answers 2

For my needs I made the following debugger:

https://github.com/ReinRaus/telegramDebugger

Its "trick" is that the bot is being developed on a local machine, and to debug it you need to write to the bot in the Telegram application itself, while the answers come back to the application and you can see all the errors and warnings that occurred during the formation of the response message.

Connect to bot

In the web-hook, before the bot starts working, you need to connect a debugger:

 include_once( "/inc/telegramDebugger/debug.inc" ); 

In the index.html file, you must specify the path to the web hook on localhost:

 var localDebugger = "http://localhost/bot/hook.php"; 

Using

Open browser address:

 http://domain.com/webhook.php?debug=manage 

Start debugging for the required IDs to find out your ID- after opening the address, write something to the bot, then the ID of the chat from which the message was written will be indicated in the "Active chats".
After launch, all messages to the bot from the specified IDs will be redirected to localhost via a tab in the browser.

As a result, everything turned out to be simple - we call the php script in the browser, check for it that in the variable where json added from the telegram is empty, we substitute our values ​​(or get them) and see everything in the browser itself, in t. h mistakes.

 $json = file_get_contents('php://input'); $action = json_decode($json, true); if ($action != null) { $message = $action['message']['text']; $chat = $action['message']['chat']['id']; $user = $action['message']['from']['id']; $user_name = $action['message']['from']['username']; $first_name = $action['message']['from']['first_name']; } else { $message = 'test'; $chat = тут мой ИД; $user = тут мой ИД; $user_name = 'test'; $first_name = 'testName'; if($_GET['msg']!=null) { $message = $_GET['msg']; } } $error = 'sdfsdf 

Accordingly, now I can call my script like this:

 http://damain.ru/script.php?msg=fail 

And see what fell here: $error = 'sdfsdf