Reputation: 70
The users in the system records audio for one of the products that they have with us, and that audio is saved in our server and is used later in the platform for some functionalities.
Currently the audio is recorded in this way:
User calls to the phone number *1234*1# to record the audio for product 1. User calls to the phone number *1234*2# to record the audio for product 2. My client asked me to make it this way:
User in the dashboard and there is a button called "Record Audio". User is prompted with a popup asking for his phone number, so the platform can call him. User answers the call and hears something like "Hello blah blah blah... Please click [in the web page dashboard] the product you want to record audio for" User clicks the product he wants to record audio to, so in the call, the machine says "Record the audio for product [product clicked] after the beep"... I think I have described the key of the idea. Is that possible?
I'm using PHP.
Upvotes: 2
Views: 109
Reputation: 73075
Twilio developer evangelist here.
You absolutely can do this using Twilio. I'll give you a couple of options too, as what you describe isn't so straightforward. So we'll build up to it.
The easiest version of what you're asking to do would be to reverse the flow you describe slightly. You could have the user click the button for the product they wish to record audio for, then you ask for their phone number. Once you have that, you can use a similar system that was built in this click to call PHP tutorial to call the user back to receive their recording.
The key would be that you could include a parameter in the URL you use when you create your call that records the product ID.
$call = $client->account->calls->create(
$_ENV['TWILIO_NUMBER'], // A Twilio number in your account
$number, // The user's phone number
"http://example.com/calls?productId=" . $productId // the product the user selected
);
Then, when the call connects, Twilio will make an HTTP request to that URL, passing the product ID with it and you can handle the recording the same way you would previously.
It is, however, possible to do what you want entirely. It takes a little more work though.
Once you have received the user's phone number you can make the call to them as described with the click to call example above. You'll want to save the CallSid that the API returns as you will need to use it later.
$call = $client->account->calls->create(
$_ENV['TWILIO_NUMBER'], // A Twilio number in your account
$number, // The visitor's phone number
$url
);
$callSid = $call->sid;
The URL you supply in this call should return TwiML that speak to the user to tell them to select the item on the page. Something like:
<Response>
<Say loop="0">Please select the product on the page you wish to record audio for.</Say>
</Response>
Then, when your user presses a button, you will need to trigger another call to the REST API to redirect the call from the repeating message to TwiML that handles the recording. This is where you need the call Sid from the call you created. Your request will look a bit like this:
$call = $client->account->calls->get($callSid);
$call->update(array(
"Url" => "http://example.com/calls?productId=" . $productId
));
Check out the documentation on modifying live calls for more detail on this.
Let me know if this helps at all.
Upvotes: 1
Reputation: 3859
This can be done with Twilio.
When the user click on the record audio and submit his/her phone number you can make an outbound call to the user number using twilio rest api.
Once the caller accepts the call play a looping message asking him/her to click on the dashboard to record . On the dashboard click make another rest call to twilio to update the previous call to route to your audio recording flow.
Upvotes: 1