question

Brad Gold avatar image
Brad Gold asked Brad Gold answered

Subscription not created when using production

I have a simple app that just logs out responses from the telephony subscription. It works great in the Sandbox, but after I graduated it and use it in Production (and changing credentials), it does not create a subscription (I use this to check: https://developers.ringcentral.com/api-reference/Subscriptions/listSubscriptions). But I don't see any errors in the console.

It does print out "Ready to receive Telephony via PubNub." so it seems like it worked, but I don't see a subscription listed. Just wondering how I diagnose this further, or if I am missing something.


const RC   = require('@ringcentral/sdk').SDK
const Subs = require('@ringcentral/subscriptions').Subscriptions
require('dotenv').config();

var rcsdk = new RC({
    'server':       process.env.RC_SERVER_URL,
    'clientId':     process.env.RC_CLIENT_ID,
    'clientSecret': process.env.RC_CLIENT_SECRET
});
var platform = rcsdk.platform();
platform.login({
    'username':  process.env.RC_USERNAME,
    'password':  process.env.RC_PASSWORD,
    'extension': process.env.RC_EXTENSION
})

var subscriptions = new Subs({ sdk: rcsdk });
var subscription = subscriptions.createSubscription({
    pollInterval: 10 * 1000, renewHandicapMs: 2 * 60 * 1000
});

platform.on(platform.events.loginSuccess, () => {
    subscribe_for_telephony_notification()
});

function subscribe_for_telephony_notification() {
    subscription.setEventFilters(['/restapi/v1.0/account/~/telephony/sessions'])
        .register()
        .then(function(subscriptionResponse) {
            console.log(subscriptionResponse);
            console.log("Ready to receive Telephony via PubNub.")
        })
        .catch(function(e) {
            console.error(e);
            throw e;
        });
}

subscription.on(subscription.events.notification, function(msg) {
    console.log(msg.body);
});
subscription
1 |3000

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

First of all, you don't need to call this line. The SDK does auto refresh and keep the subscription active as long as you keep the subscription instance.

var subscription = subscriptions.createSubscription(
{ pollInterval: 10 * 1000, renewHandicapMs: 2 * 60 * 1000 }
);

Then add and call this function to list all subscriptions created by your app

async function readAllSubscriptions() {
  try {
    var resp = await platform.get('/restapi/v1.0/subscription')
    var jsonObj = await resp.json()
    if (jsonObj.records.length > 0){
      for (var record of jsonObj.records) {
        if (record.deliveryMode.transportType == 'PubNub'){
          console.log(record)
        }
      }
    }else{
      console.log("No subscription")
    }
  }catch(e) {
    console.log(e.message)
  }
}
1 |3000

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

Brad Gold avatar image
Brad Gold answered

I just took it straight from the example here: https://developers.ringcentral.com/guide/notifications/push-notifications/quick-start which does have those lines in it.

Thanks for the readAllSubscriptions() function. That was telling me that I was missing the CallControl permission. Once I added that, it worked.

Merry Christmas Phong.

1 |3000

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

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys