PHP Push notification workflow rule example

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPHP Push notification workflow rule example
(Created page with "This script uses a pre-configured push notification service to send notifications when new records are created. <pre> // POST /api/v2/db/_table/todo triggers script db._table...")
 
Line 5: Line 5:
 
// This script runs AFTER records are written to the db.
 
// This script runs AFTER records are written to the db.
  
$payload = \Request::json()->all();
+
$payload = $event['request']['payload'];
 +
$api = $platform['api'];
 +
$post = $api->post;
  
DreamFactory\Core\Utility\ServiceHandler::handleRequest(
+
if(isset($payload['resource']) && !empty($payload['resource'])){
        'POST',
+
    foreach($payload['resource'] as $record){
        'push',
+
         $msg = [
        'topic/arn:aws:sns:us-east-1:xxxxxx:new_todo',
+
                'Message' => 'A new Todo named '.$record['name'].' was just created!',
        [],
+
                'Subject' => 'New Todo Created'
         [
+
            ];
            "Message" => "A new Todo named ".$payload['name']." was just created.",
+
       
            "Subject" => "New Todo Created",
+
        // service name is 'push', push to SNS topic by name
         ]
+
         $result = $post('push/topic/arn:aws:sns:us-east-1:662443008147:new_todo', $msg);
    );
+
 
 +
        // output result to storage/logs/dreamfactory.log
 +
        print_r($result);
 +
    }
 +
}
 
</pre >
 
</pre >

Revision as of 21:16, 23 February 2016

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

// POST /api/v2/db/_table/todo triggers script db._table.todo.post.post_process
// This script runs AFTER records are written to the db.

$payload = $event['request']['payload'];
$api = $platform['api'];
$post = $api->post;

if(isset($payload['resource']) && !empty($payload['resource'])){
    foreach($payload['resource'] as $record){
        $msg = [
                'Message' => 'A new Todo named '.$record['name'].' was just created!',
                'Subject' => 'New Todo Created'
            ];
        
        // service name is 'push', push to SNS topic by name
        $result = $post('push/topic/arn:aws:sns:us-east-1:662443008147:new_todo', $msg);

        // output result to storage/logs/dreamfactory.log
        print_r($result);
    }
}