Created
April 19, 2017 14:33
-
-
Save sunnygleason/b50be0e7d5d89788fb99c6b6e9858688 to your computer and use it in GitHub Desktop.
Advanced BLOCKS Techniques - Channel Encryption & Meta Attributes BLOCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (request) => { | |
// NOTE: message metadata attributes are stored in `request.params.meta` | |
// NOTE: overall metadata attributes are stored in `request.meta` | |
// NOTE: message metadata attributes are a JSON string, read-write, but must be parsed/stringified to change | |
// NOTE: overall metadata attributes are read-only | |
if (request && request.params && request.params.meta) { | |
let attrs = JSON.parse(request.params.meta); | |
// to show attrs or request, uncomment: | |
// console.log(attrs); | |
// console.log(request); | |
// | |
// take action based on meta attrs | |
// | |
if (attrs['severity'] == 'high') { | |
// see https://www.pubnub.com/blocks-catalog/pagerduty-incident-management-and-realtime-alerts/ | |
console.log("HIGH - create incident via XHR/HTTPS Ops API"); | |
} else if (attrs['severity'] == 'medium') { | |
// see https://www.pubnub.com/blocks-catalog/offline-notifier-block/ | |
// or https://www.pubnub.com/blocks-catalog/clicksend-sms/ | |
console.log("MEDIUM - send message via XHR/SMS gateway"); | |
} else if (attrs['severity'] == 'low') { | |
// see https://www.pubnub.com/blocks-catalog/sendgrid/ | |
console.log("LOW - send message via XHR/EMAIL gateway"); | |
} | |
} | |
// NOTE - pass on message unchanged (must when | |
// cipherKey encryption is used by clients) | |
return request.ok(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment