Fix urgent voicemail SMS from number and add Discord/Slack notifications
- Fix SMS notifications to use Default SMS From Number instead of destination - Add Discord webhook notifications for urgent keyword voicemails - Add Slack webhook notifications for urgent keyword voicemails - Make notification methods public to allow external calls - Add urgent_voicemail type support with custom formatting - Include transcription, keyword, and admin link in notifications - Use bright red color for urgent alerts in both Discord and Slack 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
		@@ -83,7 +83,7 @@ class TWP_Notifications {
 | 
			
		||||
    /**
 | 
			
		||||
     * Send notification to Discord
 | 
			
		||||
     */
 | 
			
		||||
    private static function send_discord_notification($webhook_url, $message, $data) {
 | 
			
		||||
    public static function send_discord_notification($webhook_url, $data, $message = null) {
 | 
			
		||||
        $payload = array(
 | 
			
		||||
            'content' => $message,
 | 
			
		||||
            'embeds' => array(
 | 
			
		||||
@@ -105,7 +105,7 @@ class TWP_Notifications {
 | 
			
		||||
    /**
 | 
			
		||||
     * Send notification to Slack
 | 
			
		||||
     */
 | 
			
		||||
    private static function send_slack_notification($webhook_url, $message, $data) {
 | 
			
		||||
    public static function send_slack_notification($webhook_url, $data, $message = null) {
 | 
			
		||||
        $payload = array(
 | 
			
		||||
            'text' => self::get_notification_title($data),
 | 
			
		||||
            'attachments' => array(
 | 
			
		||||
@@ -134,6 +134,8 @@ class TWP_Notifications {
 | 
			
		||||
                return '⏰ Queue Timeout Alert';
 | 
			
		||||
            case 'missed_call':
 | 
			
		||||
                return '❌ Missed Call';
 | 
			
		||||
            case 'urgent_voicemail':
 | 
			
		||||
                return '🚨 URGENT Voicemail Alert';
 | 
			
		||||
            default:
 | 
			
		||||
                return '📋 Call Event';
 | 
			
		||||
        }
 | 
			
		||||
@@ -152,6 +154,8 @@ class TWP_Notifications {
 | 
			
		||||
                return 16776960; // Yellow
 | 
			
		||||
            case 'missed_call':
 | 
			
		||||
                return 15158332; // Red
 | 
			
		||||
            case 'urgent_voicemail':
 | 
			
		||||
                return 16711680; // Bright Red
 | 
			
		||||
            default:
 | 
			
		||||
                return 9807270; // Gray
 | 
			
		||||
        }
 | 
			
		||||
@@ -170,6 +174,8 @@ class TWP_Notifications {
 | 
			
		||||
                return '#ffcc00'; // Yellow
 | 
			
		||||
            case 'missed_call':
 | 
			
		||||
                return '#ff0000'; // Red
 | 
			
		||||
            case 'urgent_voicemail':
 | 
			
		||||
                return '#ff0000'; // Bright Red
 | 
			
		||||
            default:
 | 
			
		||||
                return '#666666'; // Gray
 | 
			
		||||
        }
 | 
			
		||||
@@ -213,6 +219,46 @@ class TWP_Notifications {
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Urgent voicemail specific fields
 | 
			
		||||
        if (isset($data['type']) && $data['type'] === 'urgent_voicemail') {
 | 
			
		||||
            if (isset($data['from_number'])) {
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'name' => '📞 From',
 | 
			
		||||
                    'value' => $data['from_number'],
 | 
			
		||||
                    'inline' => true
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (isset($data['keyword'])) {
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'name' => '🔴 Keyword Detected',
 | 
			
		||||
                    'value' => strtoupper($data['keyword']),
 | 
			
		||||
                    'inline' => true
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (isset($data['transcription'])) {
 | 
			
		||||
                // Truncate transcription if too long
 | 
			
		||||
                $transcription = $data['transcription'];
 | 
			
		||||
                if (strlen($transcription) > 500) {
 | 
			
		||||
                    $transcription = substr($transcription, 0, 497) . '...';
 | 
			
		||||
                }
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'name' => '📝 Transcription',
 | 
			
		||||
                    'value' => $transcription,
 | 
			
		||||
                    'inline' => false
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (isset($data['admin_url'])) {
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'name' => '🔗 Action',
 | 
			
		||||
                    'value' => '[Listen to Voicemail](' . $data['admin_url'] . ')',
 | 
			
		||||
                    'inline' => false
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $fields;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -254,6 +300,46 @@ class TWP_Notifications {
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Urgent voicemail specific fields
 | 
			
		||||
        if (isset($data['type']) && $data['type'] === 'urgent_voicemail') {
 | 
			
		||||
            if (isset($data['from_number'])) {
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'title' => 'From',
 | 
			
		||||
                    'value' => $data['from_number'],
 | 
			
		||||
                    'short' => true
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (isset($data['keyword'])) {
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'title' => '🔴 Keyword Detected',
 | 
			
		||||
                    'value' => strtoupper($data['keyword']),
 | 
			
		||||
                    'short' => true
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (isset($data['transcription'])) {
 | 
			
		||||
                // Truncate transcription if too long
 | 
			
		||||
                $transcription = $data['transcription'];
 | 
			
		||||
                if (strlen($transcription) > 500) {
 | 
			
		||||
                    $transcription = substr($transcription, 0, 497) . '...';
 | 
			
		||||
                }
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'title' => 'Transcription',
 | 
			
		||||
                    'value' => $transcription,
 | 
			
		||||
                    'short' => false
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (isset($data['admin_url'])) {
 | 
			
		||||
                $fields[] = array(
 | 
			
		||||
                    'title' => 'Action',
 | 
			
		||||
                    'value' => '<' . $data['admin_url'] . '|Listen to Voicemail>',
 | 
			
		||||
                    'short' => false
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $fields;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1383,10 +1383,39 @@ class TWP_Webhooks {
 | 
			
		||||
        
 | 
			
		||||
        // Also send urgent SMS notification
 | 
			
		||||
        $notification_number = get_option('twp_sms_notification_number');
 | 
			
		||||
        if ($notification_number) {
 | 
			
		||||
        $default_sms_from = get_option('twp_default_sms_number');
 | 
			
		||||
        
 | 
			
		||||
        if ($notification_number && $default_sms_from) {
 | 
			
		||||
            $twilio = new TWP_Twilio_API();
 | 
			
		||||
            $sms_message = "URGENT voicemail from {$from_number}. Keyword: {$keyword}. Check admin panel immediately.";
 | 
			
		||||
            $twilio->send_sms($notification_number, $sms_message);
 | 
			
		||||
            // Explicitly pass the Default SMS From Number as the third parameter
 | 
			
		||||
            $twilio->send_sms($notification_number, $sms_message, $default_sms_from);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Send Discord notification if configured
 | 
			
		||||
        $discord_webhook = get_option('twp_discord_webhook_url');
 | 
			
		||||
        if ($discord_webhook) {
 | 
			
		||||
            TWP_Notifications::send_discord_notification($discord_webhook, array(
 | 
			
		||||
                'type' => 'urgent_voicemail',
 | 
			
		||||
                'from_number' => $from_number,
 | 
			
		||||
                'keyword' => $keyword,
 | 
			
		||||
                'transcription' => $transcription_text,
 | 
			
		||||
                'voicemail_id' => $voicemail_id,
 | 
			
		||||
                'admin_url' => admin_url('admin.php?page=twilio-wp-voicemails')
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Send Slack notification if configured
 | 
			
		||||
        $slack_webhook = get_option('twp_slack_webhook_url');
 | 
			
		||||
        if ($slack_webhook) {
 | 
			
		||||
            TWP_Notifications::send_slack_notification($slack_webhook, array(
 | 
			
		||||
                'type' => 'urgent_voicemail',
 | 
			
		||||
                'from_number' => $from_number,
 | 
			
		||||
                'keyword' => $keyword,
 | 
			
		||||
                'transcription' => $transcription_text,
 | 
			
		||||
                'voicemail_id' => $voicemail_id,
 | 
			
		||||
                'admin_url' => admin_url('admin.php?page=twilio-wp-voicemails')
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user