codeapp17
codeapp17

Reputation: 69

Twilio Status callback url

I am working on voice calling app which is built in java and I need to know the call status when it is picked , rejected or complated.My server end is in java.

I set status callback url while placing a call as mention in the twilio docs. My question which url is to added in that code and do i need to add the funtion for that end point url also.

And what should be the code in that funtion like what are the parameters as I need to print the call status

com.twilio.type.Client clientEndpoint = new com.twilio.type.Client("client:" + to);
        PhoneNumber from = new PhoneNumber(CALLER_ID);
        // Make the call
        Call call = Call.creator(clientEndpoint, from, uri).setMethod(HttpMethod.POST)
                .setStatusCallbackMethod(HttpMethod.POST)
                .setStatusCallback(URI.create("https://57fb8b2c.ngrok.io/events"))
                .setStatusCallbackEvent(
                        Arrays.asList(Call.Event.ANSWERED.toString(), Call.Event.COMPLETED.toString(),
                                Call.Event.INITIATED.toString(), Call.Event.RINGING.toString()))
                .create(client);

        // Print the call SID (a 32 digit hex like CA123..)
        System.out.println(call.getSid() + "//" + call.getStatus());
        return call.getSid();

Upvotes: 0

Views: 2260

Answers (1)

philnash
philnash

Reputation: 73027

Twilio developer evangelist here.

I'm not particularly good at Java, but I can help with what happens when you set a statusCallback URL.

For each of the events you set as the statusCallbackEvent you will receive an HTTP request to your statusCallback URL when the call enters that state.

You will need to implement an endpoint (in your case, at the path /events as that's the URL you are setting) that can receive these incoming HTTP requests.

When Twilio makes the status callback request it includes all the regular webhook parameters, such as CallSid so you can tie the request to the known call sid.

The request will also include some other parameters, most importantly in your case the CallStatus parameter. The value will be one of queued, initiated, ringing, in-progress, busy, failed, or no-answer. There's more on what they mean here.

I hope that helps a bit.

Upvotes: 1

Related Questions