Created
January 31, 2023 20:42
-
-
Save aashutoshrathi/f478c15d36d516131ed98ef8678ec64d to your computer and use it in GitHub Desktop.
Sample Slack Standup Bot for getting order
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
// add a cronjob for this | |
import fetch from 'node-fetch'; // for lower node versions | |
const getOrder = () => { | |
const users = ["Jim", "Pam" "Dwight"]; // names of users | |
let shuffled = users | |
.map(value => ({ value, sort: Math.random() })) | |
.sort((a, b) => a.sort - b.sort) | |
.map(({ value }) => `-> ${value}`); | |
return shuffled.join('\n'); | |
} | |
const main = 'https://hooks.slack.com/services/<A>/<B>/<C>'; | |
const testing = 'https://hooks.slack.com/services/<A>/<B>/<D>'; | |
const main = async (isTest) => { | |
let url = main; | |
let channel = '#main'; | |
if (isTest) { | |
url = testing; | |
channel = '#testing'; | |
} | |
const order = getOrder(); | |
const data = { | |
channel, | |
username: 'Standup Bot', | |
text: `Hola! folks :wave:\nHere's the order you are looking for\n${order}\n\n`, | |
icon_emoji: ':ghost:' | |
}; | |
const response = await fetch(url, { | |
method: 'POST', | |
body: JSON.stringify(data), | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}); | |
} | |
main(process.argv[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment