Last active
January 28, 2017 15:19
-
-
Save ObjectIsAdvantag/7c96e7eccde8c5e839cbbabaf76bc6b4 to your computer and use it in GitHub Desktop.
Debug Dial outbound
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csvFile = loadFile("http://hosting.tropo.com/5075556/www/data/numbers.csv"); | |
var numbersToDial = csvJSON(csvFile); | |
for (var i = 0; i<numbersToDial.length-1; i++){ | |
var callee = numbersToDial[i]; | |
call(callee.number, { network: "SMS" }); | |
say("Hi, " + callee.name); | |
hangup(); | |
} | |
function loadFile(url){ | |
var line; | |
var returnFile = ""; | |
connection = new java.net.URL(url).openConnection(); | |
connection.setDoOutput(false); | |
connection.setDoInput(true); | |
connection.setInstanceFollowRedirects(false); | |
connection.setRequestMethod("GET"); | |
connection.setRequestProperty("Content-Type", "text/plain"); | |
connection.setRequestProperty("charset", "utf-8"); | |
connection.connect(); | |
var dis = new java.io.DataInputStream(connection.getInputStream()); | |
while (dis.available() !== 0) { | |
line = dis.readLine(); | |
returnFile += line + "#end"; | |
} | |
return returnFile; | |
} | |
function csvJSON(csv){ | |
var lines=csv.split("#end"); | |
var returnJSON = []; | |
var headers=lines[0].split(","); | |
for(var i=1;i<lines.length;i++){ | |
var obj = {}; | |
var currentline=lines[i].split(","); | |
for(var j=0;j<headers.length;j++){ | |
obj[headers[j]] = currentline[j]; | |
} | |
returnJSON.push(obj); | |
} | |
return returnJSON; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment