Skip to main content
Question

Subscription not created when using production

  • 23 December 2022
  • 2 replies
  • 341 views

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

2 replies

Userlevel 2
Badge

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

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.

Reply