Page 1 of 1

Problem with server code push

Posted: Thu Apr 13, 2017 2:48 pm
by Terry Gilliver

Have run into a problem with server code push notifications:

code
// Push Notifications API key from:
// Apps > [App] > Push Notifications > Settings
// 'badge' is iOS only setting

var pushApiKey = "0813456a-4b56-4386-97a1-b3daacf5c3ee&quot
var message = request.get("message");
var channel = request.get("channel");
console.log("message = ",message);
console.log("channel = ",channel);
Apperyio.PN.send(pushApiKey, {
payload: {
"message": message
},
filter: {
"channels": {
"$in": [channel]
}
}
});
/code

If I test this, the message is not sent, but there are no errors. The problem is somewhere in the syntax for the channels filter, if I remove the filter, then the message is sent. The Channel is set to 2 in the database for all devices. See the screenshot below:

Image

also i have found how to send a success response using Apperyio.reponse.success, but can you check the response status, and is there an Apperyio.reponse.error function?


Problem with server code push

Posted: Thu Apr 13, 2017 4:47 pm
by Terry Gilliver

figured it out, I defined the array containing the channel as a valriable 'ch' as follows:

code
// Push Notifications API key from:
// Apps > [App] > Push Notifications > Settings
// 'badge' is iOS only setting

var pushApiKey = "0813456a-4b56-4386-97a1-b3daacf5c3ee&quot
var body = JSON.parse(request.body());
var message = body.message;
var channel = body.channel;
console.log("body",body);
console.log("message = ",message);
console.log("channel = ",channel);
var ch = [channel];
Apperyio.PN.send(pushApiKey, {
payload: {
"message": message
},
filter: {
"channels": {
"$in": ch
}
}
});
Apperyio.response.success({"push":"success"}, "application/json");
/code

However, i would still like to know if I can check the status and return some diagnostic info if it fails


Problem with server code push

Posted: Thu Apr 13, 2017 10:28 pm
by Bruce Stuart

Terry,

The latter is (as an example of not returning success...)...

response.error('Error - retreiving Control Record: ' + e.message, 500);

The 500 is the code I'm returning - and - if you received an error that you 'caught' in a try{} catch(e) {
... You might put the code below.... like such
response.error('Error - retreiving Control Record: ' + e.message, 500);

}


Problem with server code push

Posted: Thu Apr 13, 2017 10:28 pm
by Bruce Stuart

I don't know about your other issue....


Problem with server code push

Posted: Fri Apr 14, 2017 12:25 pm
by Serhii Kulibaba

Hello,

It is impossible to check the response from APNS or Google Cloud Messages, because they accept all requests and have responses only after sending notifications to clients