2
votes

I'm trying to create an IVR Phone tree through REST API in Salesforce (Twilio API). The problem is that I can't catch any other callback status except 'completed'.

If the call was cancelled or there was no response on this call, Twilio sends a call response with 'completed' status anyway.

Moreover, a customer gets a voicemail with a recorded 'welcome' message and first phone tree question after an unsuccessful call attempt.

There is a code sample of how calls are created :

TwilioRestClient client = new TwilioRestClient(TwilioSID, TwilioToken);
Map<String,String> params = new Map<String, String>(); 

String webURL = webServerURL;

params.put('To', phone);  
params.put('From', phoneFrom);   
params.put('Url', webURL); 
params.put('Method', 'GET'); 
params.put('FallbackUrl', webURL);
params.put('FallbackMethod', 'GET');
params.put('StatusCallback', webURL);
if (!System.Test.isRunningTest()) {
    try {
        TwilioCall call = client.getAccount().getCalls().create(params);
    } catch(Exception ex) {
    }
}

In addition, I was trying to add 'StatusCallbackEvent' parameter (link to Twilio documentation - https://www.twilio.com/docs/voice/twiml#callstatus-values) :

params.put('StatusCallbackEvent', 'busy canceled completed failed no-answer');

// and other optiions like :
// params.put('StatusCallbackEvent', 'busy');
// params.put('StatusCallbackEvent', 'canceled');
// params.put('StatusCallbackEvent', 'completed');
// params.put('StatusCallbackEvent', 'failed');
// params.put('StatusCallbackEvent', 'no-answer');

But there was no any difference in a callback status after failed calls.

How should I make calls to get Twilio call responses with all finalized statuses ('busy', 'failed', 'no-answer', etc ...) ?

1

1 Answers

0
votes

Twilio developer evangelist here.

When you set a URL for the StatusCallback then by default you will only receive callbacks when the call is "completed". A completed call may have different reasons for being completed though, such as "busy", "failed", "no-answer" or plain "completed" and you can read that value from the CallStatus parameter that is sent to the URL.

You can subscribe to other events though, as you tried. The only thing is you were trying to subscribe to the potential statuses and not the events themselves.

For a call you can subscribe to "initiated", "ringing", "answered" and "completed". So try:

params.put('StatusCallbackEvent', 'initiated ringing answered completed');