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:
2025-08-13 20:30:58 -07:00
parent f84914281d
commit 8c78e0cb11
2 changed files with 119 additions and 4 deletions

View File

@@ -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;
}