Node push notification

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsNode push notification

This script uses a pre-configured push notification service to send notifications when new records are created.

// To enable Node.js scripting, set the path to node in your DreamFactory .env file.
// This setting is commented out by default.
// DF_NODEJS_PATH=/usr/local/bin/node
// Use npm to install any dependencies. This script requires 'lodash' and 'request'.
// Your scripts can call console.log to dump info to the log file in storage/logs.
// POST /api/v2/db/_table/todo triggers script
// This script runs AFTER records are written to the db.
// records are in array event.request.payload.resource.
var lodash = require("lodash");
if (event.request.payload.resource) {
    lodash._.each(event.request.payload.resource, function( record ) {
        var msg = {
            "Message": {
                "default": "A new Todo named '" + + "' was just created!"
            "Subject": "New Todo Created - " +
'/push/topic/arn:aws:sns:us-east-1:662443008147:new_todo', msg, '', function(body, response){
            event.setResponse(JSON.parse(body), response.statusCode, 'application/json');