1
votes

I am trying out sms and calls from Twilio. I am able to send sms and make calls from my Java code. But I am not getting how can I get status callback in the same Java code.

Is there any way I can get status callback events in my java code?

params.add(new BasicNameValuePair("StatusCallback", "https://www.myapp.com/events"));
params.add(new BasicNameValuePair("StatusCallbackMethod", "POST"));
params.add(new BasicNameValuePair("StatusCallbackEvent", "initiated"));
params.add(new BasicNameValuePair("StatusCallbackEvent", "ringing"));
params.add(new BasicNameValuePair("StatusCallbackEvent", "answered"));
params.add(new BasicNameValuePair("StatusCallbackEvent", "completed"));

Also, is there any way we can give the TwiML data (the xml for voice calls) in the function calling function from Java, instead of giving it a URL to the TwiML/XML file. params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));

CallFactory callFactory = client.getAccount().getCallFactory();
Call call = callFactory.create(params);
1

1 Answers

1
votes

Twilio developer evangelist here.

Twilio performs status callbacks as webhooks, much like you get when you receive an incoming call or message. In order to receive these webhooks your application will need to be reachable by Twilio.

If you are having difficulty with that locally, then you might be interested in checking out ngrok which is a great tool for exposing your local development environment to external services like Twilio.

In answer to your other question, you cannot supply your TwiML in the API request to Twilio. You need to have a server that Twilio can request the TwiML from when the call connects.