Is it possible to play a recording and then gather digits from the receiver of a call after a call ends (the caller hangs up)?
Similar to: https://www.twilio.com/docs/api/twiml/gather just that it's the receiver and not the caller who ask and that it happens when the call ends.
Twilio Evangelist here. Thanks for the clarification.
You can do this, but you need to use a conference call. Imagine Alice is calling Jack. Normally, you would use TwiML like this:
<Response> <Dial> +15551234567 </Dial> </Response>
What you need to do is dial Alice into a conference call:
<Response> <Dial> <Conference>Alice and Jack</Conference> </Dial> </Response>
Then you need to make an outbound API call to dial Jack into the conference. In Ruby this would be something like this:
require 'twilio-ruby' client = Twilio::REST::Client.new "account-sid", "account-token" cient.account.calls.create to: "+15551234567", from: "some-twilio-number", url: "Your app URL"
This will use the same TwiML as above to join Jack into the conference. You'll need to look at the details for a
<Conference> to avoid/select holding music, and to prevent the conference ending when Alice hangs up. Something like this:
<Response> <Dial> <Conference endConferenceOnExit="false" beep="false" waitUrl="http://some-twilml-no-hold-music"> Alice and Jack </Conference> </Dial> </Response>
Now, you will also need to use the callbacks for when the call ends (you should also set this on your Twilio Number in the Dashboard, or through the API.
Now, you can take the Call SID of whoever remains in the conference call (you'll get this when you receive the initial request for the TwiML), and use the REST API to modify that call, redirecting them to new TwiML:
require 'twilio-ruby' client = Twilio::REST::Client.new "account-sid", "account-token" call = client.account.calls.get "my-call-sid" call.redirect_to url: "http://new-url-of-twiml", method: "POST"
This allows you to redirect the call to TwiML such as:
<Response> <Gather action="http://some-url-to-send-digits-to"> <Play>http://some-mp3-or-wav-file</Play> </Gather> </Response>
Twilio will play the MP3/WAV file, while listening for any key (DTMF) tones the user enters. You'll need to configure your
<Gather> depending on how many keys you want to listen for etc. But that's very straight forward.
Hope this helps!