Python Push notification workflow rule example
From DreamFactory
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | This script uses a pre-configured push notification service to send notifications when new records are created. | ||
+ | |||
+ | '''''NOTE: DreamFactory Python scripting requires 'bunch' package to be installed on server. ''''' <code>sudo pip install bunch</code> | ||
+ | |||
<source lang="python"> | <source lang="python"> | ||
# POST /api/v2/db/_table/todo triggers script db._table.todo.post.post_process | # POST /api/v2/db/_table/todo triggers script db._table.todo.post.post_process | ||
# This script runs AFTER records are written to the db. | # This script runs AFTER records are written to the db. | ||
− | + | ||
− | + | payload = event.request.payload; | |
− | + | ||
− | + | if payload.resource != "": | |
− | payload = event | + | for record in payload.resource: |
− | + | msg = '{"Message":"A new Todo named '+record.name+' was just created!", "Subject":"New Todo Created"}'; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | if payload | + | |
− | for record in payload | + | |
− | msg = '{"Message":"A new Todo named '+record | + | |
− | + | ||
# service name is 'push', push to SNS topic by name | # service name is 'push', push to SNS topic by name | ||
− | + | result = platform.api.post('/push/topic/arn:aws:sns:us-east-1:xxxxxxx:new_todo', msg); | |
− | + | ||
− | + | ||
# output result to storage/logs/dreamfactory.log | # output result to storage/logs/dreamfactory.log | ||
− | print | + | print result.read(); |
</source> | </source> |
Latest revision as of 22:21, 15 July 2016
This script uses a pre-configured push notification service to send notifications when new records are created.
NOTE: DreamFactory Python scripting requires 'bunch' package to be installed on server. sudo pip install bunch
# 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; 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 result = platform.api.post('/push/topic/arn:aws:sns:us-east-1:xxxxxxx:new_todo', msg); # output result to storage/logs/dreamfactory.log print result.read();