Skip to content

Instantly share code, notes, and snippets.

@aashutoshrathi
Created January 31, 2023 20:42
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 aashutoshrathi/f478c15d36d516131ed98ef8678ec64d to your computer and use it in GitHub Desktop.
Save aashutoshrathi/f478c15d36d516131ed98ef8678ec64d to your computer and use it in GitHub Desktop.
Sample Slack Standup Bot for getting order
// 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