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
Subscription not created when using production
Tags: subscription
Dec 22, 2022 at 4:40pm   •   2 replies  •  0 likes
Brad Gold

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 Answers
answered on Dec 24, 2022 at 12:33am  

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.


 0
answered on Dec 23, 2022 at 8:21am  

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

 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