Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/tasks/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Task = require('./task');
const {TaskName} = require('../utils/constants');

class TaskAlert extends Task {
constructor(logger, opts, parentTask) {
super(logger, opts);
this.message = this.data.message;
}

get name() { return TaskName.Alert; }

async exec(cs) {
const {srf, accountSid:account_sid, callSid:target_sid, applicationSid:application_sid} = cs;
const {writeAlerts, AlertType} = srf.locals;
await super.exec(cs);
writeAlerts({
account_sid,
alert_type: AlertType.APPLICATION,
detail: `Application SID ${application_sid}`,
message: this.message,
target_sid
}).catch((err) => this.logger.info({err}, 'Error generating alert application'));
}

async kill(cs) {
super.kill(cs);
this.notifyTaskDone();
}
}

module.exports = TaskAlert;
3 changes: 3 additions & 0 deletions lib/tasks/make_task.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ function makeTask(logger, obj, parent) {
case TaskName.Tag:
const TaskTag = require('./tag');
return new TaskTag(logger, data, parent);
case TaskName.Alert:
const TaskAlert = require('./alert');
return new TaskAlert(logger, data, parent);
}

// should never reach
Expand Down
1 change: 1 addition & 0 deletions lib/utils/constants.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TaskName": {
"Alert": "alert",
"Answer": "answer",
"Conference": "conference",
"Config": "config",
Expand Down
Loading