Skip to content

Fix UI freezes and unhandled network exceptions by setting default Guzzle timeouts and catching all Throwables #51

Description

@chapdan777

Currently, when a task is moved or created, the Telegram notification plugin sends a request to api.telegram.org synchronously within the main PHP thread.

If the server has no internet connection, or the Telegram API is blocked by the ISP (which is very common in certain regions), the HTTP request hangs. Furthermore, because Guzzle exceptions (like ConnectException) do not inherit from Longman\TelegramBot\Exception\TelegramException, they bubble up to Kanboard's global error handler, causing the browser UI to freeze on a loading indicator and pop up intrusive red cURL error banners (e.g. cURL error 28: Connection timed out).

This PR addresses two issues:

Timeouts: Configures a reasonable timeout (3.0s) and connect_timeout (2.0s) for Guzzle HTTP clients by default so that the request does not freeze the UI for up to 30 seconds when the API is unreachable.
Exception Handling: Changes the catch block in sendMessage from TelegramException to \Throwable to catch all Guzzle/network exceptions (like timeouts/DNS resolution errors) and log them to the error log, allowing Kanboard to fail silently and keeping the UI responsive.
Diff / Proposed Changes:
diff

diff --git a/Notification/Telegram.php b/Notification/Telegram.php
index abcdefg..hijklmn 100644
--- a/Notification/Telegram.php
+++ b/Notification/Telegram.php
@@ -196,16 +196,20 @@ class Telegram extends Base implements NotificationInterface
// Create Telegram API object
$telegram = new TelegramClass($apikey, $bot_username);

  •        // Setup proxy details if set in kanboard configuration
    
  •        // Setup Guzzle client with a short timeout to prevent UI blocking
    
  •        $client_config = [
    
  •            'base_uri' => 'https://api.telegram.org',
    
  •            'timeout' => 3.0,
    
  •            'connect_timeout' => 2.0,
    
  •            'verify' => false,
    
  •        ];
    
  •        if ($telegram_proxy != '')
           {
    
  •            Request::setClient(new \GuzzleHttp\Client([
    
  •                'base_uri' => 'https://api.telegram.org',
    
  •                'timeout' => 20,
    
  •                'verify' => false,
    
  •                'proxy'   => $telegram_proxy,
    
  •            ]));
    
  •        }
    
  •            $client_config['proxy'] = $telegram_proxy;
    
  •        }
    
  •        Request::setClient(new \GuzzleHttp\Client($client_config));
    
           // Message payload
           if ($is_topic)
    

@@ -253,9 +257,9 @@ class Telegram extends Base implements NotificationInterface
rmdir(sys_get_temp_dir() . "/kanboard_telegram_plugin");
}
}

  •    catch (TelegramException $e)
    
  •    catch (\Throwable $e)
       {
           // log telegram errors
    
  •        error_log($e->getMessage());
    
  •        error_log("Telegram notification failed: " . $e->getMessage());
       }
    
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions