Reputation: 101
I have been trying to update an old app that used parse.com. I have setup my own instance of parse server and directed the app to use the new instance. Everything works now in the app with the exception of the push notifications. I created a new firebase application and enabled FCM. I have placed the keys in myConfig.json which i reference when i start parse from the terminal. It looks like:
{
"appId": "idofapp",
"masterKey": "master,
"cloud": "/home/ubuntu/cloud/",
"databaseURI": "mongodb://localhost:27017/test-app",
"push": {
"android":{
"senderId": "99999999999",
"apiKey": "BigLongKeyGeneratedFromFirebase"
}
}
}
I have created a cloud/main.js which i reference in the config file. It looks like:
Parse.Cloud.define("SendPush", function(request) {
var msg = request.params.message;
var query = new Parse.Query(Parse.User);
var user = request.params.user;
query.equalTo("objectId", user);
Parse.Push.send({
where: query,
data:{
alert: {
"title" : msg,
"body" : msg
},
sound: 'default'
}
}, {
useMasterKey: true,
success: function(){
response.success("Push Sent!");
},
error: function(error){
response.error("Error while trying to send push " + error.message);
}
});
});
I enabled verbose logging since it wasn't giving me any information about why the push notifications were not being delivered. It prints out the following five times only changing the Status-Id.
verbose: REQUEST for [POST] /parse/functions/SendPush: {
"message": "You have a new message ",
"user": "bXYVlwltiN"
} method=POST, url=/parse/functions/SendPush, x-parse-session-token=r:6d11549cc2f2e7ffd64ba07a6d327e8d, x-parse-application-id=app, x-parse-client-version=a1.15.8, x-parse-app-build-version=1, x-parse-app-display-version=1.0, x-parse-os-version=8.0.0, user-agent=Parse Android SDK 1.15.8 (com.company.name/1) API Level 26, x-parse-installation-id=44123cf9-65fa-4871-8798-22eafa291711, content-type=application/json, content-length=57, host=ec2-19-198-39-191.us-west-2.compute.amazonaws.com:1337, connection=Keep-Alive, accept-encoding=gzip, message=You have a new message , user=bXYVlwltiN
verbose: REQUEST for [POST] /parse/push: {
"where": {
"objectId": "bXYVlwltiN"
},
"data": {
"alert": {
"title": "You have a new message ",
"body": "You have a new message "
},
"sound": "default"
}
} method=POST, url=/parse/push, user-agent=node-XMLHttpRequest, Parse/js1.11.1 (NodeJS 7.10.1), accept=*/*, content-type=text/plain, host=localhost:1337, content-length=269, connection=close, objectId=bXYVlwltiN, title=You have a new message , body=You have a new message , sound=default
verbose: RESPONSE from [POST] /parse/push: {
"headers": {
"X-Parse-Push-Status-Id": "ZOrTd4OylW"
},
"response": {
"result": true
}
} X-Parse-Push-Status-Id=ZOrTd4OylW, result=true
No notifications are delivered. Can you please tell me what I have missed?
I have changed the cloud function to the following and still get the same error:
Parse.Cloud.define("SendPush", function(request, response) {
var userId = request.params.user;
var message = "sening a test message"; //request.params.message;
var queryUser = new Parse.Query(Parse.User);
queryUser.equalTo('objectId', userId);
var query = new Parse.Query(Parse.Installation);
query.matchesQuery('user', queryUser);
Parse.Push.send({
where: query,
data: {
alert: message,
badge: 0,
sound: 'default'
}
}, {
success: function() {
console.log('##### PUSH OK');
response.success();
},
error: function(error) {
console.log('##### PUSH ERROR');
response.error('ERROR');
},
useMasterKey: true
});
});
Upvotes: 0
Views: 417
Reputation: 1769
From what I can see, response is undefined. It shows ils be the second argument of your sendPush cloud functions
Upvotes: 0