Reputation: 1005
We want to call our customers using an outbound API call. It presents a simple IVR flow "Press 1 to confirm, 2 to talk to an agent". The call should be forwarded to another number when the user presses 2. Is this possible in Twilio?
Upvotes: 0
Views: 320
Reputation: 3889
Heyooo, Twilio Developer Evangelist here. 👋
That's totally possible. :) What you can do is use the PHP helper library to make the outbound call.
$twilio->calls
->create(
"+15558675310", // to
"+15017122661", // from
array("url" => "http://demo.twilio.com/docs/voice.xml")
);
To create a call you have to define a from
and to
number but also an endpoint that responds the configuration TwiML for the call. In your case, the TwiML configuration for the outbound call could look like this.
<Response>
<Gather action="/handle-input" timeout="5" numDigits="1">
<Say>
Press one to confirm and two to talk to an agent.
</Say>
</Gather>
</Response>
This will say the message out loud and wait for a number press using the Gather verb. The important piece of the gather configuration is the action
attribute. It defines an endpoint that will be called after the called number responded to your call and it will then include the entered information.
The /handle-input
endpoint can then parse the response body and look for the Digits
key. It will include the pressed digits. Depending on what number was pressed /handle-input
can then respond with different TwiML and either say "Thank you" or forward the ongoing call to another number.
To forward the ongoing call the following configuration would do the trick.
<Response>
<Dial>+4915...</Dial>
</Response>
I hope that helps. :) You can also have a look at this detailed tutorial covering a similar case like this.
Upvotes: 1