I’d love some advice on my Twilio setup for a problem I’m trying to solve.
I want to place incoming calls on hold before routing to an available agent. Calls are routed to agents one at a time and are routed on a round robin basis, meaning it is routed to the agent who has been available for the longest, first.
Here is the relevant part of my code:
# Endpoint for TwiML Voice URL
def connect
response = Twilio::TwiML::VoiceResponse.new
response.say(voice: "woman", message: "Connecting you to an agent. This call may be recorded for quality purposes. One moment please.")
response.enqueue(wait_url: "wait_music", name: "support")
# Simple agent call routing
client.calls.create(
url: "/queue",
to: "client:support_agent",
from: params[:From]
)
return response.to_s
end
def wait_music
response = Twilio::TwiML::VoiceResponse.new
response.play(url: "http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3")
return response.to_s
end
def queue
response = Twilio::TwiML::VoiceResponse.new
response.dial do |dial|
dial.queue("support")
end
return response.to_s
end
I’m facing the issue where agent calls are triggered immediately in Twilio, even while the /connect
endpoint is still processing the prompt and returning the TwiML back to Twilio. This results in agents hearing the ring before the caller finishes hearing the wait music or prompt about call recording.
I’m looking for a way to ensure the prompt completes and the caller is queued before agents are dialed. In a Zendesk video demo, agents are called only after the full prompt is played and the caller is queued, which is my goal.