2

Based on the documentation for the TwiML <Leave> verb, when a caller exits a queue, their call should continue executing the call logic following the <Enqueue> that caused them to enter the queue. In my case, my callers enter the queue by processing this TwiML:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Enqueue>business</Enqueue>
  <Say>Sorry, no one is currently available. Please leave a message.</Say>
  <Record action="${endpoint}/hangup" timeout="10" transcribeCallback="${endpoint}/voicemailHandler"/>
</Response>

Later, I am executing this Javascript logic to trigger the removal of a member from the queue:

await twilioClient
      .queues(queueSid)
      .members('Front')
      .update({url: `${endpoint}/leave`})

The /leave endpoint directs the member to this bit of TwiML:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Leave />
</Response>

I'm running into an issue where, once the Javascript executes, instead of hearing the <Say>, the call just ends and the caller is disconnected. Am I misunderstanding the documentation? If so, how should I restructure my logic to achieve my desired result?

Christopher
  • 885
  • 2
  • 10
  • 16
  • Based on how I read it, the `waitUrl`, https://www.twilio.com/docs/voice/twiml/enqueue#attributes-waitUrl, is what is processing the TwiML document containing the ``. "After 9PM, wait.xml will dequeue the user and return control to the block in the original call TwiML:" – Alan Jun 20 '20 at 11:56

1 Answers1

0

As Alan said, you will need to specify a waitUrl that will process your call and send the Leave instruction.

For example, you could set the waitUrl equal to a Twilio Function that checks if the call is during business hours as shown in the blog post here, and the TwiML would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Enqueue waitUrl="https://zaffre-zorse-5224.twil.io/queue">support</Enqueue>
    <Say>Unfortunately, the support line has closed. Please call again tomorrow.</Say>
</Response>

And your Function would look something like this:

exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.VoiceResponse();

    let moment = require('moment-timezone');
    let timezone = event.timezone || 'America/Los_Angeles';
    const hour = moment().tz(timezone).format('H');
    const dayOfWeek = moment().tz(timezone).format('d');
    
    if ((hour >= 8 && hour < 17) && (dayOfWeek >= 1 && dayOfWeek <= 5)) {
        // "open" from 8am to 5pm, PST.
        twiml.play('http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3');
    } else {
        twiml.leave();
    }
    callback(null, twiml);
};
  • There are plenty of scenarios besides you are calling outside business hours. My scenario is this: a workflow that transverses various filters through timeouts and escalations and eventually ends up in a washout queue. At that point I want to have a verb to determine whether continue waiting or leave a voice mail. Can't do this on the waitUrl because the waitUrl is playing hold music. I could kluge the wait music to end at the same time that escalations are exhausted but is this really the best we can do? – AQuirky May 10 '23 at 18:14
  • The waitUrl supports and other verbs at the same time: https://www.twilio.com/docs/voice/twiml/enqueue#attributes-waitUrl. Press 1 to leave a voicemail or stay on the line to keep waiting. your_hold_music.mp3 The caller would hear your message asking if they would like leave a voicemail first. If they don't press anything, the file will execute. Then this would repeat when the play file finishes. – Samuel Eddy May 19 '23 at 15:17
  • @Samual Eddy, yes but it does not support hold music for the time it takes to traverse the workflow and *then* issue with announcement. What I have concluded is that there is no way to do this exactly. The best you can do is to, on the waitUrl, for 30 seconds and then . – AQuirky May 21 '23 at 21:34
  • @AQuirky if there's any kind of event (or status callback) after traversing the workflow, you should be able to use this to update the call via API and add it to a new queue with a different waitUrl: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress. Since the Queue API doesn't support waitUrl updates for in progress queues, a lot of folks get around it by bouncing calls between different queues with the API. – Samuel Eddy May 23 '23 at 03:16