···
import { Elysia, t } from "elysia";
import { swagger } from "@elysiajs/swagger";
import { version } from "../package.json";
4
-
import { SlackApp } from "slack-edge";
import { SlackCache } from "./cache";
5
+
import { SlackWrapper } from "./slackWrapper";
6
+
import type { SlackUser } from "./slack";
7
-
if (!process.env.SLACK_BOT_TOKEN || !process.env.SLACK_SIGNING_SECRET) {
8
-
const missingEnvVars = [
9
-
!process.env.SLACK_BOT_TOKEN && "SLACK_BOT_TOKEN",
10
-
!process.env.SLACK_SIGNING_SECRET && "SLACK_SIGNING_SECRET",
14
-
`Missing required environment variables: ${missingEnvVars.join(", ")}`,
18
-
const slackApp = new SlackApp({
20
-
SLACK_BOT_TOKEN: process.env.SLACK_BOT_TOKEN,
21
-
SLACK_SIGNING_SECRET: process.env.SLACK_SIGNING_SECRET,
22
-
SLACK_LOGGING_LEVEL: "INFO",
24
-
startLazyListenerAfterAck: true,
8
+
const slackApp = new SlackWrapper();
const cache = new SlackCache(process.env.DATABASE_PATH ?? "./data/cachet.db");
···
79
-
const slackConnection = await slackApp.client.auth.test();
62
+
const slackConnection = await slackApp.testAuth();
const databaseConnection = await cache.healthCheck();
83
-
if (!slackConnection.ok || !databaseConnection)
66
+
if (!slackConnection || !databaseConnection)
86
-
slack: slackConnection.ok,
69
+
slack: slackConnection,
database: databaseConnection,
···
// if not found then check slack first
125
-
const slackUser = await slackApp.client.users.info({
108
+
let slackUser: SlackUser;
110
+
slackUser = await slackApp.getUserInfo(params.user);
112
+
if (e instanceof Error && e.message === "user_not_found")
113
+
return error(404, { message: "User not found" });
129
-
if (!slackUser.ok) return error(404, { message: "User not found" });
131
-
if (!slackUser.user?.profile?.image_original || !slackUser.user.id)
132
-
return error(404, { message: "User data malformed" });
115
+
return error(500, {
116
+
message: `Error fetching user from Slack: ${e}`,
134
-
await cache.insertUser(
136
-
slackUser.user?.profile?.image_original,
120
+
await cache.insertUser(slackUser.id, slackUser.profile.image_original);
140
-
id: slackUser.user.id,
expiration: new Date().toISOString(),
142
-
user: slackUser.user.id,
143
-
image: slackUser.user.profile.image_original,
125
+
user: slackUser.id,
126
+
image: slackUser.profile.image_original,
···
144
+
message: t.String(),