Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Created July 4, 2023 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwilson/22d907e60b9d4407e59fadd74c545567 to your computer and use it in GitHub Desktop.
Save alexwilson/22d907e60b9d4407e59fadd74c545567 to your computer and use it in GitHub Desktop.
const GOOGLE_DRIVE_FOLDER_ID = '';
const GOOGLE_DOC_TEMPLATE_ID = '';
const SLACK_WEBHOOK_URL = '';
function isMonday (d) {
return d.getDay() === 1
}
function nextMonday() {
var d = new Date();
if (isMonday(d)) {
return d;
}
d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
return d;
}
function slack(message) {
var url = SLACK_WEBHOOK_URL;
var payload = {
"channel" : "#tlg-private",
"username" : "tlg-report-bot",
"text" : message
}
var options = {
"method" : "post",
"contentType" : "application/json",
"payload" : JSON.stringify(payload)
};
return UrlFetchApp.fetch(url, options)
}
// runs every Monday morning
function nagAgenda() {
slack('Remember to check the agenda for this week\'s <https://docs.google.com/document/d/yes/edit%7CTLG meeting>');
}
// runs every Friday AM
function nagReport() {
slack("It's Friday! Contributions to the <https://drive.google.com/drive/folders/lol%7CTLG Report> & <https://docs.google.com/document/d/yes/edit%7CWeekly Briefing> please.");
}
function main() {
// Generate a timestamp
var timestamp = Utilities.formatDate(nextMonday(), "GMT", "dd/MM/yyyy");
var iso8061 = Utilities.formatDate(nextMonday(), "GMT", "yyyy-MM-dd");
// Copy the TLG Report template
var docid = DriveApp.getFileById(GOOGLE_DOC_TEMPLATE_ID).makeCopy().getId();
var doc = DocumentApp.openById(docid);
doc.setName('TLG Report + Meeting - ' + iso8061);
// Replace the date
var body = doc.getActiveSection();
body.replaceText("XDATEX", timestamp);
doc.saveAndClose();
// Add the file to the TLG folder
var file = DriveApp.getFileById(docid);
var folder = DriveApp.getFolderById(DRIVE_FOLDER_ID);
folder.addFile(file);
// Slack
slack("✨ Hi, here's a fresh <" + doc.getUrl() + "|TLG Report>. ✨");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment