use of com.twilio.twiml.voice.Say in project api-snippets by TwilioDevEd.
the class TwilioHandleRecordingServlet method service.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
String recordingUrl = request.getParameter("RecordingUrl");
Say sayHello = new Say.Builder("Listen to your recorded message.").build();
Say sayGoodbye = new Say.Builder("Goodbye").build();
VoiceResponse twiml;
if (recordingUrl != null) {
Play play = new Play.Builder(recordingUrl).build();
twiml = new VoiceResponse.Builder().say(sayHello).play(play).say(sayGoodbye).build();
} else {
response.sendRedirect("/twiml");
return;
}
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
e.printStackTrace();
}
}
use of com.twilio.twiml.voice.Say in project twilio-java by twilio.
the class TwiMLResponseExample method main.
/**
* TwiML example usage.
*
* @param args command line args
* @throws TwiMLException if cannot generate TwiML
*/
public static void main(final String[] args) throws TwiMLException, URISyntaxException {
// Say
Say say = new Say.Builder("Hello World!").voice(Say.Voice.MAN).loop(5).build();
VoiceResponse response = new VoiceResponse.Builder().say(say).build();
System.out.println(response.toXml());
// Gather, Redirect
Gather gather = new Gather.Builder().numDigits(10).say(new Say.Builder("Press 1").build()).build();
Redirect redirect = new Redirect.Builder(new URI("https://example.com")).build();
response = new VoiceResponse.Builder().gather(gather).redirect(redirect).build();
System.out.println(response.toXml());
// Conference
Conference conference = new Conference.Builder("my room").beep(Conference.Beep.TRUE).build();
Dial dial = new Dial.Builder().callerId("+1 (555) 555-5555").action(new URI("https:///example.com")).hangupOnStar(true).conference(conference).build();
response = new VoiceResponse.Builder().dial(dial).build();
System.out.println(response.toXml());
}
use of com.twilio.twiml.voice.Say in project api-snippets by TwilioDevEd.
the class SendSmsDuringCall method service.
// service() responds to both GET and POST requests.
// You can also use doGet() or doPost()
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Create a dict of people we know.
HashMap<String, String> people = new HashMap<String, String>();
people.put("+14158675308", "Curious George");
people.put("+12349013030", "Boots");
people.put("+12348134522", "Virgil");
// if the sender is known, then greet them by name
String name = people.get(Request.getParameter("From")) != null ? people.get(Request.getParameter("From")) : "Monkey";
try {
Say say = new Say.Builder().build(String.format("Hello! %s", name));
Sms sms = new Sms.Builder().build(String.format("%s, thanks for the call!", name));
VoiceResponse twiml = new VoiceResponse.Builder().say(say).sms(sms).build();
} catch (TwiMLException e) {
e.printStackTrace();
}
response.setContentType("application/xml");
response.getWriter().print(twiml.toXml());
}
use of com.twilio.twiml.voice.Say in project api-snippets by TwilioDevEd.
the class TwilioServlet method service.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Create a TwiML response and add our friendly message.
Say say = new Say.Builder("Hello. It's me.").build();
Play play = new Play.Builder("https://deved-sample-assets-2691.twil.io/ahoyhoy.mp3").build();
VoiceResponse twiml = new VoiceResponse.Builder().say(say).play(play).build();
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
e.printStackTrace();
}
}
use of com.twilio.twiml.voice.Say in project api-snippets by TwilioDevEd.
the class VoiceApp method main.
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello Web");
post("/", (request, response) -> {
Say say = new Say.Builder("Hello from your pals at Twilio! Have fun.").build();
VoiceResponse voiceResponse = new VoiceResponse.Builder().say(say).build();
return voiceResponse.toXml();
});
}
Aggregations