Add background notifications and fix Discord/Slack notification bugs

Background Notification Features:
- Implement Web Push Notifications for alerts when browser is minimized
- Add Service Worker for persistent background notification support
- Integrate Page Visibility API to detect when page is in background
- Add browser notification permission request with user consent flow
- Create more aggressive background polling (10 seconds) when page hidden
- Add vibration patterns for mobile device alerts

Bug Fixes:
- Fix Discord/Slack notification parameter order bug preventing delivery
- Add comprehensive logging for notification debugging
- Correct webhook function signatures for proper data passing

Mobile Enhancements:
- Support system notifications on Android browsers
- Add click-to-focus functionality for notifications
- Implement background alert system for multitasking
- Add notification button with visual feedback

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-15 16:51:47 -07:00
parent 9832f899c3
commit d050f1538b
5 changed files with 352 additions and 3 deletions

View File

@@ -9,23 +9,34 @@ class TWP_Notifications {
* Send notification to Discord and/or Slack
*/
public static function send_call_notification($type, $data) {
// Log notification attempt
error_log("TWP: Attempting to send {$type} notification with data: " . json_encode($data));
// Check if notifications are enabled for this type
if (!self::is_notification_enabled($type)) {
error_log("TWP: {$type} notifications are disabled");
return;
}
$message = self::format_message($type, $data);
error_log("TWP: Formatted message: " . $message);
// Send to Discord if configured
$discord_url = get_option('twp_discord_webhook_url');
if (!empty($discord_url)) {
self::send_discord_notification($discord_url, $message, $data);
error_log("TWP: Sending Discord notification to: " . substr($discord_url, 0, 50) . "...");
self::send_discord_notification($discord_url, $data, $message);
} else {
error_log("TWP: Discord webhook URL not configured");
}
// Send to Slack if configured
$slack_url = get_option('twp_slack_webhook_url');
if (!empty($slack_url)) {
self::send_slack_notification($slack_url, $message, $data);
error_log("TWP: Sending Slack notification to: " . substr($slack_url, 0, 50) . "...");
self::send_slack_notification($slack_url, $data, $message);
} else {
error_log("TWP: Slack webhook URL not configured");
}
}