I am currently using the Urban Airship service to send Push Messages and looking at moving to Parse.com.
In Android, one can supply a set of data using key value pairs which can be accessed once the message is tapped.
Using Parse, is it possible to include this custom payload when sending to iOS and Android?
Thanks
Yes this is possible. Here's an example of a Parse push with arguments, in CloudCode.
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {
alert: "Notification message",
keyOne: "First value",
keyTwo: "Another value"
}
},{
success: function() {
// Push was successful
},
error: function(error) {
throw "Got an error " + error.code + " : " + error.message;
}
});
Then you can access the data on the device receiving the Push.
Related
I was trying to send sms without opening sms app. I have tried expo sms but no luck. I have also tried few other packages but still nothing...is there a way?
Looks like this library is working fine and reached the goals to send a message without going into the default message environment.
var phoneNumbers = {
"addressList": ["+911212121212", "+911212121212"]
};
var message = "This is automated test message"
SmsAndroid.autoSend(
phoneNumbers,
message,
(fail) => {
console.log('Failed with this error: ' + fail);
},
(success) => {
console.log('SMS sent successfully');
},
);
You can use this module npm install react-native-sms --save && react-native link react-native-sms
Next step add some code:
import SendSMS from 'react-native-sms'
someFunction() {
SendSMS.send({
body: 'The default body of the SMS!',
recipients: ['0123456789', '9876543210'],
successTypes: ['sent', 'queued'],
allowAndroidSendWithoutReadPermission: true
}, (completed, cancelled, error) => {
console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);
});
}
I'm running parse-server on ubuntu and can't seem to get push notifications working when sent in cloud code.
Push's work when using a REST api call (passing master key) but don't work when cloud code calls them.
What's interesting is that the cloud code Parse.Push() method returns a success and thus no error message.
My hypothesis is that this is a configuration problem, and the Parse.Push() method is referencing somethign I have incorrectly configured on the server.
here is my cloud function. This call works when sent via REST. and the success callback in cloud is always called.
Parse.Push.send(
{
// where: pushQueryClient,
channels: ["user_tkP7gurGzc"],
data:
{
alert: pushTextClient
}
},
{
success:function(){
console.log("push sent");
},
error: function(error){
console.log("push failed");
console.dir(error);
},
useMasterKey: true});
i think you have an issue with the useMasterKey parameter.
Please try to use this code in order to send the push notification:
Parse.Push.send({
where: whereQuery,
data: {
alert: {
title: request.params.title,
body: request.params.body
},
type: request.params.type,
sound: 'default'
}
}, {
useMasterKey: true
}).then(function() {
response.success();
}, function(error) {
response.error("Push failed " + error);
});
In this code i use Promises which is the best practice and also wrap useMasterKey in a separate object
I am trying to run a parse cloud code function that sends a push to a user that is associated with an installation object. When I run the following code from within the cloud function I get Error 115 - Client-initiated push isn't enabled.
// SEND PUSH TO PARENT
var query = new Parse.Query(Parse.Installation);
query.equalTo('user', reservation.get("parent"));
Parse.Push.send({
where: query, // Set our Installation query
data: {
alert: "Your request has been accepted!"
}
}, {
success: function () {
console.log("push worked");
return result;
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
return result;
}
});
I don't see anywhere that client side pushes need to be enabled for cloud code? Am I missing something or do I need it enabled?
Navigate to your app's settings in the Parse Dashboard, then enable client side push under Push Notifications.
I am using Parse.com to send push notifications via Cloud Code. These notifications are "send to sync" so I want them to be collapsible. Collapsible means that if a device is turned off or otherwise not receiving push notifications, that these notifications should not build up. When my phone turns on, I don't need a bunch of undelivered pushes showing up telling me to sync. All I need is one. I see no way to do this in Cloud Code. Is there a way to make your push notifications collapsible? Here is my CloudCode.
Parse.Cloud.afterSave("Tagnames", function (request) {
//Get the Customer that is pointed to in the AlarmDefinitions object.
query = new Parse.Query("Customers");
query.get(request.object.get("customer").id, {
success : function (cust) {
//We have the customer pointed to by the AlarmDefinition.
//Create the json payload data we will send to our clients.
console.log("Customer=" + cust.get("customer"));
console.log("action:" + "com.jrb.scadaalarm.rcvr.UPDATE_TAGNAMES");
//send the push so that all customers can get notified.
Parse.Push.send({
channels : [cust.get("customer")],
data: {
action: "com.jrb.scadaalarm.rcvr.UPDATE_TAGNAMES"
}
}, {
success : function () {
// Push was successful
console.log("Push successful.");
},
error : function (error) {
// Handle error
console.error("Push failed: " + error.code + " : " + error.message);
}
});
//
},
error : function (error) {
console.error("Got an error " + error.code + " : " + error.message);
}
});
});
Unfortunately, it doesn't look like Parse supports stackable notifications. Take a look at this answer here, from the Parse archives.
https://parse.com/questions/android-stack-push-notifications
Hey I'm using Parse as my backend and I love it but I have a problem with the afterSave hook.
Here is the Code I'm using:
Parse.Cloud.afterSave ("JGZwoelf",function (request) {
Parse.Push.send({
//Selecting the Channel
channels: [ request.object.get('JGZwoelfPush') ],
data: {
//Selecting the Key inside the Class
alert: request.object.get('AusfallInfo')
}
}, {
success: function () {
//Push was send successfully
},
error: function (error) {
//Handle error
throw "Got an error" + error.code + " : " + error.message;
}
});
});
Every time the logs console is telling me: Result:
Uncaught Got an error112 : Missing channel name.
I just don't understand what is wrong! It must be in that JavaScript code. If I enter the push notification manually everything works fine :/
Edit:
The part Parse.Push.send should look like this:
Parse.Push.send ({
//Selecting the already existing Push Channel
channels: ["JGAchtPush"], //This has to be the name of your push channel!!
data: {
//Selecting the Key inside the Class
alert: request.object.get ("AusfallInfo")
}
}, {
success: function () {
//Push was sent successfully
//nothing was loged
},
error: function (error) {
throw "Got and error" + error.code + " : " + error.message;
}
});
The channel name needs to be something like ["exampleChannel"].
Thanks in advance for any given help :)
The first argument to afterSave should be a class name, not an objectId.
following is for new folks (like me), it is the exact same code in original question, plus a few more comments, plus the correction from accepted answer. purpose is to show example of what few pieces of code need changing for this to work in your parse cloud code. thank you Constantin Jacob and bklimt.
Parse.Cloud.afterSave ("UserVideoMessage",function (request) { // name of my parse class is "UserVideoMessage"
Parse.Push.send ({
//Selecting the already existing Push Channel
channels: ["admin"], //This has to be the name of your push channel!!
data: {
//Selecting the Key inside the Class, this will be the content of the push notification
alert: request.object.get ("from")
}
}, {
success: function () {
//Push was sent successfully
//nothing was loged
},
error: function (error) {
throw "Got and error" + error.code + " : " + error.message;
}
});
});