-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-answer.js
99 lines (87 loc) · 3.37 KB
/
auto-answer.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
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
92
93
94
95
96
97
98
/********************************************************
*
* Macro Authors: William Mills
* Solutions Engineer
* wimills@cisco.com
*
* Taylor Hanson
* Solutions Engineer
* tahanson@cisco.com
* Cisco Systems
*
* Version: 1-0-0
* Released: 06/18/24
*
* This macro automatically hangups any existing calls,
* and answers a Meeting Invite/Add *IF* the inviter is
* listed in AUTOANSWER_NUMBERS
*
* Full Readme, source code and license details for this macro
* are available on Github:
* https://github.com/wxsd-sales/emergency-dial-macro
*
********************************************************/
import xapi from 'xapi';
/********************************************************
* Settings -
* The only Setting that must be configured in this macro is AUTOANSWER_NUMBERS.
* All other configuration changes are optional
********************************************************/
//AUTOANSWER_NUMBERS Should be an array of strings. Value can be found in the device's web view under Spark SharedAccount ID:
// https://X.X.X.X/web/configurations/status/Spark
const AUTOANSWER_NUMBERS = [''];
const ANSWER_MUTED = true;
const AUTOANSWER_DELAY_SECONDS = 0;
var autoanswerhandler;
function normaliseRemoteURI(number){
var regex = /^(sip:|h323:|spark:|h320:|webex:|locus:)/gi;
number = number.replace(regex, '');
//console.log('Normalised Remote URI to ' + number);
return number;
}
async function answerCall(callId){
let calls = await xapi.Status.Conference.Call.get()
for(let call of calls){
//console.log(call);
if(call.id !== callId){
console.log("Disconnecting from CallId:", call.id);
await xapi.Command.Call.Disconnect({ CallId: call.id });
} else {
console.log("Skipping disconnect for emergency meeting, CallId:", call.id);
}
}
xapi.command('Call Accept').then(async function(){
if(ANSWER_MUTED){
let value = await xapi.Status.Audio.Microphones.Mute.get()
console.log(`Mute:${value}`);
if(value === "Off"){
console.log("Muting microphones.");
xapi.Command.Audio.Microphones.Mute();
} else {
console.log("Muting microphones in 1 second.");
setTimeout(function(){xapi.Command.Audio.Microphones.Mute()}, 1000);
}
}
}).catch((error) =>{
console.error(error);
});
}
xapi.event.on('IncomingCallIndication', async function (event){
console.log(event);
if(AUTOANSWER_NUMBERS.includes(normaliseRemoteURI(event.RemoteURI))){
xapi.command("UserInterface Message Alert Display", {Title: 'Incoming Autoanswer-number', Text: 'This call will automatically be answered after ' + AUTOANSWER_DELAY_SECONDS + ' seconds', Duration: AUTOANSWER_DELAY_SECONDS});
autoanswerhandler = setTimeout(async function(){ await answerCall(event.CallId) }, AUTOANSWER_DELAY_SECONDS * 1000);
}
});
xapi.status.on('Call Status', (status) => {
if(status === 'Connected'){
clearTimeout(autoanswerhandler);
//console.log('Call was accepted before auto-answer was performed');
xapi.command("UserInterface Message Alert Clear");
}
});
xapi.event.on('CallDisconnect', (event) => {
clearTimeout(autoanswerhandler);
//console.log('Call was disconnected before auto-answer was performed');
xapi.command("UserInterface Message Alert Clear");
});