Created
July 4, 2023 16:12
-
-
Save alexwilson/22d907e60b9d4407e59fadd74c545567 to your computer and use it in GitHub Desktop.
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
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