Last active
August 5, 2017 13:30
-
-
Save macaullyjames/807afb60808252d6247dc32505034403 to your computer and use it in GitHub Desktop.
Google Scripts code for sending SMS from Google Sheets – from https://medium.com/46-thoughts/send-sms-from-google-spreadsheet-71f11d358361
This file contains 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
function elksSMS() { | |
// Get the properties | |
var prop = PropertiesService.getScriptProperties(); | |
var username = prop.getProperty('46elksUsername'); | |
var password = prop.getProperty('46elksPassword'); | |
var spreadsheetID = prop.getProperty('SpreadsheetID'); | |
var sender = prop.getProperty('46elksAccountPhoneNumber'); | |
var auth = Utilities.base64Encode(username + ":" + password); | |
// Open the requested SpreadSheet and Sheet | |
var spreadSheet = SpreadsheetApp.openById(spreadsheetID); | |
var sheet = spreadSheet.getSheets()[0]; | |
var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, 5).getValues(); | |
// Loop over all rows in the range and send the SMS | |
for (var i in range) { | |
if (range[i][1] == '' || range[i][3] == 'SENT') continue; | |
var state = sheet.getRange(2+Number(i), 4); | |
var info = sheet.getRange(2+Number(i), 5); | |
try { | |
UrlFetchApp.fetch("https://api.46elks.com/a1/SMS", { | |
"method": "post", | |
"headers": { "Authorization": "Basic " + auth }, | |
"payload": { | |
"from" : sender, | |
"to" : '+' + range[i][1], | |
"message" : range[i][2] | |
} | |
}); | |
state.setValue('SENT').setBackground('#93c47d'); | |
info.setValue('Sent on ' + new Date()); | |
} catch (err) { | |
state.setValue('FAILED').setBackground('#e06666'); | |
info.setValue(String(err).replace('\n', '')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment