Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Sample of using Parse with the SendGrid Cloud Module. This example will send an email when other users comment on a picture in Anypic (https://parse.com/anypic).

View parse+sendgrid.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// Require the SendGrid Cloud Module
var sendgrid = require("sendgrid");
sendgrid.initialize("you@parse.com", "your_password");
 
// Run this Cloud Function every time a new Activity (such as a comment)
// is saved
Parse.Cloud.afterSave("Activity", function(request, response) {
// Check if the activity type is a comment
var activity = request.object;
if (activity.get("type") === "comment") {
 
// Get the owner of the photo commented on
var targetUser = activity.get("toUser");
targetUser.fetch({
success: function(targetUser) {
 
// Send an email if we have the user's email
if (targetUser.get("email") && targetUser.get("email").length > 0) {
sendgrid.sendEmail({
to: targetUser.get("email"),
from: "anypic@parse.com",
subject: request.user.get("displayName") + " commented on your picture!",
text: "Check it out at anypic.org!"
}, {
success: function() {},
error: function() {}
});
}
},
error: function() {}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.