I'm working on a project and I decided to use cloud code to send these user to user push notifications. So here's what I want to do:
When a new row is created/saved then take the content from the 'toUser' column which is a Pointer<_User>
and then once I've got the content from the 'toUser' column I'd like to send a push notification to that username, and the usernames are available under 'username' as a string in the '_User' class.
This is the code I've tried to use:
Parse.Cloud.afterSave("CustomMessage", function(request, response) {
var toUser = request.object.get('toUser');
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('toUser', toUser);
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {
alert: "You've got a new message from " + toUser
}
}, {
success: function() {
// Push was successful
response.success();
},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
response.error();
}
});
});
For some reason, this code isn't working for me. It sends a push notification onto parse and it reads like this:
Could somebody please show me how to do this?
I appreciate any help,
armanb21