-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSendUpdates.gs
More file actions
129 lines (110 loc) · 4.88 KB
/
Copy pathSendUpdates.gs
File metadata and controls
129 lines (110 loc) · 4.88 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const COL_FINAL_EMAIL_STATUS = "Final Email Status";
const COL_FINAL_STATUS = "Final Status";
const COL_JOB_POSITION = "Which position are you applying for?";
const COL_EMAIL_ADDRESS = "Email Address";
const COL_EXTERNAL_FEEDBACK = "External Feedback";
const DEFAULT_FEEDBACK = "Understanding of technical concepts and/or experience not a fit";
const STATUS = {
REJECTED: "Rejected",
WAITLISTED: "Waitlisted"
};
function getCellValueByColumnName(row, colName, header) {
const col = header.indexOf(colName);
if (col != -1) {
return row[col];
}
}
function shouldSendStatus(row, header) {
const finalStatus = getCellValueByColumnName(row, COL_FINAL_STATUS, header);
if (finalStatus != STATUS.REJECTED && finalStatus != STATUS.WAITLISTED) {
return false;
}
const emailStatus = getCellValueByColumnName(row, COL_FINAL_EMAIL_STATUS, header);
if (emailStatus == "Sent") {
return false;
}
return true;
}
function validate(candidateEmail, jobPosition) {
if (candidateEmail == "") {
return { status: false, err: "email not provided" };
}
if (jobPosition == "") {
return { status: false, err: "position not provided" };
}
return { status: true, err: undefined }
}
function getRejectedHtmlBody(feedback = DEFAULT_FEEDBACK) {
return `<p>Dear Candidate,</p>
<div> </div>
<div>Thank you very much for investing your time and effort to apply for an internship position at Gramoday.</div>
<div> </div>
<div>Unfortunately, at this time, we decided to proceed with our selection process with another candidate. We have the below feedback from our selection panel:</div>
<div>\"${feedback}\"</div>
<div> </div>
<div>Please follow our linkedin page for future opportunities : <a href="https://www.linkedin.com/company/agrilinks-technologies/" target="_blank" rel="noopener" data-saferedirecturl="https://www.google.com/url?q=https://www.linkedin.com/company/agrilinks-technologies/&source=gmail&ust=1642424959596000&usg=AOvVaw0K-YGeMWceo55biB5PRhES">https://www.linkedin.com/<wbr />company/agrilinks-<wbr />technologies/</a><br /><br /></div>
<div>I wish you the best of luck in your future endeavors and hope we'll have a chance to meet again soon.</div>
</div>
<div> </div>
<div>Regards,</div>
<div>Gramoday Team</div>`;
}
function getWaitlistedHtmlBody(jobPosition) {
return `<p>Dear Candidate,</p>
<div> </div>
<div>Thank you very much for investing your time and effort to apply for ${jobPosition} at Gramoday.</div>
<div><br />We really enjoyed meeting you, learning about your skills and experiences and having a really interesting conversation.</div>
<div><br />Unfortunately, at this time, we decided to proceed with our selection process with another candidate.<br /><br /></div>
<div>For now, we have kept your candidature as <strong>"<span class="il">waitlisted</span>" </strong>which means that in case we have an opening that better fits your profile, we will make sure to get in touch with you, and you will be automatically <strong>shortlisted</strong>.<br /><br /></div>
<div>I wish you the best of luck in your future endeavours and hope we'll have a chance to meet again soon.</div>
<div> </div>
<div>Regards,</div>
<div>Gramoday Team</div>`;
}
function sendEmail(email, jobPosition, candStatus, candFeedback) {
const { status, err } = validate(email, jobPosition);
if (!status) {
Logger.log("Invalid data: ", err);
return false;
}
MailApp.sendEmail({
to: email,
cc: INTERVIEWER_EMAIL,
subject: `[Update] Gramoday - ${jobPosition}`,
htmlBody: candStatus == STATUS.REJECTED ? getRejectedHtmlBody(candFeedback) : getWaitlistedHtmlBody(jobPosition)
});
return true;
}
function sendUpdate(row, header) {
Logger.log("Sending updates to: %s", row);
const email = getCellValueByColumnName(row, COL_EMAIL_ADDRESS, header);
const jobPosition = getCellValueByColumnName(row, COL_JOB_POSITION, header);
const status = getCellValueByColumnName(row, COL_FINAL_STATUS, header);
const feedback = getCellValueByColumnName(row, COL_EXTERNAL_FEEDBACK, header);
return sendEmail(email, jobPosition, status, feedback);
}
function updateStatusInSheet(sheet, row, header, statusCol, statusMsg) {
const col = header.indexOf(statusCol);
if (col != -1) {
const range = sheet.getRange(row + 1, col + 1);
range.setValue(statusMsg);
}
}
function sendUpdates() {
try {
const sheet = SpreadsheetApp.getActiveSheet();
const data = sheet.getDataRange().getValues();
Logger.log("No of rows: %s", data.length);
const header = data[0];
for (let row = 1; row < data.length; ++row) {
if (shouldSendStatus(data[row], header)) {
const success = sendUpdate(data[row], header);
if (success) {
updateStatusInSheet(sheet, row, header, COL_FINAL_EMAIL_STATUS, "Sent");
}
}
}
} catch (err) {
Logger.log("Error in sendUpdates: %s", err)
}
}