Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Mattieuga
Last active December 13, 2015 22:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattieuga/4983322 to your computer and use it in GitHub Desktop.
Save Mattieuga/4983322 to your computer and use it in GitHub Desktop.
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).
// 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