Skip to content

Commit

Permalink
feat(notify-witnesses): witness gets notified via 'DM'
Browse files Browse the repository at this point in the history
- witness gets notified via 'Slack DM' when tagged in an incident report

[Delivers #152107092]
  • Loading branch information
bmuthoga authored and O'Brian Kimokot committed Mar 27, 2018
1 parent 402dad3 commit d1d21c2
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 3,300 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node index.js
web: node index.js
40 changes: 39 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const actions = require('./modules/actions');

const dotenv = require('dotenv');

const moment = require('moment');

dotenv.load();

const slackEvents = createSlackEventAdapter(
Expand Down Expand Up @@ -245,13 +247,49 @@ slackMessages.action('confirm', (payload, respond) => {
witnesses: formatted_witnesses
})
.then((result) => {
let tagged_witnesses = result.data.data.witnesses;
tagged_witnesses.map(tagged_witness => {
sc.im.list().then(success => {
success.ims.map(im => {
if (im.user === tagged_witness.id) {
sc.chat.postMessage(
im.id, '', {
attachments: [
{
'color': '#36a64f',
'pretext': `<@${incidentReporter}> reported an incident and tagged you as a witness`,
'fields': [
{
'title': 'Subject',
'value': result.data.data.subject
},
{
'title': 'Location',
'value': `${result.data.data.Location.name}, ${result.data.data.Location.centre}, ${result.data.data.Location.country}`
},
{
'title': 'Date Occurred',
'value': moment(result.data.data.dateOccurred).format('DD MMMM, YYYY')
}
]
}
]
},
(/* err, res */) => {}
);
}
});
}).catch((/* error */) => {});
});

payload.incidentId = result.data.data.id;
actions.saveIncident(payload, respond);
})
.catch(() => {
return respond({
respond({
text: 'Something didn\'t quite work. Try again.'
});
confirmIncident(payload.user.id, payload.channel.id);
});

}).catch((/* error */) => {
Expand Down
16 changes: 0 additions & 16 deletions modules/bot.js

This file was deleted.

Loading

0 comments on commit d1d21c2

Please sign in to comment.