Description
We are using the Push Massaging through a Cloud Code.
Found Several examples online..
According to this part of the wiki, we need to add OneSignalPushAdapter (or any other adapter) to send push notifications successfully.
The OneSignalPushAdapter logs say It sent the push notifications to 1,5,9,15 devices, according to our specifications, but non of our devices just don't get any push message...
No Error, No Failure, nothing...
This is our server code:
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
//Mailgun - reset password
var SimpleMailgunAdapter = require('parse-server/lib/Adapters/Email/SimpleMailgunAdapter');
var simpleMailgunAdapter = new SimpleMailgunAdapter({
apiKey: process.env.MAILGUN_KEY,
domain: process.env.DOMAIN,
fromAddress: process.env.MAILGUN_FROM_ADDRESS
});
//Push Adapter
var OneSignalPushAdapter = require('parse-server/lib/Adapters/Push/OneSignalPushAdapter');
var oneSignalPushAdapter = new OneSignalPushAdapter({
oneSignalAppId:process.env.ONE_SIGNAL_APP_ID,
oneSignalApiKey:process.env.ONE_SIGNAL_REST_API_KEY
});
//Server Part
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
appName: 'Medidate',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337', // Don't forget to change to https if needed
publicServerURL: process.env.PUBLIC_SERVER_URL,
emailAdapter: simpleMailgunAdapter,
push: {
adapter: oneSignalPushAdapter
},
// push: pushConfig,
// push: {
// android: {
// senderId: process.env.GCM_SENDER_ID, // The Sender ID of GCM
// apiKey: process.env.GCM_API_KEY // The Server API Key of GCM
// }
// ,
// ios: {
// pdx: __dirname + '/ios_push/Medidate_prod_p12_new.p12', // the path and filename to the .p12 file you exported earlier.
// bundleId: process.env.IOS_PUSH_BUNDLEID, // The bundle identifier associated with your app
// production: true
// }
// }
// ,
// customPages: {
// invalidLink: process.env.SERVER_URL + 'invalid_link.html',
// verifyEmailSuccess: process.env.SERVER_URL + 'verify_email_success.html',
// choosePassword: process.env.SERVER_URL + 'views/choose_password',
// passwordResetSuccess: process.env.SERVER_URL + 'password_reset_success.html'
// }
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var app = express();
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a web site.');
});
var port = process.env.PORT || 1337;
app.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
As you can see, we have also tried a different approach, to use the regular push configurations (commented) but we can't figure out what should we do with this JAVA code(Android client side) part in many of the GCM tutorials online:
// Make a call to Instance API
InstanceID instanceID = InstanceID.getInstance(this);
String senderId = getResources().getString(R.string.gcm_defaultSenderId);
try {
// request token that will be used by the server to send push notifications
String token = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
Log.d(TAG, "GCM Registration Token: " + token);
// pass along this data
sendRegistrationToServer(token);
} catch (IOException e) {
e.printStackTrace();
}
We can't figure out how to use this token in our parse server...
In this alternative we get the notorious "MismatchSenderId" (we triple checked our server key and project id/sender id)
And we think it might be related to the JAVA code snippet above.
Are we missing any configuration in any of the Cloud Push alternatives?
Do we need to implement OneSignal SDK in our client side?
P.S
We don't get any errors in the Cloud Code push function part...
Thanks in advance.