-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
31 lines (25 loc) · 1.03 KB
/
main.ts
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
import axios from "npm:axios";
import { to as wrap } from "npm:await-to-js";
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
import { getJoinNowLink, shuffle, formatList } from "./lib/utils.ts";
import { people } from "./lib/people.ts";
const env = await load();
// Production
const CRON_EXPRESSION = "30 23 * * MON,TUE,WED,THU";
const URL = env["SLACK_URL"] ? env["SLACK_URL"] : Deno.env.get("SLACK_URL");
const main = async () => {
if (!URL) throw new Error("No SLACK_URL env variable set");
const shuffledPeople: string[] = shuffle(people);
const orderText: string = formatList(shuffledPeople);
const text = `*Morning standup time* 🎉 Who's running the meeting?\n${orderText}\n👉 ${getJoinNowLink()}`;
const output = { text };
const [postError, response]: [
Error | null,
{ statusText: string } | undefined
] = await wrap(axios.post(URL, output));
if (postError) throw postError;
if (response) console.log(response.statusText);
};
Deno.cron("Run main", CRON_EXPRESSION, () => {
main();
});