From 7beb0aa4f3129fcba003ff816002dfdd5032f3ff Mon Sep 17 00:00:00 2001 From: jknapp Date: Wed, 13 Aug 2025 10:04:20 -0700 Subject: [PATCH] Fix voicemail and queue announcement issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed phone agents getting 'Unauthorized' error when accessing voicemails by checking for twp_access_voicemails capability - Fixed missing ElevenLabs parameter in queue TwiML generation that prevented announcement messages - Fixed IVR voicemail messages not being saved correctly - now properly assigns message field based on action type - Added proper permission checks for both ajax_get_voicemail and ajax_get_voicemail_audio functions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- admin/class-twp-admin.php | 7 ++++++- assets/js/admin.js | 24 +++++++++++++++++++++--- includes/class-twp-workflow.php | 3 ++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/admin/class-twp-admin.php b/admin/class-twp-admin.php index 4ca4d7d..69ec601 100644 --- a/admin/class-twp-admin.php +++ b/admin/class-twp-admin.php @@ -3432,6 +3432,11 @@ class TWP_Admin { public function ajax_get_voicemail() { check_ajax_referer('twp_ajax_nonce', 'nonce'); + if (!current_user_can('manage_options') && !current_user_can('twp_access_voicemails')) { + wp_send_json_error('Unauthorized'); + return; + } + $voicemail_id = intval($_POST['voicemail_id']); if (!$voicemail_id) { @@ -3487,7 +3492,7 @@ class TWP_Admin { public function ajax_get_voicemail_audio() { check_ajax_referer('twp_ajax_nonce', 'nonce'); - if (!current_user_can('manage_options')) { + if (!current_user_can('manage_options') && !current_user_can('twp_access_voicemails')) { wp_send_json_error('Unauthorized'); return; } diff --git a/assets/js/admin.js b/assets/js/admin.js index 2416380..94ae152 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -877,14 +877,32 @@ jQuery(document).ready(function($) { // console.log('Processing IVR options - raw data:', data); data.options = {}; for (var i = 0; i < data.digit.length; i++) { + // Get the appropriate target value based on action type + var targetValue = data.target[i]; var option = { action: data.action[i], description: data.description[i], - number: data.target[i], - queue_name: data.target[i], - message: data.target[i] + number: '', + queue_name: '', + message: '' }; + // Set the appropriate field based on action type + switch(data.action[i]) { + case 'forward': + option.number = targetValue; + break; + case 'queue': + option.queue_name = targetValue; + break; + case 'voicemail': + option.message = targetValue; + break; + case 'message': + option.message = targetValue; + break; + } + // console.log('Processing option', i, '- action:', data.action[i], 'target:', data.target[i]); // For queue action, get the actual queue name from the select option text diff --git a/includes/class-twp-workflow.php b/includes/class-twp-workflow.php index 673e4bf..9bdca6d 100644 --- a/includes/class-twp-workflow.php +++ b/includes/class-twp-workflow.php @@ -975,7 +975,8 @@ class TWP_Workflow { return self::create_voicemail_twiml($action, $elevenlabs); case 'queue': - return self::create_queue_twiml($action); + $elevenlabs = new TWP_ElevenLabs_API(); + return self::create_queue_twiml($action, $elevenlabs); case 'ring_group': return self::create_ring_group_twiml($action);