-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathceo-personal-assistant.js
50 lines (40 loc) · 1.33 KB
/
ceo-personal-assistant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
This script checks each purchase request every 11 seconds.
If a decision on the purchase request has not been made
AND
Y minutes have passed since it was first requested,
then remind the CEO of that collection of purchase requests.
*/
const moment = require('moment');
const { readAllPurchaseRequests } = require('./modules/database');
const { sendDM } = require('./modules/slack');
const config = require('./config');
const checkOnPurchaseRequests = async () => {
const purchaseRequests = await readAllPurchaseRequests();
const purchaseRequestReminders = [];
for (let key of Object.keys(purchaseRequests)) {
const { timestamp, decision, item, userId } = purchaseRequests[key];
if (!decision && moment().diff(timestamp, 'minutes') > 1) {
purchaseRequestReminders.push({
item,
userId
});
}
}
console.log(
`Total reminders to send to CEO are ${purchaseRequestReminders.length}`
);
if (purchaseRequestReminders.length > 0) {
sendDM(
config.ceoId,
'Hi! Here are purchase requests that still need a decision from you.',
purchaseRequestReminders.map(purchaseRequest => ({
text: `*${purchaseRequest.item}* requested by <@${
purchaseRequest.userId
}>`
}))
);
}
};
checkOnPurchaseRequests();
setInterval(checkOnPurchaseRequests, 11000);