-
Notifications
You must be signed in to change notification settings - Fork 2
/
xm_group.txt
91 lines (69 loc) · 3.78 KB
/
xm_group.txt
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var got = require('got');
const request = require('request');
const util = require('util');
exports.handler = function(context, event, callback) {
// Get Settings
var settings = JSON.parse(decodeURI(event.setting));
console.log("EVENT: " + JSON.stringify(event));
console.log("Settings: " + JSON.stringify(settings));
console.log("EVENT DIGITS: " + event.Digits);
console.log("Settings xm_livecall: " + settings.xm_livecall);
let twiml = new Twilio.twiml.VoiceResponse();
// User selects 1 - Alert, 2 - Conference Bridge, 3 - Live Call
if (event.Digits === "1" || event.Digits === "2" || event.Digits === "3") {
if (event.Digits === "1") {
Message_Phrase = settings.Alert_Phrase;
what = 'Alert';
}
if (event.Digits === "2") {
Message_Phrase = settings.Conference_Phrase;
what = 'Conference';
}
if (event.Digits === "3") {
Message_Phrase = settings.Livecall_Phrase;
what = 'Livecall';
}
console.log("what: " + what);
console.log("event.Digits: " + event.Digits);
// Direct to livecall function
if (what === "Livecall") {
const gather = twiml.gather({
input: 'dtmf',
numDigits: 1,
action: settings.xm_livecall + '?setting=' + encodeURI(JSON.stringify(settings)) + '&Message_Phrase=' + encodeURI(Message_Phrase) + '&what=' + what + '&Digits=' + event.Digits
});
// repeats the message until a response is recieved
gather.say({ voice: 'alice', loop: 1}, Message_Phrase + settings.Group_Speak_Text);
twiml.pause({ length: 1 });
twiml.redirect(settings.xm_group + '?setting=' + encodeURI(JSON.stringify(settings)) + '&Message_Phrase=' + encodeURI(Message_Phrase) + '&what=' + what + '&Digits=' + event.Digits);
callback(null, twiml);
}
// Direct to group function
else {
const gather = twiml.gather({
input: 'dtmf',
numDigits: 1,
action: settings.xm_record + '?setting=' + encodeURI(JSON.stringify(settings)) + '&Message_Phrase=' + encodeURI(Message_Phrase) + '&what=' + what
});
// repeats the message until a response is recieved
gather.say({ voice: 'alice', loop: 1}, Message_Phrase + settings.Group_Speak_Text);
twiml.pause({ length: 1 });
twiml.redirect(settings.xm_group + '?setting=' + encodeURI(JSON.stringify(settings)) + '&Message_Phrase=' + encodeURI(Message_Phrase) + '&what=' + what + '&Digits=' + event.Digits);
callback(null, twiml);
}
}
// Incorrect Digits Repeat last step
else {
twiml.say({ voice: 'alice', loop: 1},'Invalid Digit. Listen carefully.');
console.log("PROBLEM");
const gather = twiml.gather({
input: 'dtmf',
numDigits: 1,
action: settings.xm_group + '?setting=' + encodeURI(JSON.stringify(settings))
});
gather.say({ voice: 'alice', loop: 1},'Press 1 to alert an x matters group. Press 2 to start an x matters conference bridge. Press 3 to speak live with the primary on call.');
twiml.pause({ length: 1 });
twiml.redirect(settings.xm_group + '?setting=' + encodeURI(JSON.stringify(settings)));
callback(null, twiml);
}
} // close handler