From abebe7fb9ca6b6fbbe018d10d93c5fa4133e1aea Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 7 Oct 2026 10:12:38 -0700 Subject: [PATCH] Fix IVR queue options dropping calls IVR menu options routed to a queue returned with no queue name and a child, which is invalid without TaskRouter, so Twilio hung up immediately. Redirect to the custom queue-wait handler instead, matching the workflow queue step. Co-Authored-By: Claude Opus 5.5 --- includes/class-twp-webhooks.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/class-twp-webhooks.php b/includes/class-twp-webhooks.php index 1c6d03f..e693f9a 100644 --- a/includes/class-twp-webhooks.php +++ b/includes/class-twp-webhooks.php @@ -1064,11 +1064,19 @@ class TWP_Webhooks { if ($position) { error_log('TWP IVR Queue: Call added to position ' . $position); - // Generate TwiML for queue wait with proper callback URL + // Redirect to our custom queue wait handler (same as workflow queue steps). + // A bare with a child is invalid without TaskRouter and drops the call. $twiml = new SimpleXMLElement(''); - $enqueue = $twiml->addChild('Enqueue'); - $enqueue->addAttribute('waitUrl', home_url('/wp-json/twilio-webhook/v1/queue-wait?queue_id=' . $queue_id)); - $enqueue->addChild('Task', json_encode(array('queue_id' => $queue_id, 'position' => $position))); + $say = $twiml->addChild('Say', 'Please hold while we connect you to the next available agent.'); + $say->addAttribute('voice', 'alice'); + $wait_url = add_query_arg(array( + 'queue_id' => $queue_id, + 'call_sid' => urlencode($call_data['call_sid']) + ), home_url('/wp-json/twilio-webhook/v1/queue-wait')); + $redirect = $twiml->addChild('Redirect'); + $redirect[0] = $wait_url; + $redirect->addAttribute('method', 'POST'); + error_log('TWP IVR Queue: Redirecting to queue wait handler: ' . $wait_url); return $this->send_twiml_response($twiml->asXML()); } else { error_log('TWP IVR Queue: Failed to add call to queue');