Newsletter
Sed ut perspiciatis unde.
Subscribe
|
// 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///‘; |
|
const testing = ‘https://hooks.slack.com/services///‘; |
|
|
|
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 forn${order}nn`, |
|
icon_emoji: ‘:ghost:’ |
|
}; |
|
|
|
const response = await fetch(url, { |
|
method: ‘POST’, |
|
body: JSON.stringify(data), |
|
headers: { |
|
‘Content-Type’: ‘application/json’ |
|
} |
|
}); |