Fix caller ID for workflow forward and ring group tasks

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 <noreply@anthropic.com>
This commit is contained in:
2025-09-18 16:46:52 -07:00
parent 90cb03acfd
commit 0ee8210fef

View File

@@ -570,6 +570,27 @@ class TWP_Workflow {
$dial->addAttribute('timeout', $timeout); $dial->addAttribute('timeout', $timeout);
error_log('TWP Workflow Forward: Using 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 // Add all forward numbers
foreach ($forward_numbers as $number) { foreach ($forward_numbers as $number) {
error_log('TWP Workflow Forward: Adding number to Dial: ' . $number); error_log('TWP Workflow Forward: Adding number to Dial: ' . $number);
@@ -753,8 +774,23 @@ class TWP_Workflow {
$dial->addAttribute('timeout', '30'); $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']); $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 // Set action URL to handle no-answer scenarios