-
Notifications
You must be signed in to change notification settings - Fork 4
/
Helpers.gs
71 lines (63 loc) · 2.46 KB
/
Helpers.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Gets the value of a particular cell, based on A1 Notation
function getValue(sheet, cell) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet).getRange(cell).getValue();
}
// Sets the value of a particular cell, based on A1 Notation
function setValue(sheet, cell, value) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet).getRange(cell).setValue(value);
}
// Function expects the email address and interviewed counter to be side by side
// Note that the indices are 1-based, so the first column is 1 and so on
function getContactInfo(sheet, emailColIndex, phoneColIndex, preferredColIndex, checkedInColIndex) {
var range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet).getDataRange();
for (var i = 2; i < MAX_RANGE; i++) {
if (!range.getCell(i, checkedInColIndex).getValue() && range.getCell(i, preferredColIndex).getValue() !== "") {
var type = range.getCell(i, preferredColIndex).getValue();
switch (type) {
case EMAIL_STRING:
return {
"type": type,
"to": String(range.getCell(i, emailColIndex).getValue())
};
case SMS_STRING:
return {
"type": type,
"to": String(range.getCell(i, phoneColIndex).getValue())
};
}
}
}
return {"type": "failure"};
}
// Delegate our contact object to decide how to contact applicant
function sendNotice(contact, subject, body) {
switch (contact.type) {
case EMAIL_STRING:
return sendEmail(contact.to, subject, body);
case SMS_STRING:
return sendSMS(contact.to, subject + " " + body);
default:
return;
}
}
// Send email
function sendEmail(to, subject, body) {
return MailApp.sendEmail(to, subject, body);
}
// Send SMS, ensure twilio details are properly formed
function sendSMS(to, body) {
var messages_url = "https://api.twilio.com/2010-04-01/Accounts/" + TWILIO_ACCOUNT_ID + "/Messages.json";
var payload = {
"To": to,
"Body": body,
"From": TWILIO_PHONE_NUMBER
};
var options = {
"method": "post",
"payload": payload,
"headers": {
"Authorization": "Basic " + Utilities.base64Encode(TWILIO_ACCOUNT_ID + ":" + TWILIO_AUTH_TOKEN)
}
};
UrlFetchApp.fetch(messages_url, options);
}