'How to make an outbound call in Twilio with Java, using TwiML and not a URL?
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
Solution 1:[1]
I understand that your question and Phil's answer are over four years old; however, one can place outbound calls with Twilio and directly pass the TwiML that you want the call to follow concurrently, starting in Twilio version 3.39.0 as shown here: https://github.com/twilio/twilio-node/releases/tag/3.39.0. One can now opt the URL for TwiML starting in this release.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vincent T Nguyen |
