News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Why am I not able to receive inbound calls?
Tags: sdk
Jan 13, 2020 at 3:09am   •   6 replies  •  0 likes
Muhammad Shoaib

Hi.

After making lots of inbound calls in I am not able to receive calls present event notifications in sandbox.

Before that the call status was Voice mail and the duration was 33 sec but now it show status Unknown and the duration is 6 sec in call logs.

The same thing happened with my first account and then I created another one that worked for some time and then I had to create new account which also worked for some time and then I created another account which is working now and I am able to receive notifications and may be the same thing can happen again with the new account.

6 Answers
answered on Feb 25, 2020 at 9:59am  

Sorry for the delayed response.

First of all, for serious problems and if you are a customer, you can always send your question to the developer support team by submitting a support ticket for more dedicated support.

Then, when something stops working on a sandbox, don't rush to create a new one before trying to solve the problem or asking us. to check your sandbox account. Sandbox account has limited hours of making phone calls etc.

As you said, now you have 3 sandbox accounts and I am not sure which one should I have a look at to see what could be wrong. The sandbox account you gave me with the main company number +19294682382 has ran out of limit (519 used minutes out of 500). I just reset it for you so you now can try with that sandbox account.

One thing to remember when testing notification is that each account can have max 20 subscriptions. Every time you subscribe for a notification, you should save the subscription id and the next time you run the test app again, check if that subscription still exists then delete it before making a new one. For app that may run for weeks or months, I recommend to use webhooks notification instead of PubNub.


 0
answered on Feb 25, 2020 at 3:42am  

 0
answered on Feb 21, 2020 at 5:44am  

I have never logged in to softfone app and below is my code that i am using which works fine but after sending many calls it stops receiving notifications so i have to create new account.


If i log in to softphone will it resolve the issue?

I am currently configuring it in sandbox so if i switch to production does it solve the issue in production?

@Phong Vu

/* eslint-disable no-unreachable */
"use strict";
const SDK = require('ringcentral');
const number_formatter = require("libphonenumber-js");
const common = require('./common');
const commEmitter = common.commonEmitter;
const _ = require('lodash');

module.exports = class RC {
    constructor(nes) {
        this.shared = nes.shared;
        this.platform = {};
        this.subscription = {};
        this.ringcentral_var = {};
        this.db = nes.modules.db;
        this.patient = {};
    }

    async init() {
        if(_.isEmpty(this.shared.config.ringcentral)) return console.log("Ringcentral credentials not found")
        let to_init = this.shared.config.ringcentral;
        if(to_init.nes_ringcentral_enabled) {
            this.init_ringcentral();
        }
    }

    init_ringcentral(){
        RC.ringcentral_var = this.shared.config.ringcentral;

        if(RC.ringcentral_var.nes_rc_appKey != '' && RC.ringcentral_var.nes_rc_appSecret != '') {
            RC.db = this.db;
            let rcsdk = new SDK({
                server:SDK.server.sandbox,
                appKey: this.shared.config.ringcentral.nes_rc_appKey,
                appSecret:this.shared.config.ringcentral.nes_rc_appSecret
            });
            RC.platform = rcsdk.platform();
            RC.subscription = rcsdk.createSubscription();
            this.login_ringcentral(RC.ringcentral_var);
        }
    }

    // ringcentral login using account number and pass
    login_ringcentral(ringcentral_var){
        
        if(ringcentral_var.nes_rc_username != '' && ringcentral_var.nes_rc_password != '') {
            let un= ringcentral_var.nes_rc_username;
            let pwd= ringcentral_var.nes_rc_password;
            let that = this;
            // need to handle disconnect and reconnect on disconnect
            RC.platform.login({
                username:un,
                password:pwd
            }).then(function(){
                RC.platform.get(`/restapi/v1.0/subscription`).then((r) => {
                    let subs = JSON.parse(r._text);

                    // if there are earlier subscriptions delete them
                    // if there are multiple events subscribe will need to handle their removal
                    if(subs.records.length > 0){
                        let _deletesubsciption = [];
                        for(let i = 0; i < subs.records.length; i++) {
                            _deletesubsciption.push(RC.platform.delete('/restapi/v1.0/subscription/' + subs.records[i].id));
                        }
                        Promise.all(_deletesubsciption).then((r) => {
                            that.subscribe_extensions(ringcentral_var);
                        });
                    }else{
                        that.subscribe_extensions(ringcentral_var);
                    }
                });
            })
            .catch(() => console.log('invalid credentials of ringcentral'))
        }
    }

    subscribe_extensions(ringcentral_var){
        var extensions = [];
        var page = 1;

        function get_extensions_page() {

            return RC.platform
                .get('/account/~/extension/', {
                    type: 'User',
                    status: 'Enabled',
                    page: page,
                    perPage: 500 //REDUCE NUMBER TO SPEED BOOTSTRAPPING
                })
                .then(function (response) {
                    var data = response.json();
                    extensions = extensions.concat(data.records);
                    if (data.navigation.nextPage) {
                        page++;
                        return get_extensions_page();
                    } else {
                        return extensions;
                    }
                });
        }

        return get_extensions_page()
            .then(this.create_event_filter)
            .then(this.start_subscription)
            .catch(function (e) {
                console.error(e);
                throw e;
            });
    }

    // create an array of event filter uri that can be hit to subscribe for presence events
    create_event_filter(extensions){
        var _eventFilters = [];
        for(var i = 0; i < extensions.length; i++) {
            var extension = extensions[i];
            _eventFilters.push('/account/~/extension/' + extension.id + '/presence?detailedTelephonyState=true');
        }
        return _eventFilters;
    }

    // create subscription and start listening
    start_subscription(eventFilters) {
        return RC.subscription
            .setEventFilters(eventFilters)
            .register().then(function(){
                RC.platform.get(`/restapi/v1.0/subscription`).then(() => {
                    console.log("Waiting for RingCentral Events");
                });

                // Register Subscription Event Listeners
                RC.subscription.on(RC.subscription.events.notification, handle_subscription_notification);
                RC.subscription.on(RC.subscription.events.renewSuccess, handle_subscription_renew_success);
                RC.subscription.on(RC.subscription.events.renewError, handle_subscription_renew_error);
            });

        // Define Event Handlers
        // might need to cache user and patient data to increase performance
        async function handle_subscription_notification(msg) {
            let user = {};
            let ext = msg.body.activeCalls[0].to;
            let pat_num = msg.body.activeCalls[0].from;
            pat_num = number_formatter.parsePhoneNumberFromString(pat_num).formatNational();
            let usql = `SELECT id,username FROM form_user where rc_ext = %L`;
            let ru = await RC.db.env.ds.query(usql, [ext]);
            let psql = `SELECT id,auto_name FROM form_patient where phone_cell = %L OR phone_home = %L OR phone_work = %L`;
            let rp = await RC.db.env.ds.query(psql, [pat_num]);
            if(ru.length > 0 && rp.length > 0){
                user['extension_id'] = msg.body.extensionId;
                user['call_status'] = msg.body.telephonyStatus;
                user['user_id'] = ru[0].id;
                user['patient_id'] = rp[0].id;
                user['patient_name'] = rp[0].auto_name;
                if(msg.body.telephonyStatus == "Ringing") {
                    commEmitter.emit("rc_event", user)
                }
            }
        }

        function handle_subscription_renew_success(data) {
            console.log('RENEW SUBSCRIPTION SUCCESS DATA: ', data._response.status);
        }

        function handle_subscription_renew_error(data) {
            console.log('RENEW SUBSCRIPTION ERROR DATA: ', data);
            RC.login_ringcentral(RC.ringcentral_var);
        }
    }
}



 0
answered on Feb 21, 2020 at 8:05am  

also in the call logs the call lasts for 06 seconds and it shows the result Unkown and before that when i was receiving notifications the call lasted for 03:47 minutes.


 0
answered on Feb 21, 2020 at 5:53am  

I have never logged in to softphone and below is my code that i am using which works correct and sends notifications but after making lots of calls it stops sending notifications and i have to create new account.

My concern is that if i switch to production does it happens again, i am currently using sandbox.

@Phong Vu

/* eslint-disable no-unreachable */
"use strict";
const SDK = require('ringcentral');
const number_formatter = require("libphonenumber-js");
const common = require('./common');
const commEmitter = common.commonEmitter;
const _ = require('lodash');

module.exports = class RC {
    constructor(nes) {
        this.shared = nes.shared;
        this.platform = {};
        this.subscription = {};
        this.ringcentral_var = {};
        this.db = nes.modules.db;
        this.patient = {};
    }

    async init() {
        if(_.isEmpty(this.shared.config.ringcentral)) return console.log("Ringcentral credentials not found")
        let to_init = this.shared.config.ringcentral;
        if(to_init.nes_ringcentral_enabled) {
            this.init_ringcentral();
        }
    }

   

    init_ringcentral(){
        RC.ringcentral_var = this.shared.config.ringcentral;

        if(RC.ringcentral_var.nes_rc_appKey != '' && RC.ringcentral_var.nes_rc_appSecret != '') {
            RC.db = this.db;
            let rcsdk = new SDK({
                server:SDK.server.sandbox,
                appKey: this.shared.config.ringcentral.nes_rc_appKey,
                appSecret:this.shared.config.ringcentral.nes_rc_appSecret
            });
            RC.platform = rcsdk.platform();
            RC.subscription = rcsdk.createSubscription();
            this.login_ringcentral(RC.ringcentral_var);
        }
    }

    // ringcentral login using account number and pass
    login_ringcentral(ringcentral_var){
        
        if(ringcentral_var.nes_rc_username != '' && ringcentral_var.nes_rc_password != '') {
            let un= ringcentral_var.nes_rc_username;
            let pwd= ringcentral_var.nes_rc_password;
            let that = this;
            // need to handle disconnect and reconnect on disconnect
            RC.platform.login({
                username:un,
                password:pwd
            }).then(function(){
                RC.platform.get(`/restapi/v1.0/subscription`).then((r) => {
                    let subs = JSON.parse(r._text);

                    // if there are earlier subscriptions delete them
                    // if there are multiple events subscribe will need to handle their removal
                    if(subs.records.length > 0){
                        let _deletesubsciption = [];
                        for(let i = 0; i < subs.records.length; i++) {
                            _deletesubsciption.push(RC.platform.delete('/restapi/v1.0/subscription/' + subs.records[i].id));
                        }
                        Promise.all(_deletesubsciption).then((r) => {
                            that.subscribe_extensions(ringcentral_var);
                        });
                    }else{
                        that.subscribe_extensions(ringcentral_var);
                    }
                });
            })
            .catch(() => console.log('invalid credentials of ringcentral'))
        }
    }

    subscribe_extensions(ringcentral_var){
        var extensions = [];
        var page = 1;

        function get_extensions_page() {

            return RC.platform
                .get('/account/~/extension/', {
                    type: 'User',
                    status: 'Enabled',
                    page: page,
                    perPage: 500 //REDUCE NUMBER TO SPEED BOOTSTRAPPING
                })
                .then(function (response) {
                    var data = response.json();
                    extensions = extensions.concat(data.records);
                    if (data.navigation.nextPage) {
                        page++;
                        return get_extensions_page();
                    } else {
                        return extensions;
                    }
                });
        }

        return get_extensions_page()
            .then(this.create_event_filter)
            .then(this.start_subscription)
            .catch(function (e) {
                console.error(e);
                throw e;
            });
    }

    // create an array of event filter uri that can be hit to subscibe for presence events
    create_event_filter(extensions){
        var _eventFilters = [];
        for(var i = 0; i < extensions.length; i++) {
            var extension = extensions[i];
            _eventFilters.push('/account/~/extension/' + extension.id + '/presence?detailedTelephonyState=true');
        }
        return _eventFilters;
    }

    // create subscription and start listening
    start_subscription(eventFilters) {
        return RC.subscription
            .setEventFilters(eventFilters)
            .register().then(function(){
                RC.platform.get(`/restapi/v1.0/subscription`).then(() => {
                    console.log("Waiting for RingCentral Events");
                });

                // Register Subscription Event Listeners
                RC.subscription.on(RC.subscription.events.notification, handle_subscription_notification);
                RC.subscription.on(RC.subscription.events.renewSuccess, handle_subscription_renew_success);
                RC.subscription.on(RC.subscription.events.renewError, handle_subscription_renew_error);
            });

        // Define Event Handlers
        // might need to cache user and patient data to increase performance
        async function handle_subscription_notification(msg) {
            let user = {};
            let ext = msg.body.activeCalls[0].to;
            let pat_num = msg.body.activeCalls[0].from;
            pat_num = number_formatter.parsePhoneNumberFromString(pat_num).formatNational();
            let usql = `SELECT id,username FROM form_user where rc_ext = %L`;
            let ru = await RC.db.env.ds.query(usql, [ext]);
            let psql = `SELECT id,auto_name FROM form_patient where phone_cell = %L OR phone_home = %L OR phone_work = %L`;
            let rp = await RC.db.env.ds.query(psql, [pat_num]);
            if(ru.length > 0 && rp.length > 0){
                user['extension_id'] = msg.body.extensionId;
                user['call_status'] = msg.body.telephonyStatus;
                user['user_id'] = ru[0].id;
                user['patient_id'] = rp[0].id;
                user['patient_name'] = rp[0].auto_name;
                if(msg.body.telephonyStatus == "Ringing") {
                    commEmitter.emit("rc_event", user)
                }
            }
        }

        function handle_subscription_renew_success(data) {
            console.log('RENEW SUBSCRIPTION SUCCESS DATA: ', data._response.status);
        }

        function handle_subscription_renew_error(data) {
            console.log('RENEW SUBSCRIPTION ERROR DATA: ', data);
            RC.login_ringcentral(RC.ringcentral_var);
        }
    }
}



 0
answered on Feb 20, 2020 at 10:57am  

It looks like you have never login to your user account using a RingCentral softphone. If that is the case, download the soft phone and switch to the sandbox mode and login the phone with your user credentials. Then make a phone call to that number to make sure the phone is ringing.

If doing the above does not help, please also share some code how you implement the notification.


 0
answered on Jan 13, 2020 at 9:49am  

What are those sandbox accounts main company numbers (or account ids)?


 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us