fix(slack): resolve bolt constructors

This commit is contained in:
Basit Mustafa
2026-01-18 20:45:11 -07:00
committed by Peter Steinberger
parent 7ef7b94bc0
commit 4ed1b7c7ed

View File

@@ -1,6 +1,6 @@
import type { IncomingMessage, ServerResponse } from "node:http"; import type { IncomingMessage, ServerResponse } from "node:http";
import SlackBolt from "@slack/bolt"; import SlackBoltDefault, * as SlackBoltModule from "@slack/bolt";
import { resolveTextChunkLimit } from "../../auto-reply/chunk.js"; import { resolveTextChunkLimit } from "../../auto-reply/chunk.js";
import { DEFAULT_GROUP_HISTORY_LIMIT } from "../../auto-reply/reply/history.js"; import { DEFAULT_GROUP_HISTORY_LIMIT } from "../../auto-reply/reply/history.js";
@@ -26,16 +26,23 @@ import { normalizeAllowList } from "./allow-list.js";
import type { MonitorSlackOpts } from "./types.js"; import type { MonitorSlackOpts } from "./types.js";
const slackBoltModule = SlackBolt as typeof import("@slack/bolt") & { type SlackBoltNamespace = typeof import("@slack/bolt");
default?: typeof import("@slack/bolt");
}; const slackBoltDefault = SlackBoltDefault as unknown;
// Bun allows named imports from CJS; Node ESM doesn't. Use default+fallback for compatibility. const slackBoltNamespace =
const slackBolt = slackBoltModule.default || slackBoltModule; (typeof slackBoltDefault === "object" && slackBoltDefault
const App = slackBolt.App || (slackBolt.default && slackBolt.default.App) || slackBoltModule.App; ? ("default" in slackBoltDefault
const HTTPReceiver = ? (slackBoltDefault as { default?: unknown }).default
slackBolt.HTTPReceiver || : slackBoltDefault)
(slackBolt.default && slackBolt.default.HTTPReceiver) || : undefined) as SlackBoltNamespace | undefined;
slackBoltModule.HTTPReceiver; // Bun allows named imports from CJS; Node ESM doesn't. Resolve default/module shapes for compatibility.
const App =
((typeof slackBoltDefault === "function"
? slackBoltDefault
: slackBoltNamespace?.App) ??
SlackBoltModule.App) as SlackBoltNamespace["App"];
const HTTPReceiver = (slackBoltNamespace?.HTTPReceiver ??
SlackBoltModule.HTTPReceiver) as SlackBoltNamespace["HTTPReceiver"];
function parseApiAppIdFromAppToken(raw?: string) { function parseApiAppIdFromAppToken(raw?: string) {
const token = raw?.trim(); const token = raw?.trim();
if (!token) return undefined; if (!token) return undefined;