forked from victorops/twilio-live-call-routing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smsVoIncident.js
40 lines (32 loc) · 1.15 KB
/
smsVoIncident.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const qs = require('qs');
const got = require('got');
const _ = require('lodash');
exports.handler = function(context, event, callback) {
const { ROUTING_KEY, VICTOROPS_TWILIO_SERVICE_API_KEY } = context;
console.log(`${ROUTING_KEY} ${VICTOROPS_TWILIO_SERVICE_API_KEY}`);
var got = require('got');
let twiml = new Twilio.twiml.MessagingResponse();
twiml.message({ to: event.From }, 'Incident Created');
var alert = {
monitoring_tool: 'Twilio',
message_type: 'critical',
entity_display_name: `${event.Body}`,
state_message: `From ${event.From} -- ${event.Body}`,
entity_id: `${event.From}`
};
console.log(alert);
got.post(`https://alert.victorops.com/integrations/generic/20131114/alert/${VICTOROPS_TWILIO_SERVICE_API_KEY}/${ROUTING_KEY}`, {
body: alert,
headers: {
'accept': 'application/json',
'Content-Type': 'application/json'
},
json: true
}).then(function(response) {
console.log(response.body);
callback(null, twiml);
}).catch(function(error) {
console.log(error);
callback(error);
});
};