question

Muhammad Shoaib avatar image
Muhammad Shoaib asked ·

Not able to receive inbound calls

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 which worked for sometime 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 happed again with the new account.

notificationspresence
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.

Phong Vu avatar image
Phong Vu answered ·

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

1 comment Share
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.

+19294682382

this is the latest account phone number that i am using and i have created 5 accounts now and i am not able to receive notifications from account other than the latest one. Is there any limit in sending notifications on sandbox account and does the same thing will happen when we switch to production?

0 Likes 0 · ·
Phong Vu avatar image
Phong Vu answered ·

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.

Share
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.

Muhammad Shoaib avatar image
Muhammad Shoaib answered ·

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);
        }
    }
}


Share
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.

Muhammad Shoaib avatar image
Muhammad Shoaib answered ·

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.

Share
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.

Muhammad Shoaib avatar image
Muhammad Shoaib answered ·

@Phong Vu

Share
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.

Phong Vu avatar image
Phong Vu answered ·

Sorry for the delayed response.

First of all, for serious problem and if you are a customer, you can always send your question to devsupport@ringcentral.com 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.

Share
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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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