Files
twilio-wp-plugin/twilio-wp-plugin.php
jknapp 7cd7f036ff Fix extension transfer system and browser phone compatibility
Major Fixes:
- Fixed extension transfers going directly to voicemail for available agents
- Resolved browser phone call disconnections during transfers
- Fixed voicemail transcription placeholder text issue
- Added Firefox compatibility with automatic media permissions

Extension Transfer Improvements:
- Changed from active client dialing to proper queue-based system
- Fixed client name generation consistency (user_login vs display_name)
- Added 2-minute timeout with automatic voicemail fallback
- Enhanced agent availability detection for browser phone users

Browser Phone Enhancements:
- Added automatic microphone/speaker permission requests
- Improved Firefox compatibility with explicit getUserMedia calls
- Fixed client naming consistency across capability tokens and call acceptance
- Added comprehensive error handling for permission denials

Database & System Updates:
- Added auto_busy_at column for automatic agent status reversion
- Implemented 1-minute auto-revert system for busy agents with cron job
- Updated database version to 1.6.2 for automatic migration
- Fixed voicemail user_id association for extension voicemails

Call Statistics & Logging:
- Fixed browser phone calls not appearing in agent statistics
- Enhanced call logging with proper agent_id association in JSON format
- Improved customer number detection for complex call topologies
- Added comprehensive debugging for call leg detection

Voicemail & Transcription:
- Replaced placeholder transcription with real Twilio API integration
- Added manual transcription request capability for existing voicemails
- Enhanced voicemail callback handling with user_id support
- Fixed transcription webhook processing for extension voicemails

Technical Improvements:
- Standardized client name generation across all components
- Added ElevenLabs TTS integration to agent connection messages
- Enhanced error handling and logging throughout transfer system
- Fixed TwiML generation syntax errors in dial() methods

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-02 11:03:33 -07:00

142 lines
4.0 KiB
PHP

<?php
/**
* Plugin Name: Twilio WP Plugin
* Plugin URI: https://repo.anhonesthost.net/wp-plugins/twilio-wp-plugin
* Description: WordPress plugin for Twilio integration with phone scheduling, call forwarding, queue management, and Eleven Labs TTS
* Version: 2.2.0
* Author: Josh Knapp
* License: GPL v2 or later
* Text Domain: twilio-wp-plugin
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
// Plugin constants
define('TWP_VERSION', '2.4.2');
define('TWP_DB_VERSION', '1.6.2'); // Track database version separately
define('TWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('TWP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('TWP_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Plugin activation hook
*/
function twp_activate() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-activator.php';
TWP_Activator::activate();
}
/**
* Check if Twilio SDK is installed and show admin notice if not
*/
function twp_check_sdk_installation() {
$autoloader_path = TWP_PLUGIN_DIR . 'vendor/autoload.php';
$sdk_installed = false;
if (file_exists($autoloader_path)) {
// Try to load autoloader and check for classes
require_once $autoloader_path;
$sdk_installed = class_exists('Twilio\Rest\Client');
}
if (!$sdk_installed) {
add_action('admin_notices', 'twp_sdk_missing_notice');
}
}
/**
* Display admin notice for missing SDK
*/
function twp_sdk_missing_notice() {
?>
<div class="notice notice-error is-dismissible">
<h3>Twilio WordPress Plugin - SDK Required</h3>
<p><strong>The Twilio PHP SDK is required for this plugin to work.</strong></p>
<p>To install the SDK, run this command in your plugin directory:</p>
<code>chmod +x install-twilio-sdk.sh && ./install-twilio-sdk.sh</code>
<p>Or install via Composer: <code>composer install</code></p>
<p><em>Plugin path: <?php echo TWP_PLUGIN_DIR; ?></em></p>
</div>
<?php
}
// Check SDK installation and database updates on admin pages
if (is_admin()) {
add_action('admin_init', 'twp_check_sdk_installation');
add_action('admin_init', 'twp_check_database_updates');
add_action('admin_init', 'twp_setup_auto_revert_cron');
}
// Hook up cron functions
add_filter('cron_schedules', 'twp_add_cron_interval');
add_action('twp_auto_revert_agents', 'twp_handle_auto_revert_agents');
/**
* Check and perform database updates if needed
*/
function twp_check_database_updates() {
$current_db_version = get_option('twp_db_version', '1.0.0');
if (version_compare($current_db_version, TWP_DB_VERSION, '<')) {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-activator.php';
TWP_Activator::ensure_tables_exist();
update_option('twp_db_version', TWP_DB_VERSION);
}
}
/**
* Setup auto-revert cron job for agent status
*/
function twp_setup_auto_revert_cron() {
if (!wp_next_scheduled('twp_auto_revert_agents')) {
wp_schedule_event(time(), 'twp_every_minute', 'twp_auto_revert_agents');
}
}
/**
* Handle auto-revert cron job
*/
function twp_handle_auto_revert_agents() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-agent-manager.php';
TWP_Agent_Manager::revert_auto_busy_agents();
}
/**
* Add custom cron schedule
*/
function twp_add_cron_interval($schedules) {
$schedules['twp_every_minute'] = array(
'interval' => 60, // Every 60 seconds
'display' => esc_html__('Every Minute (TWP)', 'twilio-wp-plugin')
);
return $schedules;
}
/**
* Plugin deactivation hook
*/
function twp_deactivate() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-deactivator.php';
TWP_Deactivator::deactivate();
}
register_activation_hook(__FILE__, 'twp_activate');
register_deactivation_hook(__FILE__, 'twp_deactivate');
/**
* Core plugin class
*/
require plugin_dir_path(__FILE__) . 'includes/class-twp-core.php';
/**
* Begin execution of the plugin
*/
function run_twilio_wp_plugin() {
$plugin = new TWP_Core();
$plugin->run();
}
run_twilio_wp_plugin();