Running in node.js .
Not picking up on any call action after successful subscription.
My Code:
- function setSubscription() {
- const platform = rcsdk.platform()
- platform.login({
- username: '+14706150273',
- extension: '101',
- password: '********'
- }).then(response => {
- const subscription = rcsdk.createSubscription().setEventFilters(['/account/~/telephony/sessions']);
- subscription.on(subscription.events.notification, function (msg) {
- console.log(msg);
- });
- subscription.register().then(function (response) {
- console.log(response.json());
- console.log('Success: Subscription is listening');
- }).catch(function (e) {
- console.log('Subscription Error: ' + e.message);
- });
- }).catch(e => {
- console.error(e)
- })
- }
Console output after run showing successfully subscribed (but nothing after) - Calls are showing in the sandbox call log:
- [nodemon] starting `node index.js`
- Server is running on port: 5000
- {
- uri: 'https://platform.devtest.ringcentral.com/restapi/v1.0/subscription/edde4bf6-1563-4263-94c7-247954e3ac68',
- id: 'edde4bf6-1563-4263-94c7-247954e3ac68',
- creationTime: '2021-11-16T22:52:03.946Z',
- status: 'Active',
- eventFilters: [ '/restapi/v1.0/account/307128004/telephony/sessions' ],
- expirationTime: '2021-11-16T23:07:03.946Z',
- expiresIn: 899,
- deliveryMode: {
- transportType: 'PubNub',
- encryption: false,
- address: '4174641560134678_4a93035d',
- subscriberKey: 'sub-c-b8b9cd8c-e906-11e2-b383-02ee2ddab7fe'
- }
- }
- Success: Subscription is listening
The issue is fixed and PubNub notifications should work normal now. Please try again and report if you still face the problem.
Verified - works.
Much appreciated your time and effort.
fantastic thanks Phong Vu!
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("======"); });
Eta on a fix?
No ETA but I know that they are working on it.
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?
Hold on. There seems to be an issue with PubNub notification on sandbox env.
Stay tuned for updates after our investigation and fixes.
Hi, is there a workaround we can use to get sandbox working whilst waiting for a fix?e.g. What's the timeout/expiry period on PubNub that we a waiting for, or should we avoid deleting subscriptions? In my dev/test cycle I am creating and deleting subscriptions each dev cycle. If I know the timeout, or the action that leaves an orphaned PubNub session open, perhaps I can work around it in the short term. If there was some other one-off method to reset the PubNub session in sandbox that too would work (can we communicate with PubNub directly using the subscription info to delete the session?) thanks
If you use a RingCentral SDK to create a PubNub subscription, the SDK will handle the renewal to keep the session alive. If you terminate our app or delete the SDK instance, PubNub subscription will be expired after 15 mins. If you run and terminate your test many times within a short period time. You can read and delete any pending PubNub subscription using this example code in Node JS.
async function deleteRegisteredSubscription(id) { try{ var resp = await platform.delete('/restapi/v1.0/subscription/' + i 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) await deleteRegisteredSubscription(record.id) } } }else{ console.log("No subscription") } }catch(e) { console.log(e.message) } }
Is this issue only in sandbox env? Prod working fine?
Yes, just affects sandbox env. Production works normally.
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
I am not aware of any way to sniff or monitor PubNub traffics. Internally the engineering team can. But even I don't have access to that.
So right now, there is some issues with the sandbox PN notification and the team is working on that.
An update on this would be great. We are in need to implement a new system and this is obviously causing an unwanted delay.
Alternatively, how can we use Prod env for development?
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"}}}
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.
const rcsdk = new SDK({ server: rcCred.RINGCENTRAL_SERVER, appKey: rcCred.RINGCENTRAL_CLIENTID, appSecret: rcCred.RINGCENTRAL_CLIENTSECRET, }); const platform = rcsdk.platform(); rcsdk.platform() .login({ username: rcCred.RINGCENTRAL_USERNAME, // phone number in full format extension: '', // leave blank if direct number is used password: rcCred.RINGCENTRAL_PASSWORD }) .then(async function (response) { const authData = platform.auth().data(); platform.auth().setData(authData console.log('logged in })
Using these exact credentials with the other SDK and it works (the auth)
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("======"); });
Thanks the auth works.
Now, I copied your code exactly - running the readAllSubscriptions returns a 404 error, and no activity is logged.
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' } }
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( })
You always write you do EXACTLY ... No you don't. You don't even pay attention to the code I posted there for you.
platform.login({ username: '...', extension: '', password: '...' }) platform.on(platform.events.loginSuccess, function(e){ console.log("Login success") subscribe_for_telephony_notification() // CALL IT FROM HERE });
I did that as well and the result is the same, simply tried another way to make sure. Here is my entire code, nothing else in the file, only redacted user info.
const RingCentral = require('@ringcentral/sdk').SDK const Subscriptions = require('@ringcentral/subscriptions').Subscriptions; const rcsdk = new RingCentral({ server: 'https://platform.devtest.ringcentral.com', clientId: '**', 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() readAllSubscriptions(); }); 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("======"); })
I don't know what happened in your code and env. I could run my code to create and list subscription w/o any problem. In fact, I leave it running now. Try to make inbound or outbound calls when you can to see if I can receive the notification events.
I just placed a test call - did you see any activity?
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) }); }
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?
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.
I've tried that as well, but can't get the user pass the Auth with that new SDK. Using same credentials.
You have to fix your code to pass the authentication.
Remember the param keys have been changed
var rcsdk = new SDK({ server: RINGCENTRAL_SERVER, clientId: RINGCENTRAL_CLIENTID, clientSecret: RINGCENTRAL_CLIENTSECRET });
I'm doing that exactly. Getting this error
response: Response { size: 0, timeout: 0, [Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null }, [Symbol(Response internals)]: { url: 'https://platform.devtest.ringcentral.com/restapi/oauth/token', status: 400, statusText: 'Bad Request', headers: [Headers], counter: 0 } }, request: Request { size: 0, timeout: 0, follow: 20, compress: true, counter: 0, agent: undefined, originalBody: 'grant_type=password&username=xxx&password=xxx&client_id=', [Symbol(Body internals)]: { body: <Buffer 67 72 61 6e 74 5f 74 79 70 65 3d 70 61 73 73 77 6f 72 64 26 75 73 65 72 6e 61 6d 65 3d 25 32 42 31 34 37 30 36 31 35 30 32 37 33 26 70 61 73 73 77 6f ... 24 more bytes>, disturbed: false, error: null }, [Symbol(Request internals)]: { method: 'POST', redirect: 'follow', headers: [Headers], parsedURL: [Url], signal: null } }, originalMessage: 'Response has unsuccessful status' }
Also, upon more testing, If I wait for the subscription to expire, then I run the code again it will work - Deleting the subscription doesn't seem to actually remove it, although it is not showing anymore in the subscription list after running the readAllSubscriptions function.
Show me the new code where you authenticate. Mask your username and password.
- const rcsdk = new SDK({
- server: rcCred.RINGCENTRAL_SERVER,
- appKey: rcCred.RINGCENTRAL_CLIENTID,
- appSecret: rcCred.RINGCENTRAL_CLIENTSECRET,
- });
- const platform = rcsdk.platform();
- rcsdk.platform()
- .login({
- username: rcCred.RINGCENTRAL_USERNAME, // phone number in full format
- extension: '', // leave blank if direct number is used
- password: rcCred.RINGCENTRAL_PASSWORD
- })
- .then(async function (response) {
- const authData = platform.auth().data();
- platform.auth().setData(authData
- console.log('logged in
- })
Using these exact credentials with the other SDK and it works (the auth)
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