0

I'm attempting to send a push notification to a specific user's installation.

In the user class I have a column which is a pointer to an installation instance. Here's my code:

Parse.Cloud.beforeSave("Notification", function(request, response) {
    var user;

    if (!request.object.get("reciever")) {
        response.error("Please include a user");
    } else {
        user = request.object.get("reciever");
    }

        var message = request.object.get("message");

        var query = new Parse.Query(Parse.User);
        query.include("installation");
        query.equalTo("objectID", user.get("objectID"));
        query.find({
                success: function(result) {
                        var obj = result[0];
                var intst = obj.get("installation");
                    console.log(intst);

                        Parse.Push.send({
                          where: intst,
                          data: {
                            alert: message
                          }
                        }, {
                          success: function() {
                            console.log("Push was successful");
                                response.success();
                          },
                          error: function(error) {
                            console.error(error);
                        response.error(error);
                          }
                        });
                },
                error: function(error) {
                response.error(error);
                }
        });
});

From looking at my logs, the installation instance was received correctly. When sending, I get the following error:

Failed to create new object, with error code: {"code":115,"message":"Missing the push channels."}

What am I doing wrong?

Dan
  • 345
  • 2
  • 17

1 Answers1

0

The Parse documentation specifys this as an example for sending Push notificatons using Javascript

Parse.Push.send({  
    channels: [ "Giants", "Mets" ],  
    data: {    alert: "The Giants won against the Mets 2-3."  }
}, {
    success: function() {    
        // Push was successful  
    },  error: function(error) { 
       // Handle error  
    }
});

What you are missing is the 'channels: ["Giants", "Mets"]' section of this push notifcation. If you go into your installation table in parse you will notice there is a Channels column and this is what defines who the pushes get sent to. In this example the push will go to anyone who has signed up for the channels 'Giants' and 'Mets'.

JayDev
  • 1,340
  • 2
  • 13
  • 21