Files
twilio-wp-plugin/twilio-wp-plugin.php

253 lines
9.9 KiB
PHP
Raw Permalink Normal View History

2025-08-06 15:25:47 -07:00
<?php
/**
* Plugin Name: Twilio WP Plugin
* Plugin URI: https://repo.anhonesthost.net/wp-plugins/twilio-wp-plugin
2025-08-06 15:25:47 -07:00
* Description: WordPress plugin for Twilio integration with phone scheduling, call forwarding, queue management, and Eleven Labs TTS
* Version: {auto_update_value_on_deploy}
* Requires PHP: 8.1
* Author: Josh Knapp
2025-08-06 15:25:47 -07:00
* 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', '{auto_update_value_on_deploy}');
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
define('TWP_DB_VERSION', '1.6.2'); // Track database version separately
2025-08-06 15:25:47 -07:00
define('TWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('TWP_PLUGIN_URL', plugin_dir_url(__FILE__));
define('TWP_PLUGIN_BASENAME', plugin_basename(__FILE__));
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// External SDK location - legacy/manual install path (wp-content/twilio-sdk/)
// Bundled vendor/ inside the plugin (shipped via release zip) is now the primary source.
define('TWP_EXTERNAL_SDK_DIR', dirname(dirname(TWP_PLUGIN_DIR)) . '/twilio-sdk/');
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// External AWS SDK location - installed via install-aws-sdk-external.sh (wp-content/aws-sdk/)
define('TWP_EXTERNAL_AWS_SDK_DIR', dirname(dirname(TWP_PLUGIN_DIR)) . '/aws-sdk/');
2025-08-06 15:25:47 -07:00
/**
* Plugin activation hook
*/
function twp_activate() {
require_once TWP_PLUGIN_DIR . 'includes/class-twp-activator.php';
TWP_Activator::activate();
}
2025-08-07 15:24:29 -07:00
/**
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
* Check if Twilio (and optionally AWS) SDKs are available, load them, and
* register admin notices if anything required is missing.
*
* Priority for the Twilio autoloader:
* 1. Internal bundled `vendor/autoload.php` (shipped with release zip always current)
* 2. External legacy `wp-content/twilio-sdk/autoload.php` (manual install fallback)
*
* Composer's bundled autoloader handles BOTH `Twilio\…` and `Aws\…` via PSR-4. If
* the bundled vendor doesn't supply Aws (e.g. someone installed Twilio-only
* externally), we fall back to `wp-content/aws-sdk/autoload.php`.
2025-08-07 15:24:29 -07:00
*/
function twp_check_sdk_installation() {
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
$twilio_sdk_installed = false;
$aws_sdk_installed = false;
// --- Twilio SDK ---
// Priority 1: Internal bundled vendor (shipped via release zip)
$internal_autoloader = TWP_PLUGIN_DIR . 'vendor/autoload.php';
if (file_exists($internal_autoloader)) {
require_once $internal_autoloader;
$twilio_sdk_installed = class_exists('Twilio\Rest\Client');
}
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// Priority 2: External legacy location (manual installs)
if (!$twilio_sdk_installed) {
$external_autoloader = TWP_EXTERNAL_SDK_DIR . 'autoload.php';
if (file_exists($external_autoloader)) {
require_once $external_autoloader;
$twilio_sdk_installed = class_exists('Twilio\Rest\Client');
}
2025-08-07 15:24:29 -07:00
}
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// --- AWS SDK ---
// The bundled composer vendor may already provide it (if shipped with release).
$aws_sdk_installed = class_exists('Aws\Sns\SnsClient');
if (!$aws_sdk_installed) {
$aws_external_autoloader = TWP_EXTERNAL_AWS_SDK_DIR . 'autoload.php';
if (file_exists($aws_external_autoloader)) {
require_once $aws_external_autoloader;
$aws_sdk_installed = class_exists('Aws\Sns\SnsClient');
}
}
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// Twilio is the hard requirement — always notify if missing.
if (!$twilio_sdk_installed) {
2025-08-07 15:24:29 -07:00
add_action('admin_notices', 'twp_sdk_missing_notice');
}
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// AWS is only required when the SNS provider is selected.
if (!$aws_sdk_installed && get_option('twp_sms_provider') === 'aws_sns') {
add_action('admin_notices', 'twp_aws_sdk_missing_notice');
}
2025-08-07 15:24:29 -07:00
}
/**
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
* Display admin notice for missing Twilio SDK
2025-08-07 15:24:29 -07:00
*/
function twp_sdk_missing_notice() {
?>
<div class="notice notice-error is-dismissible">
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
<h3>Twilio WordPress Plugin - Twilio SDK Required</h3>
2025-08-07 15:24:29 -07:00
<p><strong>The Twilio PHP SDK is required for this plugin to work.</strong></p>
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
<p><strong>Recommended:</strong> Reinstall or update the plugin. Plugin updates now bundle the SDK (the release zip ships a pre-built <code>vendor/</code> directory), so a fresh install or update is the simplest fix.</p>
<p style="margin-top: 10px;"><strong>Legacy / manual install:</strong> If you can't update the plugin, you can install the SDK to the external location instead:</p>
<code>chmod +x install-twilio-sdk-external.sh && ./install-twilio-sdk-external.sh</code>
<p style="margin-top: 10px;"><em>Plugin path: <?php echo esc_html(TWP_PLUGIN_DIR); ?></em></p>
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
<p><em>Bundled vendor path: <?php echo esc_html(TWP_PLUGIN_DIR . 'vendor/'); ?></em></p>
<p><em>External SDK fallback path: <?php echo esc_html(TWP_EXTERNAL_SDK_DIR); ?></em></p>
</div>
<?php
}
/**
* Display admin notice for missing AWS SDK (only fired when SNS provider is selected)
*/
function twp_aws_sdk_missing_notice() {
?>
<div class="notice notice-error is-dismissible">
<h3>Twilio WordPress Plugin - AWS SDK Required for SNS SMS</h3>
<p><strong>You have selected AWS SNS as your SMS provider, but the AWS PHP SDK is not available.</strong></p>
<p><strong>Recommended:</strong> Update the plugin to a release-bundled version newer release zips bundle the AWS SDK alongside the Twilio SDK in <code>vendor/</code>.</p>
<p style="margin-top: 10px;"><strong>Legacy / manual install:</strong> Install the AWS SDK to the external location:</p>
<code>chmod +x install-aws-sdk-external.sh && ./install-aws-sdk-external.sh</code>
<p style="margin-top: 10px;"><em>External AWS SDK path: <?php echo esc_html(TWP_EXTERNAL_AWS_SDK_DIR); ?></em></p>
<p><em>If you don't need AWS SNS, switch the SMS provider back to Twilio under the plugin settings.</em></p>
2025-08-07 15:24:29 -07:00
</div>
<?php
}
2025-08-11 20:31:48 -07:00
// Check SDK installation and database updates on admin pages
2025-08-07 15:24:29 -07:00
if (is_admin()) {
add_action('admin_init', 'twp_check_sdk_installation');
2025-08-11 20:31:48 -07:00
add_action('admin_init', 'twp_check_database_updates');
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
add_action('admin_init', 'twp_setup_auto_revert_cron');
2025-08-11 20:31:48 -07:00
}
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
// Hook up cron functions
add_filter('cron_schedules', 'twp_add_cron_interval');
add_action('twp_auto_revert_agents', 'twp_handle_auto_revert_agents');
2025-08-11 20:31:48 -07:00
/**
* 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);
}
2025-08-07 15:24:29 -07:00
}
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
/**
* 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;
}
2025-08-06 15:25:47 -07:00
/**
* 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');
/**
* Check SDK status after plugin updates
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
* Shows warning if neither the bundled vendor/ nor the external SDK is available
* after an update this should be rare now that release zips ship vendor/.
*/
function twp_check_sdk_after_update($upgrader_object, $options) {
// Only run for plugin updates
if ($options['action'] !== 'update' || $options['type'] !== 'plugin') {
return;
}
// Check if this plugin was updated
$updated_plugins = isset($options['plugins']) ? $options['plugins'] : array();
if (!in_array(TWP_PLUGIN_BASENAME, $updated_plugins)) {
return;
}
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
// Check if a Twilio SDK autoloader is available anywhere
$internal_sdk = file_exists(TWP_PLUGIN_DIR . 'vendor/autoload.php');
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
$external_sdk = file_exists(TWP_EXTERNAL_SDK_DIR . 'autoload.php');
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
if (!$internal_sdk && !$external_sdk) {
// Set a transient to show warning on next admin page load
set_transient('twp_sdk_update_warning', true, 60 * 5);
}
}
add_action('upgrader_process_complete', 'twp_check_sdk_after_update', 10, 2);
/**
* Show SDK update warning
*/
function twp_show_sdk_update_warning() {
if (get_transient('twp_sdk_update_warning')) {
delete_transient('twp_sdk_update_warning');
?>
<div class="notice notice-warning is-dismissible">
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
<h3>Twilio WordPress Plugin - SDK Missing After Update</h3>
<p><strong>The plugin was updated, but no Twilio SDK could be found.</strong></p>
<p>Plugin release zips normally bundle the SDK in <code>vendor/</code>, so this usually means the release was built without dependencies, or the upload was incomplete. Try downloading the release zip again and reinstalling.</p>
<p style="margin-top: 10px;"><strong>Manual install fallback:</strong></p>
<code>cd <?php echo esc_html(TWP_PLUGIN_DIR); ?> && ./install-twilio-sdk-external.sh</code>
Bundle Twilio + AWS SDKs in releases, add SNS install path Gitea release workflow now runs composer install --no-dev before zipping, so each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader priority is flipped to match: internal vendor/autoload.php first (always current after every plugin update), external wp-content/twilio-sdk/ second (legacy/manual install fallback). AWS SDK detection wired in alongside Twilio: composer's bundled autoloader covers Aws\… natively when present; otherwise plugin falls back to a new external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users see no new noise. Loader priority flip applied in three places that all had the same external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation), class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php (constructor). twp_check_sdk_after_update messaging updated to reflect that plugin updates now bundle the SDK. Files: .gitea/workflows/release.yml — composer install before ZIP twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK detection, twp_aws_sdk_missing_notice includes/class-twp-twilio-api.php — internal-first autoloader includes/class-twp-webhooks.php — internal-first autoloader install-aws-sdk-external.sh — new AWS SDK PHAR installer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 08:48:45 -07:00
<p style="margin-top: 10px;"><em>Bundled vendor path: <?php echo esc_html(TWP_PLUGIN_DIR . 'vendor/'); ?></em></p>
<p><em>External SDK fallback path: <?php echo esc_html(TWP_EXTERNAL_SDK_DIR); ?></em></p>
</div>
<?php
}
}
add_action('admin_notices', 'twp_show_sdk_update_warning');
2025-08-06 15:25:47 -07:00
/**
* 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();