Read SMS Message On Another Account

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I'm developing a periodic task that will track specific SMS conversations on Ring Central, parse replies, and perform some updates to our database. Is there a way to read SMS messages from multiple accounts from one logged in account (i.e. can I use administrator credentials to read messages for all of our employees?).
Photo of Tina Hoang-To

Tina Hoang-To

  • 92 Points 75 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,642 Points 5k badge 2x thumb
During a session where you have authenticated as a user with Administrative permissions for the account, you can currently only fetch the call-log data across all user extensions, but not the message-store (which is where the historical SMS data resides).

But that doesn't mean it cannot be done...

If you're using the JS SDK in Node.js, here is a way you could do that, let me know if this helps you workaround this inconvenience:


    var smsData;
    // Initialize the sdk
    var sdk= new RC({
        server: process.env.RC_API_BASE_URL,
        appKey: process.env.RC_APP_KEY,
        appSecret: process.env.RC_APP_SECRET
    });
    // Bootstrap Platform and Subscription
    var platform = sdk.platform();
    login();
    // Login to the RingCentral Platform
    function login() {
        return platform.login({
                username: process.env.RC_USERNAME,
                password: process.env.RC_PASSWORD,
                extension: process.env.RC_EXTENSION
            })  
            .then(init)
            .catch(function(e){
                console.log("Login Error into the RingCentral Platform :", e); 
                throw e;
            }); 
    }   
    /*  
        Obtain list of extensions after Login success
     */
    function init(loginData) {
        var extensions = []; 
        var page = 1;
        function getExtensionsPage() {
            return platform
                .get('/account/~/extensions', {
                    page: page,
                    perPage: process.env.DEVICES_PER_PAGE                                             //REDUCE NUMBER TO SPEED BOOTSTRAPPING
                })  
                .then(function(response) {
                    var data = response.json();
                    extensions = extensions.concat(data.records);
                    if (data.navigation.nextPage) {
                        page++;
                        return getExtensionsPage();                                                     // this will be chained
                    } else {
                        return extensions;                                                              // this is the finally resolved thing
                    }
                })
                .then(getAllExtensionSMS);
        }
        /*
                Loop until you capture all extensions
         */
        return getExtensionsPage()
            .then(function(extensinos) {
                return extensions;
            })
            .catch(function(e) {
                console.error("Error: getDevicesPage(): " + e);
                throw e;
             });
}
                                    
// Iterate to grab each extension's message-store?messageType=SMS
function getAllExtensionSMS(extensions) {
    return Promise.all(extensions.map(function(ext) {
        return platform
            .get('/account/~/extension/' + ext.id + '/message-store?messageType=SMS')
            .then(function(extensionSmsData) {
                smsData.concat(extensionSmsData.records);
            })
            .catch(function(e) {
                console.error(e);
                throw e;
            });
    })).catch(function(e) {
        console.error('Error with one of the promises to get SMS data', e);
        throw e;
    });
}
Photo of Tina Hoang-To

Tina Hoang-To

  • 92 Points 75 badge 2x thumb
We're currently using the Python client, I tried to implement the equivalent of the script above, but it appears that '/account/~/extensions' is not a supported endpoint (I'm getting  an Invalid URI error). Does this mean this functionality is only supported for Node clients?
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,642 Points 5k badge 2x thumb
No, this is an API route (and our API is a modern, RESTful interface).

Here is the Extension resource on our API explorer: https://developers.ringcentral.com/api-explorer/latest/index.html#/!/Extension/listExtensions

Additionally, you could use the RingCentral Python SDK available on Githubhttps://github.com/ringcentral/ringcentral-python You would need to re-write the code above in Python, but it should provide you with a little more direction on how to solve your use case.
Photo of Tina Hoang-To

Tina Hoang-To

  • 92 Points 75 badge 2x thumb
The URL is spelled wrong in your example (it says '/account/~/extensions' instead of '../extension'). That makes sense, thanks for the quick reply. It appears that our app does not have sufficient permissions to access that endpoint anyways so we'll go with our own workaround.
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,642 Points 5k badge 2x thumb
My bad, fat-finger error.

You should be able to go into your Sandbox account's online portal: https://service.devtest.ringcentral.com as an admin and enable SMS for an extension (the extension will also need to be enabled and activated).

If you can send SMS from the softphone in sandbox mode for the user you're testing with via the API, then it should work (and there could be something else going on).

Let me know what you find out.