Subscribing to presence events of multiple extensions using RCSDK

  • 4
  • Article
  • Updated 3 years ago
  • (Edited)
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
    http://ringcentral.github.io/api-explorer/#!/Authentication/oauth_token_post

  2. GET the list of all extensions within the account: 
    http://ringcentral.github.io/api-explorer/#!/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": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/<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 http://ringcentral.github.io/api-explorer/#!/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": "https://platform.devtest.ringcentral.com/restapi/v1.0/subscription/<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(subscription.events.notification, 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.
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,642 Points 5k badge 2x thumb

Posted 3 years ago

  • 4
Photo of Cameron

Cameron

  • 90 Points 75 badge 2x thumb
Can't you use a tilda in place of extension in the eventFilter rather than explicitly specifying each extension?
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,642 Points 5k badge 2x thumb
No, because the tilda is only going to equal the currently logged in user, not necessarily the entire explicit list of multiple extensions.
Photo of Cameron

Cameron

  • 90 Points 75 badge 2x thumb
Ah, I see. Thanks for the fast response.