From 0ee8210fef2534c68f4f8b6d8a8accb6b94d835d Mon Sep 17 00:00:00 2001 From: jknapp Date: Thu, 18 Sep 2025 16:46:52 -0700 Subject: [PATCH] Fix caller ID for workflow forward and ring group tasks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated forward and ring group tasks to use the incoming number (To) as the caller ID for outbound calls instead of the original caller's number (From). Changes: - Forward task now sets callerId attribute to the number that was called - Ring group task also defaults to using the incoming number as caller ID - Both functions check multiple sources for the To number (GLOBALS, POST, REQUEST) - Added detailed logging for caller ID selection This ensures that when calls are forwarded, the receiving party sees the business number that was called, not the original caller's personal number. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- includes/class-twp-workflow.php | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/includes/class-twp-workflow.php b/includes/class-twp-workflow.php index a740bcb..b9c147e 100644 --- a/includes/class-twp-workflow.php +++ b/includes/class-twp-workflow.php @@ -570,6 +570,27 @@ class TWP_Workflow { $dial->addAttribute('timeout', $timeout); error_log('TWP Workflow Forward: Using timeout: ' . $timeout); + // Set caller ID to the number that was called (To number from call data) + // This makes the outbound call appear to come from the number the caller dialed + $caller_id = null; + if (isset($GLOBALS['call_data']['To']) && !empty($GLOBALS['call_data']['To'])) { + $caller_id = $GLOBALS['call_data']['To']; + error_log('TWP Workflow Forward: Using incoming number as caller ID: ' . $caller_id); + } elseif (isset($_POST['To']) && !empty($_POST['To'])) { + $caller_id = $_POST['To']; + error_log('TWP Workflow Forward: Using POST To as caller ID: ' . $caller_id); + } elseif (isset($_REQUEST['To']) && !empty($_REQUEST['To'])) { + $caller_id = $_REQUEST['To']; + error_log('TWP Workflow Forward: Using REQUEST To as caller ID: ' . $caller_id); + } + + if ($caller_id) { + $dial->addAttribute('callerId', $caller_id); + error_log('TWP Workflow Forward: Set callerId attribute to: ' . $caller_id); + } else { + error_log('TWP Workflow Forward: No To number found for caller ID, will use account default'); + } + // Add all forward numbers foreach ($forward_numbers as $number) { error_log('TWP Workflow Forward: Adding number to Dial: ' . $number); @@ -753,8 +774,23 @@ class TWP_Workflow { $dial->addAttribute('timeout', '30'); } - if (isset($step['caller_id'])) { + // Set caller ID - use provided value or default to the incoming number + if (isset($step['caller_id']) && !empty($step['caller_id'])) { $dial->addAttribute('callerId', $step['caller_id']); + } else { + // Use the number that was called (To number) as default caller ID + $caller_id = null; + if (isset($GLOBALS['call_data']['To']) && !empty($GLOBALS['call_data']['To'])) { + $caller_id = $GLOBALS['call_data']['To']; + } elseif (isset($_POST['To']) && !empty($_POST['To'])) { + $caller_id = $_POST['To']; + } elseif (isset($_REQUEST['To']) && !empty($_REQUEST['To'])) { + $caller_id = $_REQUEST['To']; + } + + if ($caller_id) { + $dial->addAttribute('callerId', $caller_id); + } } // Set action URL to handle no-answer scenarios