Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recording a voicemail while in a Twilio Queue

Tags:

twilio

I'm writing a call centre app using Twilio, and I've run into a problem. The calls are received and put into a queue, while we find an agent to answer the call. Whilst they're listening to the hold music, they are read their position in the queue, and I'm trying to use a Gather verb to allow them to press 1 and then leave a message.

It all works well, except that it won't record. I've tried recording outside of the queue and it's all fine, so it seems to be the fact that it's in the queue that is the problem. I'm not sure, thus, how to deal with it?

So, if I just send this on initial connection:

<Response><Say>Please record your message after the tone.</Say><Record action="http://ngrok.com/handleVoicemailRecording"></Record></Response>

then it works fine, and calls the method. If however, I do the "proper" route as I see it, then the recording doesn't happen, and the queue immediately re-calls the "waitUrl" action for the queue:

Initial call:

[2016-01-19 17:38:45.637] <Response><Say voice="alice" language="en-AU">Thanks for calling, please note all calls may be recorded for security and training purposes. We'll answer your call very shortly.</Say><Enqueue waitUrl="http://ngrok.com/holdMusic">1COVERAUS</Enqueue></Response>

Queue waitUrl response:

[2016-01-19 17:38:56.202] <Response><Gather numDigits="1" action="http://ngrok.com/leaveVoicemail"><Say>Thanks for waiting, you're 1 in the queue. Press 1 at any time to leave a message.</Say><Play>https://s3-ap-southeast-2.amazonaws.com/somemusic.mp3</Play></Gather></Response>

Record command, the Say of which works, and the Record doesn't

[2016-01-19 17:39:10.861] <Response><Say voice="alice" language="en-AU">Please record your message after the tone.</Say><Record action="http://ngrok.com/handleVoicemailRecording"></Record></Response>

And then 3 seconds later (at the end of the Say), Twilio requests the waitUrl again, having not beeped.

[2016-01-19 17:39:13.757] <Response><Gather numDigits="1" action="http://ngrok.com/leaveVoicemail"><Say voice="alice" language="en-AU">Thanks for waiting, you're 1 in the queue.</Say><Say voice="alice" language="en-AU">Press 1 at any time to leave a message.</Say><Play>https://s3-ap-southeast-2.amazonaws.com/somemusic.mp3</Play></Gather></Response>

Any ideas? Is this by design? Can I get around it in a useful way?

like image 597
Pete Storey Avatar asked Jan 19 '16 17:01

Pete Storey


1 Answers

Twilio developer evangelist here.

This behaviour is by design. The <Enqueue> documentation provides you the verbs that can be used within the waitUrl TwiML. However, this does not mean that you are out of luck, we can still create this feature.

Instead of going from <Gather> to <Say/><Record/> you can use <Leave> to have the user leave the queue. The call won't hang up, rather it will try to carry on from after the original <Enqueue>. Add your <Say/><Record/> in that original TwiML and it will play when the user decides to leave the queue and record a message.

So, you initial TwiML will now be:

<Response>
  <Say voice="alice" language="en-AU">
    Thanks for calling, please note all calls may be recorded for security and training purposes. We'll answer your call very shortly.
  </Say>
  <Enqueue waitUrl="http://ngrok.com/holdMusic">1COVERAUS</Enqueue>
  <Say voice="alice" language="en-AU">
    Please record your message after the tone.
  </Say>
  <Record action="http://ngrok.com/handleVoicemailRecording"></Record>
</Response>

Your waitUrl TwiML stays the same:

<Response>
  <Gather numDigits="1" action="http://ngrok.com/leaveVoicemail">
    <Say>
      Thanks for waiting, you're 1 in the queue. Press 1 at any time to leave a message.</Say>
    <Play>https://s3-ap-southeast-2.amazonaws.com/somemusic.mp3</Play>
  </Gather>
</Response>

And the Gather action simply becomes:

<Response>
  <Leave/>
</Response>

Let me know if that helps at all.

like image 118
philnash Avatar answered Nov 08 '22 01:11

philnash