Каркас monorepo: scheduler, data_collector, khbuild_assistant_prep, khb_common; миграции; CI/CD
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
18
packages/khb_common/src/alerts/index.ts
Normal file
18
packages/khb_common/src/alerts/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { CommonSettings } from "../settings/index.js";
|
||||
|
||||
/** Уведомление ИТ-команде в Slack. Без настроек itAlerts возвращает false (вызывающий пишет в лог). */
|
||||
export async function itNotify(
|
||||
settings: Pick<CommonSettings, "itAlerts">,
|
||||
text: string,
|
||||
fetchFn: typeof fetch = fetch,
|
||||
): Promise<boolean> {
|
||||
const cfg = settings.itAlerts;
|
||||
if (!cfg) return false;
|
||||
const res = await fetchFn("https://slack.com/api/chat.postMessage", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json", authorization: `Bearer ${cfg.slackBotToken}` },
|
||||
body: JSON.stringify({ channel: cfg.slackChannelId, text }),
|
||||
});
|
||||
const body = (await res.json()) as { ok?: boolean };
|
||||
return res.ok && body.ok === true;
|
||||
}
|
||||
Reference in New Issue
Block a user