Add queue timeout voicemail and Amazon SNS SMS provider support

This update adds two major features:

1. Queue Timeout Voicemail
   - Callers can now leave voicemail when queue timeout is reached
   - Configurable per-queue voicemail prompts with TTS support
   - Automatic transcription and urgent keyword detection
   - Admin setting to choose between voicemail or callback on timeout

2. Amazon SNS SMS Provider
   - Alternative SMS provider to Twilio for sending text messages
   - Useful when Twilio SMS approval is difficult to obtain
   - Provider abstraction layer allows switching between Twilio/SNS
   - Full AWS SNS configuration in admin settings
   - Supports custom sender IDs in compatible countries
   - Lower cost per SMS compared to Twilio

New Files:
- includes/class-twp-voicemail-handler.php - Voicemail recording handler
- includes/interface-twp-sms-provider.php - SMS provider interface
- includes/class-twp-sms-provider-twilio.php - Twilio SMS implementation
- includes/class-twp-sms-provider-sns.php - Amazon SNS implementation
- includes/class-twp-sms-manager.php - SMS provider abstraction manager
- QUEUE_VOICEMAIL_SMS_FEATURES.md - Complete feature documentation

Modified Files:
- includes/class-twp-call-queue.php - Added voicemail option to timeout handler
- includes/class-twp-twilio-api.php - Updated send_sms() to use provider abstraction
- admin/class-twp-admin.php - Added SMS provider and timeout action settings
- composer.json - Added AWS SDK dependency

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-21 11:13:54 -07:00
parent 82b735f5df
commit 4baa8f539a
10 changed files with 1189 additions and 53 deletions

View File

@@ -0,0 +1,150 @@
<?php
/**
* SMS Manager
*
* Manages SMS provider selection and message sending
*/
class TWP_SMS_Manager {
private static $provider = null;
/**
* Get the active SMS provider instance
*
* @return TWP_SMS_Provider|null
*/
public static function get_provider() {
if (self::$provider !== null) {
return self::$provider;
}
// Load interface and providers
require_once dirname(__FILE__) . '/interface-twp-sms-provider.php';
require_once dirname(__FILE__) . '/class-twp-sms-provider-twilio.php';
require_once dirname(__FILE__) . '/class-twp-sms-provider-sns.php';
// Get selected provider from settings
$selected_provider = get_option('twp_sms_provider', 'twilio');
switch ($selected_provider) {
case 'aws_sns':
self::$provider = new TWP_SMS_Provider_SNS();
break;
case 'twilio':
default:
self::$provider = new TWP_SMS_Provider_Twilio();
break;
}
return self::$provider;
}
/**
* Send an SMS message using the configured provider
*
* @param string $to_number Recipient phone number (E.164 format)
* @param string $message Message body
* @param string $from_number Sender phone number (E.164 format)
* @return array Response array with 'success' and 'data' or 'error'
*/
public static function send_sms($to_number, $message, $from_number = null) {
$provider = self::get_provider();
if (!$provider) {
return [
'success' => false,
'error' => 'No SMS provider configured'
];
}
// Validate provider configuration before sending
$validation = $provider->validate_configuration();
if (!$validation['success']) {
error_log('TWP SMS Error: Provider validation failed - ' . $validation['error']);
return $validation;
}
// Send SMS
$result = $provider->send_sms($to_number, $message, $from_number);
// Log the result
if ($result['success']) {
error_log(sprintf(
'TWP SMS: Message sent via %s to %s',
$provider->get_provider_name(),
$to_number
));
} else {
error_log(sprintf(
'TWP SMS Error: Failed to send via %s to %s - %s',
$provider->get_provider_name(),
$to_number,
$result['error'] ?? 'Unknown error'
));
}
return $result;
}
/**
* Get list of available SMS providers
*
* @return array Array of provider IDs and names
*/
public static function get_available_providers() {
return [
'twilio' => 'Twilio',
'aws_sns' => 'Amazon SNS'
];
}
/**
* Validate current provider configuration
*
* @return array Response array with 'success' and 'message' or 'error'
*/
public static function validate_current_provider() {
$provider = self::get_provider();
if (!$provider) {
return [
'success' => false,
'error' => 'No SMS provider configured'
];
}
return $provider->validate_configuration();
}
/**
* Get current provider name
*
* @return string Provider name
*/
public static function get_current_provider_name() {
$provider = self::get_provider();
if (!$provider) {
return 'None';
}
return $provider->get_provider_name();
}
/**
* Test SMS send
*
* @param string $to_number Test recipient number
* @return array Response array
*/
public static function send_test_sms($to_number) {
$message = sprintf(
'This is a test message from Twilio WordPress Plugin using %s provider at %s',
self::get_current_provider_name(),
current_time('Y-m-d H:i:s')
);
return self::send_sms($to_number, $message);
}
}