Python Push notification workflow rule example

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPython Push notification workflow rule example
# POST /api/v2/db/_table/todo triggers script
# This script runs AFTER records are written to the db.

import httplib;

payload = event['request']['payload'];
host = event['request']['headers']['host'][0];
headers = {
connection = httplib.HTTPConnection(host);

if payload['resource'] != "":
    for record in payload['resource']:
        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
        connection.request('POST', '/api/v2/push/topic/arn:aws:sns:us-east-1:xxxxxxxxxx:new_todo', msg, headers);
        response = connection.getresponse();
        # output result to storage/logs/dreamfactory.log