Last active
January 25, 2025 18:20
-
-
Save ScriptRaccoon/dbff6fb3e6f14e5fbfea28523eb4d0cf to your computer and use it in GitHub Desktop.
Script for a slack app sending a daily bot message thatannounces the Daily animator
This file contains hidden or 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 scriptProperties = PropertiesService.getScriptProperties() | |
const WEBHOOK_URL = scriptProperties.getProperty('WEBHOOK_URL') | |
const COLLEAGUES = [ | |
{ | |
name: 'Hanna', | |
slackID: '...', | |
}, | |
{ | |
name: 'Martin', | |
slackID: '...', | |
}, | |
{ | |
name: 'Script', | |
slackID: '...', | |
}, | |
] | |
function checkIfWeekEnd() { | |
const day = new Date().getDay() | |
return day == 0 || day == 6 | |
} | |
function sendMessage() { | |
const isWeekEnd = checkIfWeekEnd() | |
if (isWeekEnd) return | |
const daysSinceEpoch = Math.floor(new Date() / (1000 * 60 * 60 * 24)) | |
const index = daysSinceEpoch % COLLEAGUES.length | |
const colleague = COLLEAGUES[index] | |
const message = `Today's Daily Animator is <@${colleague.slackID}>! :microphone:` | |
const payload = { | |
blocks: [ | |
{ | |
type: 'divider', | |
}, | |
{ | |
type: 'section', | |
text: { | |
type: 'mrkdwn', | |
text: message, | |
}, | |
}, | |
{ | |
type: 'divider', | |
}, | |
{ | |
type: 'context', | |
elements: [ | |
{ | |
type: 'mrkdwn', | |
text: 'Join the daily at 9:15 <https://meet.google.com/whatever|here>.', | |
}, | |
], | |
}, | |
], | |
} | |
const options = { | |
method: 'POST', | |
contentType: 'application/json', | |
payload: JSON.stringify(payload), | |
} | |
UrlFetchApp.fetch(WEBHOOK_URL, options) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment