sarahjohn avatar image
sarahjohn Posted ·

Need to set Caller ID with area code matching using RingCentral WebRTC

After asking and trying things out I figured out the following:
(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:


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:

areacode to lat/lon: You can use a direct areacode to lat/lon database such as the one here:
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.
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: | Cassandra Database
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

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

1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

No Comments

· Write a Comment

Write a Comment

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.