This is a migrated thread and some comments may be shown as answers.

how to list devices from a cloud function

6 Answers 83 Views
Push Notifications
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 05 Nov 2015, 07:35 PM

 From a cloud function, how can i get a list of all devices and send a specific push notifications to each one of them depending on their parameters?

1.  i know how to send push notifications filtering by device id
>> http://docs.telerik.com/platform/backend-services/javascript/push-notifications/push-send-cloud-code
i am OK here

2.  get a list of device and for each device create a push notification >>> i am not OK

http://docs.telerik.com/platform/backend-services/rest/push-notifications/push-initialization-and-registration#retrieving-a-device-list
>>> this is the only place where i can find information about listing devices (this is the rest api, not the cloud function documentation).

http://docs.telerik.com/platform/backend-services/rest/server-side-logic/cloud-code/cloud-code-make-http-requests
>>> will i have to make a rest call from cloud function (this is strange) ?
  

thank you

 

 

 

 

 

6 Answers, 1 is accepted

Sort by
0
Lyubomir Dokov
Telerik team
answered on 09 Nov 2015, 01:58 PM
Hi Michael,

In a cloud function, the best way to read devices registered for push notifications is by using the JS SDK. You could make a REST API call, but the SDK has convenient methods to make it easy for you. Note, that you must initialize the SDK with master key, as the devices are only available for reading with master authentication.

Here is how it's done:
Everlive.CloudFunction.onRequest(function(request, response, done){
     
    var el = Everlive.Sdk.withMasterKey(); //Convenient way to get SDK initialized with Master Key
     
    el.push.devices.get().then(
        function success(result) {
            response.result = result;
            done();
        },
        function error(err) {
            response.result = err;
            done();
        }
    );
});

Note, that the code above sets the retrieved devices to the result object so that you can easily test your cloud function. Normally you will just use the result to create a push notification.

The el.push.devices object works the same way as if you work with data e.g. is similar to el.data('myType'). You can read more information on working with data from the JS SDK here.

There is just one more thing I would like to note. The mechanism for targeting push notifications is very flexible. You can put a complex filter in the push notification itself. Instead of doing a filter on devices and then sending a notification by specifying the IDs of those devices, you can simply set the filter on the push notification. When we start sending it, we will filter the devices using the filter you specified and send only to devices that match.

I hope this helps, let me know if you have other questions.

Regards,
Lyubomir Dokov
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Michael
Top achievements
Rank 1
answered on 12 Nov 2015, 09:44 AM

Thanks for your answer.

 When i went into the documentation, i did this : backend services > api reference > javascript sdk > push

I just saw currentDevices. I didn't find push.devices (screenshot attached).

 Am i missing a point or is it missing in the documentation?

Thank you

0
Lyubomir Dokov
Telerik team
answered on 12 Nov 2015, 10:52 AM
Hi Michael,

You are right, this is missing from our documentation. Thank you for pointing it out, we will fix it.


Regards,
Lyubomir Dokov
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Michael
Top achievements
Rank 1
answered on 12 Nov 2015, 10:58 AM
Cool. Do i get Telerik points for this? ;-)
0
Accepted
Anton Dobrev
Telerik team
answered on 16 Nov 2015, 11:12 AM
Hi Mike,

Thanks for reporting this, I updated your Telerik Points.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Michael
Top achievements
Rank 1
answered on 16 Nov 2015, 01:16 PM
thanks a lot
Tags
Push Notifications
Asked by
Michael
Top achievements
Rank 1
Answers by
Lyubomir Dokov
Telerik team
Michael
Top achievements
Rank 1
Anton Dobrev
Telerik team
Share this question
or