Skip to content

Instantly share code, notes, and snippets.

@torgeir
Created September 15, 2023 17:11
Show Gist options
  • Save torgeir/acf870bb5856299b81e87460327d87c6 to your computer and use it in GitHub Desktop.
Save torgeir/acf870bb5856299b81e87460327d87c6 to your computer and use it in GitHub Desktop.
A script to post the name of a team member to a slack web hook once a week.
(async function () {
var webHookUrl = "https://hooks.slack.com/triggers/a/b/c";
// credits chatgpt
function isoWeek(date) {
// copy date so don't modify original
date = new Date(date);
// set to nearest thursday (current date + 4 - current day) % 7
date.setUTCDate(date.getUTCDate() + 4 - (date.getUTCDay() || 7));
// get first day of year
var yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
// calculate full weeks to nearest thursday
var week = Math.ceil(((date - yearStart) / 86400000 + 1) / 7);
return week;
}
var team = [];
var memberByWeek = [...Array(52).keys()]
.map((n) => n + 1)
.map((week) => team[(week - 1) % team.length]);
var member = memberByWeek[isoWeek(new Date())];
await fetch(webHookUrl, {
method: "POST",
body: JSON.stringify({ member }),
headers: {
"content-type": "application/json",
},
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment