Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created April 19, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnygleason/b50be0e7d5d89788fb99c6b6e9858688 to your computer and use it in GitHub Desktop.
Save sunnygleason/b50be0e7d5d89788fb99c6b6e9858688 to your computer and use it in GitHub Desktop.
Advanced BLOCKS Techniques - Channel Encryption & Meta Attributes BLOCK
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