Search code examples
twiliotwilio-click-to-calltwilio-taskrouter

Twilio Client JS SDK doesn't show ringing state for outgoing call


I'm following the Dynamic Call Center with Python and Django to build a simple Django call center. I'm handling outgoing and incoming calls like so:

@csrf_exempt
def CallTaskRouter(request):
    response = VoiceResponse()
    if 'phoneNumber' in request.POST:
        dial = response.dial(caller_id=TWILIO_NUMBER, answer_on_bridge='true')
        dial.number(request.POST['phoneNumber'], 
        status_callback_event='initiated ringing answered completed', 
        status_callback='https://my-url/status', 
        status_callback_method='GET')

    else:
        response = VoiceResponse()
        gather = response.gather(numDigits=1, action='https://my-url/support/enqueue', method="POST")
        gather.say("To speak to support, press one.", language='en-US')
        gather.say("To speak to sales, press two.", language='en-US')
        response.append(gather)

    return HttpResponse(
        str(response), content_type='application/xml; charset=utf-8'
    )

I'd like to notify user when the customer's phone is "ringing" and I'd like to start the call time counter once the call is answered. I use js to setup "device" and initiate the call like so:

device = new Twilio.Device(data.token, { 
            codecPreferences: ['opus', 'pcmu'],
            fakeLocalDTMF: true,
            enableRingingState: true,
        });

function callCustomer(phoneNumber) {
    numberToCall = phoneNumber;
    var params = { phoneNumber: phoneNumber};
    newConnection = device.connect(params); 
    newConnection.on('ringing', function(){
        initiateCallTime();
        console.log('Ringing')
    });
    };

Even though I followed all the inquiries in documentation (answer_on_bridge='true', enableRingingState: true) the connection is starting with "open" state (I used connection.status() function to find out) and doesn't go thought the expected status value ("pending", "connecting", "ringing"...)

Am I missing anything? please help


Solution

  • If you are using a trial account for Twilio voice, you can NOT use "ringing" functionality. See here.

    I created an issue for it here.