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');