1
votes

I'm looking to make an outbound call in a Java application using Twilio. All of the tutorials I found used a static TwiML file hosted on a URL. I haven't been able to find any documentation on how to pass in TwiML as a parameter for an outgoing call.

I found this on this link, but it doesn't explain how to dynamically render TwiML: https://www.twilio.com/docs/guides/how-to-make-outbound-phone-calls-in-java#where-to-next

Of course, the TwiML you use to make the outbound call doesn't need to be a static file like in this example. Server-side Java code that you control can dynamically render TwiML to use for the outbound call.

I've tried the following:

PhoneNumber to = new PhoneNumber(toPhone); // Replace with your phone number
PhoneNumber from = new PhoneNumber(fromPhone); // Replace with a Twilio number
TwiML twiml = new VoiceResponse.Builder()
        .say(new Say.Builder(message).build())
        .build();
Call call = Call.creator(to, from, twiml.toXml()).create(client);

While the Call.creator()has some overloaded methods of (PhoneNumber, PhoneNumber, String), none of them will accept TwiML, nor XML.

How do make an outbound call in Java using TwiML? Thanks

1

1 Answers

3
votes

Twilio developer evangelist here.

You cannot make an outbound call with Twilio and directly pass the TwiML that you want the call to follow at the same time.

When you make the outbound call you need to pass a URL. That URL does not have to return static TwiML though. If you want to return dynamic TwiML you need to set the URL for the call to a URL of a web application that can respond to the request with TwiML.

It might make it more obvious what I mean if you check out some of the dynamic tutorials. This one on building an automated phone survey dynamically generates the next question and takes input from the user in response. This click to call implementation in Java also dynamically generates the <Dial> when the call connects.

Let me know if that helps at all.