Improve debugging function

This commit is contained in:
Matteo Gheza 2022-03-15 15:03:08 +01:00
parent d1f15f6fa1
commit 37593eca9e
1 changed files with 16 additions and 2 deletions

View File

@ -183,6 +183,19 @@ function yesOrNo($value)
return ($value === 1 || $value) ? '<b>SI</b>' : '<b>NO</b>';
}
function sendLongMessage($text, $userId) {
global $Bot;
if(strlen($text) > 4096) {
$message_json = wordwrap($text, 4096, "<@MESSAGE_SEPARATOR@>", true);
$message_json = explode("<@MESSAGE_SEPARATOR@>", $message_json);
foreach($message_json as $segment) {
sendLongMessage($segment, $userId);
}
} else {
$Bot->sendMessage($userId, $text);
}
}
function telegramBotRouter() {
global $Bot;
@ -266,10 +279,11 @@ function telegramBotRouter() {
}
$message->reply($messageText);
if(defined("BOT_TELEGRAM_DEBUG_USER")){
if(defined("BOT_TELEGRAM_DEBUG_USER") && BOT_TELEGRAM_DEBUG_USER !== $message->from->id){
$messageText .= "\n\n🔎 JSON del messaggio:";
$Bot->sendMessage(BOT_TELEGRAM_DEBUG_USER, $messageText);
$Bot->sendMessage(json_encode($message, JSON_PRETTY_PRINT));
$message_json = json_encode($message, JSON_PRETTY_PRINT);
sendLongMessage($message_json, BOT_TELEGRAM_DEBUG_USER);
}
});