javascriptwebrtcringcentralcaller-idringout

How to set Caller ID with area code matching using RingCentral?


When using RingCentral for making outbound calls, is it possible do Local Presence or to set the Caller ID (CLID)? I have a set of 1000+ phone numbers with various area codes for my company I want to be able to use for Caller ID when dialing out. I also have a number of different agents making calls so I need multiple agents to be able to use the same Caller ID simultaneously.

I'm using the RingCentral WebRTC JavaScript SDK and didn't see a Caller ID option. I see an option to set Caller ID for RingOut but no Local Presence option.


Solution

  • After asking and trying things out I figured out the following approach which can be done via WebRTC or RingOut.

    (1) Assigning Caller ID (CLID) Phone Numbers

    To load multiple CLID phone numbers into a RingCentral account, add them as Company Numbers which can be done in the Online Account Portal for the Admin account under:

    Home > Phone System > Company Numbers and Info > Add Number

    I assigned all of these to Auto-Receptionist.

    Once these numbers are loaded as Company Numbers, they should be available to users to use as a CLID. To verify this, retrieve the list of CLID numbers available to a user by calling the following REST API endpoint after the user has authorized the app:

    /restapi/v1.0/account/~/extension/~/phone-number

    The numbers returned that can be used for Caller ID will have CallerId as one of the elements in the features property.

    (2) Selecting the Proper CLID based on Destination Number

    In your app, once you have the number to be dialed, find the closest matching area code. The best is if there is an exact match for your area code. After that, find the one you have that is geographically the closest.

    To identify the best number to use, an areacode to lat/lon mapping with nearest-neighbor matching can be used. I wasn't able to find a direct code to lat/lon mapping but it's possible to do one of the following:

    1. areacode to lat/lon: You can use a direct areacode to lat/lon database such as the one here: https://github.com/grokify/gotilla/blob/master/strconv/phonenumber/us-area-code-geo.csv
    2. areacode to zipcode with lat/lon: You can use a zipcode dataset with areacode and lat/lon data as mentioned by Benjamin Dean. Zipcodes are useful because more dense areas have more zipcodes ensuring highly populated areas are represented more.
    3. areacode to LOCODE with lat/lon: UN LOCODES also have lat/lon information and can be used. Ideally each LOCODE would be mapped to a population for weighting purposes.

    For a quick solution, I took the areacodes and mapped each to the UN LOCODE dataset here:

    Once a UN LOCODE is available, the lat/lon in the LOCODE dataset can be used and a distance can be calculated. Of note, some cities do not have lat/lon data it would be ideal to submit that to the UN LOCODE project. Right now this only one primary city per areacode but it can be enhanced to have multiple cities. In the ideal case, all cities with UN LOCODES in the US and Canada would be mapped to areacodes (and zipcodes).

    (3) Making the Call with the CLID

    With RingCentral, it is possible to set your Caller ID to authorized numbers including a user's own numbers and company numbers. This can be done by both WebRTC and RingOut which are described below.

    (3.1) Making the Call with the CLID via WebRTC

    Users should login with their own extensions so user calls will not conflict with each other. Then the app can set the preferred CLID using the RingCentral WebRTC SDK using the fromNumber parameter as shown:

    var session = webPhone.userAgent.invite('PHONE_NUMBER', {
        media: {
            render: {
                remote: document.getElementById('remoteVideo'),
                local: document.getElementById('localVideo')
            }
        },
        fromNumber: 'CALLERID_NUMBER', // Optional, Company Number will be used as default
        homeCountryId: '1' // Optional, the value of
     }).then(...);
    

    (3.2) Making the Call with the CLID via RingOut

    For completeness, it is also possible to set the Caller ID via RingOut using the following:

    POST /restapi/v1.0/account/~/extension/~/ring-out
    
    {
        "from": {"phoneNumber": "+12125550101"},
        "to": {"phoneNumber": "+16175550101"},
        "callerId": {"phoneNumber": "+16505550101"},
        "playPrompt": true
    }
    

    https://developer.ringcentral.com/api-reference#RingOut-makeRingOutCall