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

@@ -562,6 +562,8 @@ class TWP_Call_Queue {
private static function notify_agents_for_queue($queue_id, $caller_number) {
global $wpdb;
error_log("TWP: notify_agents_for_queue called for queue {$queue_id}, caller {$caller_number}");
// Get queue information including assigned agent group and phone number
$queue_table = $wpdb->prefix . 'twp_call_queues';
$queue = $wpdb->get_row($wpdb->prepare(
@@ -569,13 +571,21 @@ class TWP_Call_Queue {
$queue_id
));
if (!$queue || !$queue->agent_group_id) {
if (!$queue) {
error_log("TWP: Queue {$queue_id} not found in database");
return;
}
if (!$queue->agent_group_id) {
error_log("TWP: No agent group assigned to queue {$queue_id}, skipping SMS notifications");
return;
}
error_log("TWP: Found queue '{$queue->queue_name}' with agent group {$queue->agent_group_id}");
// Send Discord/Slack notification for incoming call
require_once dirname(__FILE__) . '/class-twp-notifications.php';
error_log("TWP: Triggering Discord/Slack notification for incoming call");
TWP_Notifications::send_call_notification('incoming_call', array(
'type' => 'incoming_call',
'caller' => $caller_number,