Skip to content

Instantly share code, notes, and snippets.

@florianmartens
Created September 24, 2021 14:25
Show Gist options
  • Save florianmartens/0b0324ac82344034970962af84ddd2e4 to your computer and use it in GitHub Desktop.
Save florianmartens/0b0324ac82344034970962af84ddd2e4 to your computer and use it in GitHub Desktop.
Slack bot for engspresso
import "./utils/env";
import { App } from "@slack/bolt";
import { utcToZonedTime } from "date-fns-tz";
// post messages the next time it's 3pm
const getNextTimestamp = () => {
let date = new Date();
if (date.getHours() > 14) {
date.setDate(date.getDate() + 1);
}
date.setHours(15);
const timeZone = "Europe/Berlin";
return utcToZonedTime(date, timeZone);
};
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
});
app.message("", async ({ message, say, client }) => {
try {
await client.chat.scheduleMessage({
channel: "#team-europe", // -> TODO: invite bot to channel
post_at: Math.round(addMinutes(new Date(), 1).getTime() / 1000),
text: (message as any).text,
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: `*<@${
(message as any).user
}>* submitted the following ☕️ Engspresso message:`,
},
},
{
type: "divider",
},
{
type: "section",
text: {
type: "mrkdwn",
text: (message as any).text,
},
},
],
});
} catch (error) {
console.error(error);
}
await say(
"Your message will be posted to 'team-europe' at 3 pm to let the team know you're not attending the Engspresso ☕️."
);
});
(async () => {
await app.start(3000);
console.log("⚡️ Bolt app is running!");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment