From b4da42524171b501a95e8abdb0a62aea2ab8336c Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Thu, 5 Jan 2017 15:12:40 +0100 Subject: [PATCH] configured twilio voice, fixed bug with added slash on numbers --- app/client/alarm_settings.html | 6 +++--- app/public/sayings/alarm.twiml.xml | 4 ++++ app/server/methods.js | 28 +++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 app/public/sayings/alarm.twiml.xml diff --git a/app/client/alarm_settings.html b/app/client/alarm_settings.html index 36d8b2d..30156f8 100644 --- a/app/client/alarm_settings.html +++ b/app/client/alarm_settings.html @@ -52,21 +52,21 @@ 2. - + 3. - + 4. - + diff --git a/app/public/sayings/alarm.twiml.xml b/app/public/sayings/alarm.twiml.xml new file mode 100644 index 0000000..ef68adf --- /dev/null +++ b/app/public/sayings/alarm.twiml.xml @@ -0,0 +1,4 @@ + + + Zoblak Farm ALARM! ALARM! ALARM! + diff --git a/app/server/methods.js b/app/server/methods.js index 07d15ca..11a169d 100644 --- a/app/server/methods.js +++ b/app/server/methods.js @@ -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