Skip to content

Commit

Permalink
SNS: support 'callback' subject
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-lemon committed Jun 26, 2019
1 parent 501a35f commit 187b16c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions SNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ exports = module.exports = (function (_$) {
}

//! post to slack channel.
const do_post_slack = (pretext='', title='', text='', fields=[])=>{
const do_post_slack = (pretext='', title='', text='', fields=[], color='#FFB71B', username='hello-alarm')=>{
if (pretext && typeof pretext == 'object'){
const args = pretext||{};
pretext = args.pretext||'';
title = args.title||'';
text = args.text||'';
fields = args.fields||[];
title = args.title||title;
text = args.text||text;
fields = args.fields||fields;
color = args.color||color;
username = args.username||username;
}
// Set the request body
const now = new Date().getTime();

//! build attachment.
const attachment = {
"username" : "hello-alarm",
"color" : "#FFB71B",
"username" : username,
"color" : color,
"pretext" : pretext,
"title" : title,
"text" : text,
Expand Down Expand Up @@ -181,6 +183,15 @@ exports = module.exports = (function (_$) {
return do_post_slack('', 'error-report', text=asText(data), [])
}

//! chain for ALARM type. (see data/alarm.jsonc)
const chain_process_callback = ({subject, data, context}) => {
_log(`chain_process_callback(${subject})...`)
data = data || {};
_log('> data=', data);

return do_post_slack('', 'callback-report', text=asText(data), [], '#B71BFF')
}

//! chain for HTTP type.
const chain_process_http = ({subject, data, context}) => {
_log(`chain_process_http(${subject})...`)
Expand Down Expand Up @@ -242,6 +253,7 @@ exports = module.exports = (function (_$) {
: subject.startsWith('ALARM: ') ? chain_process_alarm
: subject.startsWith('DeliveryFailure event') ? chain_process_delivery_failure
: subject === 'error' ? chain_process_error
: subject === 'callback' ? chain_process_callback
: chain_process_http;

//! start chain processing.
Expand Down

0 comments on commit 187b16c

Please sign in to comment.