benjamin-dean avatar image
benjamin-dean posted cameron736 commented

Subscribing to presence events of multiple extensions using RCSDK

This article describes the basic process of how to subscribe to the presence events of multiple extensions within a single account using the RingCentral API.

A couple of example use cases for this are:
  • Call Center Administrative Dashboard (beta)
  • Logging of caller id(s) into a CRM or other authoritative database
You will need the following prerequisites to continue with this article:
Once you have the prerequisites ready...
  1. Authenticate as the Admin user using the API Explorer, with these scopes: ReadAccounts, ReadPresence, ReadCallLog!/Authentication/oauth_token_post

  2. GET the list of all extensions within the account:!/Account_and_Extension_Information/v1_0_account__account...

    This will return a JSON response which contains a property named "records" which is an array. Each child node of that array is an extension object from RingCentral.

    Here is an example extension object:L

    {       "uri": "<ACCOUNT_ID>/extension/<EXTENSION_ID>";,       "id": <EXTENSION_ID>,       "extensionNumber": "102",       "contact": {         "firstName": "Dummy",         "lastName": "User",         "email": "<USER_EMAIL>"       },       "name": "Dummy User",       "type": "User",       "status": "Activated",       "permissions": {         "admin": {           "enabled": false         },         "internationalCalling": {           "enabled": true         }       },       "profileImage": {         "uri": "<PROFILE_IMAGE_URI>;       }     }

  3. Using the record of extensions from the response in Step #2, populate the array property named "eventFilters" for the POST body request to!/Notifications/v1_0_subscription_post.

    You'll want to add a new array child node for each extension. If we had three extension records returned: 101 (, 102, 103 (each with a unique ID), we would want to include a new array item as follows:

    {   "eventFilters": [      "/restapi/v1.0/account/~/extension/<101_ID>/presence",     "/restapi/v1.0/account/~/extension/<102_ID>/presence",     "/restapi/v1.0/account/~/extension/<103_ID>/presence",      "/restapi/v1.0/account/~/extension/~/message-store"    ],    "deliveryMode": {      "transportType": "PubNub",      "encryption": "false"    }  }

  4. We'll use the response data we receive from defining this new subscription to establish a new PubNub channel. Here is an example of the response from /restapi/v1.0/subscription:
    {   "id": "<SUBSCRIPTION_ID>",   "creationTime": "2015-10-02T00:03:38.816Z",   "status": "Active",   "uri": "<SUBSCRIPTION_ID>;,   "eventFilters": [     "/restapi/v1.0/account/<ACCOUNT_ID>/extension/<EXTENSION_ID>/presence",     "/restapi/v1.0/account/<ACCOUNT_ID>/extension/<EXTENSION_ID>/message-store"   ],   "expirationTime": "2015-10-02T00:18:38.816Z",   "expiresIn": 899,   "deliveryMode": {     "transportType": "PubNub",     "encryption": true,     "address": "<ADDRESS>",     "subscriberKey": "<SUBSCRIBER_KEY>",     "encryptionAlgorithm": "<ALGORITHM>",     "encryptionKey": "<PUBNUB_ENCRYPTION_KEY>"   } }

  5. In your application, check that your RingCentral authentication is valid:
    platform.isAuthorized().then(function(){ ... }).catch(function(e){ ... }); 

  6. Inside the success handler above, you'll want to get your subscriptions, and then register your listener.

    // Gets the subscription, you could also use the  var subscription = rcsdk.getSubscription();  // Configure the listner for new events subscription.on(, function(msg) {     console.log(msg, msg.body);  // Register the listener subscription.register(); });

  7. Now you'll want to login to the RingCental app as one of your extensions (which is NOT your Admin user).

  8. After you're authenticated into RingCentral, use your cellular phone (or from any other line/extension) and call-in to the authenticated RC extension's number to generate an update to your extension's presence.

  9. Since you have subscribed to your own channel in PubNub, your app should begin receiving data from RingCentral's Subscription you created above which contains the presence information for all of your extensions. This will allow your app to receive updates the state of your RingCentral extensions in your account.
1 |1000

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

cameron736 avatar image cameron736 commented ·
Can't you use a tilda in place of extension in the eventFilter rather than explicitly specifying each extension?
0 Likes 0 ·
benjamin-dean avatar image benjamin-dean commented ·
No, because the tilda is only going to equal the currently logged in user, not necessarily the entire explicit list of multiple extensions.
0 Likes 0 ·
cameron736 avatar image cameron736 benjamin-dean commented ·
Ah, I see. Thanks for the fast response.
1 Like 1 ·



benjamin-dean contributed to this article