configured twilio voice, fixed bug with added slash on numbers

This commit is contained in:
Senad Uka
2017-01-05 15:12:40 +01:00
parent 7906e5a1a0
commit b4da425241
3 changed files with 30 additions and 8 deletions

View File

@@ -52,21 +52,21 @@
<td>2.
</td>
<td>
<input required name="sms2" type="tel" id="sms2" placeholder="+3876xxxxxxxx" value={{ config 'sms2'}}/>
<input required name="sms2" type="tel" id="sms2" placeholder="+3876xxxxxxxx" value={{ config 'sms2'}} />
</td>
</tr>
<tr>
<td>3.
</td>
<td>
<input required name="sms3" type="tel" id="sms3" placeholder="+3876xxxxxxxx" value={{ config 'sms3'}}/>
<input required name="sms3" type="tel" id="sms3" placeholder="+3876xxxxxxxx" value={{ config 'sms3'}} />
</td>
</tr>
<tr>
<td>4.
</td>
<td>
<input required name="sms4" type="tel" id="sms4" placeholder="+3876xxxxxxxx" value={{ config 'sms4'}}/>
<input required name="sms4" type="tel" id="sms4" placeholder="+3876xxxxxxxx" value={{ config 'sms4'}} />
</td>
</tr>
</table>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman" language="english">Zoblak Farm ALARM! ALARM! ALARM!</Say>
</Response>

View File

@@ -218,7 +218,7 @@ reactToAlarmData = function(controller_id) {
var boxSilent = config.timeoutBox && minutesSinceLastBoxContact > config.timeoutBox;
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(new Date()).diff(moment(state.lastPhoneContact), 'minutes') : -1;
var phoneSilent = false;//config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
var phoneSilent = false; //config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
console.log("too ", tooCold, tooHot, boxSilent, phoneSilent);
console.log("lpc", state.lastPhoneContact);
@@ -254,7 +254,9 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
var smsSent = !!state.state.alarmSmsSent;
var needsToSendSms = !smsSent // && phoneSilent;
var sendSmsPart = needsToSendSms ? { 'state.alarmSmsSent': true } : {};
var sendSmsPart = needsToSendSms ? {
'state.alarmSmsSent': true
} : {};
ControllerState.update(state._id, {
'$set': Object.assign({
@@ -265,17 +267,18 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
});
if (needsToSendSms) {
sendAlarmingSms(controller_id,reason, state.config.smsNumbers)
sendAlarmingSms(controller_id, reason, state.config.smsNumbers);
callTheUser(controller_id, reason, state.config.smsNumbers);
}
}
function sendAlarmingSms(controller_id,reason, numbers) {
function sendAlarmingSms(controller_id, reason, numbers) {
for (var i in numbers) {
var number = numbers[i];
twilio = Twilio('AC10d7ed0bf54c1be4b1cd7133130e63f4', 'e133d3f02a69b79e93ad9ca1d73517d1');
twilio.sendSms({
to: number, // Any number Twilio can deliver to
from: '+447481345235', // A number you bought from Twilio and can use for outbound communication
from: '+19282124174', // A number you bought from Twilio and can use for outbound communication
body: 'Zoblak alarm! Pokrenite aplikaciju! HITNO! http://agrar.zoblak.com/alarm?controller_id=' + controller_id // body of the SMS message
}, function(err, responseData) { //this function is executed when a response is received from Twilio
if (!err) { // "err" is an error received during the request, if any
@@ -289,6 +292,21 @@ function sendAlarmingSms(controller_id,reason, numbers) {
}
}
function callTheUser(controller_id, reason, numbers) {
for (var i in numbers) {
var number = numbers[i];
twilio = Twilio('AC10d7ed0bf54c1be4b1cd7133130e63f4', 'e133d3f02a69b79e93ad9ca1d73517d1');
twilio.makeCall({
to: number, // Any number Twilio can call
from: '+441143031932', // A number you bought from Twilio and can use for outbound communication
url: 'https://handler.twilio.com/twiml/EH9491c24474db07ec52b598baa5724f1e' // A URL that produces an XML document (TwiML) which contains instructions for the call
}, function(err, responseData) {
//executed when the call has been initiated.
console.log(err); // outputs "+14506667788"
});
}
}
function stopTheAlarm(controller_id, everythingIsBackToNormal = false) {
// time of alarm stopped is reset so that scheduled job can raise the alarm
// again