function(response) { // SUCCESS CALLBACK // Iterate through available_phone_numbers for ( var available_number in response.available_phone_numbers ) { phone_number = response.available_phone_numbers[available_number].phone_number; util.log("Available Phone Number: " + phone_number); //Now what we need to is add the available number to our account using /IncomingPhoneNumbers //Remember that the price depends on the phone number type & location. client.create( 'incoming_phone_numbers', { 'PhoneNumber' : phone_number }, function (response) { // SUCCESS CALLBACK util.log("Phone number purchase SID: " + response.sid); }, function(error) { // ERROR CALLBACK util.log("Error at IncomingPhoneNumber purchase: " + error) } ); } },
router.post('/', function(req, res) { if(req.body.user.name == null | req.body.user.phone == null || req.body.user.email == null) { return res.send(400, "You need to put in your user information in the settings page."); } for(var i = 0; i < req.body.selected.length; i++) { if(req.body.selected[i].phone != undefined) { numbers.push(req.body.selected[i].phone); } } if(numbers.length === 0) { return res.send(400, "None of the contacts you selected have a phone number.");} console.log(req.body.selected); console.log(numbers); for(var i = 0; i < numbers.length; i++) { telapi.create("sms_messages", { "From": process.env.TELAPI_NUMBER, "To": numbers[i], "Body": req.body.user.name + " is having a hard time and needs your help. Message them to let them know you are there for them." }, function (response) { res.send("Messages sent successfully"); }, function (error) { res.send(400, "An error occurred while sending messages"); } ); } numbers = []; });
var transcribeAudio = function(audioURL) { telApiClient.create( 'transcriptions', { AudioUrl: audioURL, TranscribeCallback: TRANSCRIBE_CALLBACK_URL, CallbackMethod: TRANSCRIBE_CALLBACK_METHOD }, function(response) { console.log("Transcription SID: " + response.sid); }, function(error) { console.log("Error: " + error); } ); }
router.post('/', function(req, res) { if(req.body.user.name == null | req.body.user.phone == null || req.body.user.email == null) { return res.send(400, "You need to put in your user information in the settings page."); } for(var i = 0; i < req.body.selected.length; i++) { if(req.body.selected[i].phone != undefined) { numbers.push(req.body.selected[i].phone); } if(req.body.selected[i].email != undefined) { emails.push(req.body.selected[i].email); } } console.log(numbers); for(var i = 0; i < numbers.length; i++) { telapi.create("sms_messages", { "From": process.env.TELAPI_NUMBER, "To": numbers[i], "Body": req.body.user.name + ' is suicidal and needs help. Contact them and take them to a hospital to get a suicide assessment. If you can\'t reach them, call 911.' }, function (response) { res.send("Messages sent successfully"); }, function (error) { return res.send(400, "An error occurred while sending messages"); } ); } numbers = []; console.log(emails); sendgrid.send({ to : emails, from : process.env.SENDGRID_USER, fromname: "Defcon One", subject : 'Emergency! ' + req.body.user.name + ' needs your help immediately', text : 'I am having suicidal thoughts right now and I need your help. Please call or text me immediately at ' + req.body.user.phone + ' and take me to a local hospital to get a suicide assessment. If you are unable to reach me, call 911. I am not safe and cannot guarantee you that right now I will not hurt myself. This is urgent and you must take immediate action.\n\n' + req.body.user.name + '\n(via the Defcon One app)' }, function(err, json) { if (err) { return res.send(400, "An error occurred while sending messages"); } res.send("Messages sent successfully"); }); emails = []; });
var telapi = require('telapi').client, sms = new telapi( 'ACa1852f1f9c9c4a83a123986c30c54935', 'ce374ecf093846b18c1c94da6a0c8f87' ); sms.create('sms_messages', { From : '+16788046693', To : '+40741699975', Body : 'Alerta Intrus! http://navigheaza.ro/rpi/20130420/01-222002-00.jpg http://cacat/srl/?stream=sloboz Daca nu este false alarm suna la 911 !!' });
* @category TelApi Helper * @package TelApi * @author Nevio Vesic <*****@*****.**> * @license http://creativecommons.org/licenses/MIT/ MIT * @copyright (2012) TelTech Systems, Inc. <*****@*****.**> */ var util = require("util"); // For logging purposes :) var Client = require('telapi').client; // Load configuration file var configuration = require('./configuration'); // Setup TelAPI Client var client = new Client(configuration.account_sid, configuration.auth_token); client.create( 'carrier', { 'PhoneNumber' : '{PhoneNumber_E.164}' }, function(response) { // SUCCESS CALLBACK for(var carrier in response.carrier_lookups) { util.log( "Carrier lookup cost " + response.carrier_lookups[carrier].price + ". Phone Number carrier is: " + response.carrier_lookups[carrier].carrier + "." ); } }, function(error) { // ERROR CALLBACK
* @category TelApi Helper * @package TelApi * @author Nevio Vesic <*****@*****.**> * @license http://creativecommons.org/licenses/MIT/ MIT * @copyright (2012) TelTech Systems, Inc. <*****@*****.**> */ var util = require("util"); // For logging purposes :) var Client = require('telapi').client; // Load configuration file var configuration = require('./configuration'); // Setup TelAPI Client var client = new Client(configuration.account_sid, configuration.auth_token); // Send a new SMS message. // Make sure the From and To parameters are set. client.create( 'sms_messages', { "From" : "(XXX) XXX-XXXX", "To" : "(XXX) XXX-XXXX", "Body" : "Example message sent from TelAPI Node.JS helper" }, function(response) { // SUCCESS CALLBACK util.log("SMS successfully sent. SMS SID: " + response.sid); }, function(error) { // ERROR CALLBACK util.log("ERROR OCCURED: " + error)
* @category TelApi Helper * @package TelApi * @author Nevio Vesic <*****@*****.**> * @license http://creativecommons.org/licenses/MIT/ MIT * @copyright (2012) TelTech Systems, Inc. <*****@*****.**> */ var util = require("util"); // For logging purposes :) var Client = require('telapi').client; // Load configuration file var configuration = require('./configuration'); // Setup TelAPI Client var client = new Client(configuration.account_sid, configuration.auth_token); // Retrieve the 10 newest notifications in the TelAPI account client.get( 'notifications', { 'PageSize' : 10 }, // Limit to 10 notifications per page function(response) { // SUCCESS CALLBACK util.log("Pagination details ........................................."); util.log(""); util.log("Current page is: " + response.page); util.log("Number of pages: " + response.num_pages); util.log("Current page size: " + response.page_size); util.log("Total records: " + response.total)
* @category TelApi Helper * @package TelApi * @author Nevio Vesic <*****@*****.**> * @license http://creativecommons.org/licenses/MIT/ MIT * @copyright (2012) TelTech Systems, Inc. <*****@*****.**> */ var util = require("util"); // For logging purposes :) var Client = require('telapi').client; // Load configuration file var configuration = require('./configuration'); // Setup TelAPI Client var client = new Client(configuration.account_sid, configuration.auth_token); client.create( 'cnam', { 'PhoneNumber' : '{PhoneNumber_E.164}' }, function(response) { // SUCCESS CALLBACK for(var cnam in response.cnam_dips) { util.log( "CNAM lookup cost " + response.cnam_dips[cnam].price + ". Cnam body is: " + response.cnam_dips[cnam].body + "." ); } }, function(error) { // ERROR CALLBACK
* @category TelApi Helper * @package TelApi * @author Nevio Vesic <*****@*****.**> * @license http://creativecommons.org/licenses/MIT/ MIT * @copyright (2012) TelTech Systems, Inc. <*****@*****.**> */ var util = require("util"); // For logging purposes :) var Client = require('telapi').client; // Load configuration file var configuration = require('./configuration'); // Setup TelAPI Client var client = new Client(configuration.account_sid, configuration.auth_token); // Retrieve specific account details. client.get( [ 'usages' ], null, function(response) { // SUCCESS CALLBACK for(var usage in response.usages) { util.log( "Usage average cost for " + response.usages[usage].month + " month is " + response.usages[usage].average_cost + " USD." ); }