question

Manager Desk avatar image
Manager Desk asked Steve Cowley commented

PubNub Subscription Event not detecting call notification

Running in node.js .

Not picking up on any call action after successful subscription.

My Code:


                 
  1. function setSubscription() {
  2. const platform = rcsdk.platform()
  3. platform.login({
  4. username: '+14706150273',
  5. extension: '101',
  6. password: '********'
  7. }).then(response => {
  8. const subscription = rcsdk.createSubscription().setEventFilters(['/account/~/telephony/sessions']);
  9. subscription.on(subscription.events.notification, function (msg) {
  10. console.log(msg);
  11. });
  12. subscription.register().then(function (response) {
  13. console.log(response.json());
  14. console.log('Success: Subscription is listening');
  15. }).catch(function (e) {
  16. console.log('Subscription Error: ' + e.message);
  17. });
  18. }).catch(e => {
  19. console.error(e)
  20. })
  21. }


Console output after run showing successfully subscribed (but nothing after) - Calls are showing in the sandbox call log:

                 
  1. [nodemon] starting `node index.js`
  2. Server is running on port: 5000
  3. {
  4. uri: 'https://platform.devtest.ringcentral.com/restapi/v1.0/subscription/edde4bf6-1563-4263-94c7-247954e3ac68',
  5. id: 'edde4bf6-1563-4263-94c7-247954e3ac68',
  6. creationTime: '2021-11-16T22:52:03.946Z',
  7. status: 'Active',
  8. eventFilters: [ '/restapi/v1.0/account/307128004/telephony/sessions' ],
  9. expirationTime: '2021-11-16T23:07:03.946Z',
  10. expiresIn: 899,
  11. deliveryMode: {
  12. transportType: 'PubNub',
  13. encryption: false,
  14. address: '4174641560134678_4a93035d',
  15. subscriberKey: 'sub-c-b8b9cd8c-e906-11e2-b383-02ee2ddab7fe'
  16. }
  17. }
  18. Success: Subscription is listening
developer sandbox
1 |1500 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 Manager Desk commented

Can you add these 2 functions and call the readAllSubsciptions() to see if you have multiple subscriptions. If there is more than one, delete them and retry subscribe for a new subscription.

function deleteRegisteredSubscription(id) {
  platform.delete('/subscription/' + id)
    .then(function (response){
        console.log(response)
    })
    .catch(function(e){
      console.log(e.message)
    });
}

function readAllSubscriptions() {
  platform.get('/subscription')
    .then(function (response) {
      var json = response.json()
      if (json.records.length > 0){
        for (var record of json.records) {
          console.log(record)
        }
      }else{
        console.log("No subscription")
      }
    })
    .catch(function(e) {
      console.log(e.message)
    });
}
7 comments
1 |1500 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.

This initially worked - checking that only 1 subscription is active. However, running this again (Same code exactly), yields the same non responsive result.


Any insight?

0 Likes 0 ·

I don't use the JS SDK 3.x anymore. I am not sure if it is updated to handle to keep the subscription alive after 15 mins. I recommend you to install the SDK v4.x.x, port your code and try again.

$ npm install @ringcentral/sdk @ringcentral/subscriptions --save

I am not aware of notification issues today as it works well for me.

0 Likes 0 ·

I've tried that as well, but can't get the user pass the Auth with that new SDK. Using same credentials.

0 Likes 0 ·
Show more comments
                    
  1. const rcsdk = new SDK({
  2. server: rcCred.RINGCENTRAL_SERVER,
  3. appKey: rcCred.RINGCENTRAL_CLIENTID,
  4. appSecret: rcCred.RINGCENTRAL_CLIENTSECRET,
  5. });
  6. const platform = rcsdk.platform();
  7.  
  8. rcsdk.platform()
  9. .login({
  10. username: rcCred.RINGCENTRAL_USERNAME, // phone number in full format
  11. extension: '', // leave blank if direct number is used
  12. password: rcCred.RINGCENTRAL_PASSWORD
  13. })
  14. .then(async function (response) {
  15. const authData = platform.auth().data();
  16. platform.auth().setData(authData
  17. console.log('logged in
  18. })


Using these exact credentials with the other SDK and it works (the auth)

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered Manager Desk commented

Why do you need this right after authenticated?

const authData = platform.auth().data();
platform.auth().setData(authData ...

Anyway, I masked the sensitive info you post in your previous comment. I could login with my code and here is what you should implement the authentication

const RingCentral = require('@ringcentral/sdk').SDK
const Subscriptions = require('@ringcentral/subscriptions').Subscriptions;
const rcsdk = new RingCentral({
  server: RINGCENTRAL_SERVER,
  clientId: RINGCENTRAL_CLIENTID,
  clientSecret: RINGCENTRAL_CLIENTSECRET
})

var platform = rcsdk.platform();
const subscriptions = new Subscriptions({
   sdk: rcsdk
});
var subscription = subscriptions.createSubscription();
platform.login({
        username: '...',
        extension: '',
        password: '...'
      })

platform.on(platform.events.loginSuccess, function(e){
    console.log("Login success")
    subscribe_for_telephony_notification()
    
});
async function subscribe_for_telephony_notification(){
  var eventFilters = [
    '/restapi/v1.0/account/~/telephony/sessions'
  ]
  subscription.setEventFilters(eventFilters)
  .register()
  .then(async function(subscriptionResponse) {
      console.log("Ready to receive Tel session events via PubNub.")
  })
  .catch(function(e) {
    console.error(e.message);
  })
}
subscription.on(subscription.events.notification, function(msg) {
    console.log(JSON.stringify(msg));
    console.log("======");
});
7 comments
1 |1500 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.

Thanks the auth works.

Now, I copied your code exactly - running the readAllSubscriptions returns a 404 error, and no activity is logged.

0 Likes 0 ·

I ran from my code and here I see 2 active subscriptions? Not suer what you are doing and why you got the error?

{
  uri: 'https://platform.devtest.ringcentral.com/restapi/v1.0/subscription/713dd679-a76e-446a-b178-bbf4cb6301c3',
  id: '713dd679-a76e-446a-b178-bbf4cb6301c3',
  creationTime: '2021-11-17T23:29:55.417Z',
  status: 'Active',
  eventFilters: [ '/restapi/v1.0/account/307128xxx/telephony/sessions' ],
  expirationTime: '2021-11-17T23:44:55.417Z',
  expiresIn: 198,
  deliveryMode: {
    transportType: 'PubNub',
    encryption: false,
    address: '4264014597516063_c012c842',
    subscriberKey: 'sub-c-b8b9cd8c-e906-11e2-b383-02ee2ddab7fe'
  }
}
{
  uri: 'https://platform.devtest.ringcentral.com/restapi/v1.0/subscription/7255b59b-8cf9-4f76-9930-a0091c4ca607',
  id: '7255b59b-8cf9-4f76-9930-a0091c4ca607',
  creationTime: '2021-11-17T23:41:23.983Z',
  status: 'Active',
  eventFilters: [ '/restapi/v1.0/account/307128xxx/telephony/sessions' ],
  expirationTime: '2021-11-17T23:56:23.983Z',
  expiresIn: 887,
  deliveryMode: {
    transportType: 'PubNub',
    encryption: false,
    address: '4264025658548312_03a2c71a',
    subscriberKey: 'sub-c-b8b9cd8c-e906-11e2-b383-02ee2ddab7fe'
  }
}
0 Likes 0 ·

i'm using your code exactly, shows 404 Not Found when trying to list active subscriptions.


code:

function readAllSubscriptions() {
    platform.get('/subscription')
        .then(function (response) {
            var json = response.json()
            if (json.records.length > 0) {
                for (var record of json.records) {
                    console.log(record)
                }
            } else {
                console.log("No subscription")
            }
        })
        .catch(function (e) {
            console.log(e.message)
        });
}


calling this right after a successful login:


platform.login({
    username: '****', 
    extension: '**', 
    password: '***'
}).then(()=>{
    readAllSubscriptions(
})
0 Likes 0 ·
Show more comments
Phong Vu avatar image
Phong Vu answered Manager Desk commented

Here are the events

{"uuid":"8358091234666434757","event":"/restapi/v1.0/account/307128004/telephony/sessions","timestamp":"2021-11-18T18:24:01.439Z","subscriptionId":"b948c2ad-65f5-408b-a5a4-ebff3ddedb89","ownerId":"307128004","body":{"sequence":2,"sessionId":"13964140005","telephonySessionId":"s-35d3846eadf9471e8dd8edc3b23014c6","serverId":"10.29.20.87.TAM","eventTime":"2021-11-18T18:24:01.119Z","parties":[{"accountId":"307128004","id":"p-35d3846eadf9471e8dd8edc3b23014c6-1","direction":"Outbound","to":{"phoneNumber":"+1470615xxxx"},"from":{"phoneNumber":"+1210306xxxx"},"status":{"code":"Setup","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
======
{"uuid":"6932542151911887543","event":"/restapi/v1.0/account/307128004/telephony/sessions","timestamp":"2021-11-18T18:24:01.447Z","subscriptionId":"b948c2ad-65f5-408b-a5a4-ebff3ddedb89","ownerId":"307128004","body":{"sequence":3,"sessionId":"13964140005","telephonySessionId":"s-35d3846eadf9471e8dd8edc3b23014c6","serverId":"10.29.20.87.TAM","eventTime":"2021-11-18T18:24:01.146Z","parties":[{"accountId":"307128004","id":"p-35d3846eadf9471e8dd8edc3b23014c6-2","direction":"Inbound","to":{"phoneNumber":"+1470615xxxx","name":"Manager Desk","extensionId":"307128004"},"from":{"phoneNumber":"+1210306xxxx"},"status":{"code":"Setup","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
======
{"uuid":"8858268169076275026","event":"/restapi/v1.0/account/307128004/telephony/sessions","timestamp":"2021-11-18T18:24:01.544Z","subscriptionId":"b948c2ad-65f5-408b-a5a4-ebff3ddedb89","ownerId":"307128004","body":{"sequence":4,"sessionId":"13964140005","telephonySessionId":"s-35d3846eadf9471e8dd8edc3b23014c6","serverId":"10.29.20.87.TAM","eventTime":"2021-11-18T18:24:01.444Z","parties":[{"accountId":"307128004","id":"p-35d3846eadf9471e8dd8edc3b23014c6-1","direction":"Outbound","to":{"phoneNumber":"+1470615xxxx","name":"Manager Desk","extensionId":"307128004"},"from":{"phoneNumber":"+1210306xxxx"},"status":{"code":"Answered","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
======
{"uuid":"4294381325951201884","event":"/restapi/v1.0/account/307128004/telephony/sessions","timestamp":"2021-11-18T18:24:04.960Z","subscriptionId":"b948c2ad-65f5-408b-a5a4-ebff3ddedb89","ownerId":"307128004","body":{"sequence":6,"sessionId":"13964140005","telephonySessionId":"s-35d3846eadf9471e8dd8edc3b23014c6","serverId":"10.29.20.87.TAM","eventTime":"2021-11-18T18:24:04.837Z","parties":[{"accountId":"307128004","id":"p-35d3846eadf9471e8dd8edc3b23014c6-2","direction":"Inbound","to":{"phoneNumber":"+1470615xxxx","name":"Manager Desk","extensionId":"307128004"},"from":{"phoneNumber":"+1210306xxxx"},"status":{"code":"Disconnected","reason":"CallerDropped","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
======
{"uuid":"4150499124955922640","event":"/restapi/v1.0/account/307128004/telephony/sessions","timestamp":"2021-11-18T18:24:04.951Z","subscriptionId":"b948c2ad-65f5-408b-a5a4-ebff3ddedb89","ownerId":"307128004","body":{"sequence":5,"sessionId":"13964140005","telephonySessionId":"s-35d3846eadf9471e8dd8edc3b23014c6","serverId":"10.29.20.87.TAM","eventTime":"2021-11-18T18:24:04.833Z","parties":[{"accountId":"307128004","id":"p-35d3846eadf9471e8dd8edc3b23014c6-1","direction":"Outbound","to":{"phoneNumber":"+1470615xxxx","name":"Manager Desk","extensionId":"307128004"},"from":{"phoneNumber":"+1210306xxxx"},"status":{"code":"Disconnected","rcc":false},"park":{},"missedCall":false,"standAlone":false,"muted":false}],"origin":{"type":"Call"}}}
1 comment
1 |1500 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.

I'm not sure what the issue is. Would you mind sending the entire code you have? I even tried a new clean slate server, with nothing but the code I posted above and still getting 404 with the new sdk.


Thanks for the effort.

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

Here is the entire code. Just add the app client secret and provide your username and password

const RingCentral = require('@ringcentral/sdk').SDK
const Subscriptions = require('@ringcentral/subscriptions').Subscriptions;

RINGCENTRAL_CLIENTID = '92pPUVd4S1GMn5H07641rg'
RINGCENTRAL_CLIENTSECRET = 'client-secret'
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'
RINGCENTRAL_USERNAME = '1470615xxxx'
RINGCENTRAL_PASSWORD = 'password'
RINGCENTRAL_EXTENSION = ''

const rcsdk = new RingCentral({
  server: RINGCENTRAL_SERVER,
  clientId: RINGCENTRAL_CLIENTID,
  clientSecret: RINGCENTRAL_CLIENTSECRET
})

var platform = rcsdk.platform();
platform.login({
        username: RINGCENTRAL_USERNAME,
        extension: RINGCENTRAL_EXTENSION,
        password: RINGCENTRAL_PASSWORD
      })

platform.on(platform.events.loginSuccess, async function(e){
    console.log("Login success")
    await subscribe_for_telephony_notification()
    // if checking subscription, comment the previous line and uncomment the next line. 
    //await readAllSubscriptions()
});

const subscriptions = new Subscriptions({
   sdk: rcsdk
});
var subscription = subscriptions.createSubscription();

async function subscribe_for_telephony_notification(){
  var eventFilters = [
    '/restapi/v1.0/account/~/telephony/sessions'
  ]
  subscription.setEventFilters(eventFilters)
  .register()
  .then(async function(subscriptionResponse) {
      console.log("Ready to receive Tel session events via PubNub.")
  })
  .catch(function(e) {
    console.error(e.message);
  })
}

async function deleteRegisteredSubscription(id) {
  try{
    var resp = await platform.delete('/restapi/v1.0/subscription/' + id)
    console.log(resp)
  }catch(e) {
      console.log(e.message)
  }
}

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)
          // uncomment the next line of need to delete a subscription
          await deleteRegisteredSubscription(record.id)
        }
      }
    }else{
      console.log("No subscription")
    }
  }catch(e) {
    console.log(e.message)
  }
}

subscription.on(subscription.events.notification, function(msg) {
    console.log(JSON.stringify(msg));
    console.log("======");
});
11 comments
1 |1500 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.

After digging in - the issue with reading the subscriptions was the end point that you provided in the beginning:

platform.get('/subscription')

In you're full code

/restapi/v1.0/subscription

So that's fixed, but we are back to the first issue - only one subscription is active, and i'm still not getting any notifications. Seems like the delete isn't removing something and it needs to wait to expire - if I wait for expiration it seems that the subscription does work.


Any insight on this?

0 Likes 0 ·

Hold on. There seems to be an issue with PubNub notification on sandbox env.

Stay tuned for updates after our investigation and fixes.

0 Likes 0 ·

I am using RingCentral.Net 5.9.0 in sandbox and am seeing intermittent issues with PubNub not sending notifications. I can auth and subscribe to "/restapi/v1.0/account/~/extension/~/presence?detailedTelephonyState=true" successfully each time (http response 200 status:active , transportTypePubNub etc)

but sometimes I receive call notifications, sometimes not. It's driving me crazy as I'm hunting for bugs / rate limit issues but there's no smoking gun.

I won't raise a new ticket just yet - but am following along to see if issues with PubNub are confirmed/resolved here first.

Regardless of node/.net implementation is there a way to sniff/monitor for pubnub traffic -wireshark or similar?

thankyou

0 Likes 0 ·
Show more comments
Show more comments

Eta on a fix?

0 Likes 0 ·

No ETA but I know that they are working on it.

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered Steve Cowley commented

The issue is fixed and PubNub notifications should work normal now. Please try again and report if you still face the problem.

2 comments
1 |1500 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.

Verified - works.

Much appreciated your time and effort.

0 Likes 0 ·

fantastic thanks Phong Vu!

0 Likes 0 ·

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