Озвучивание ответов (Google Chirp 3 HD): режим и голос на чат, миграция 007, загрузка аудио в Slack; docs
All checks were successful
ci / test (push) Successful in 15s
ci / deploy (push) Successful in 1m5s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 22:01:47 +03:00
parent 0c4fb2df99
commit d8f3ddee37
15 changed files with 316 additions and 11 deletions

View File

@@ -13,6 +13,8 @@ export interface SlackApi {
postMessage(channel: string, text: string, threadTs?: string): Promise<boolean>;
fileInfo(fileId: string): Promise<SlackFile | null>;
download(file: SlackFile, toPath: string): Promise<number>;
/** Загружает файл в канал (нужен scope files:write). */
uploadFile?(channel: string, filename: string, data: Buffer, title?: string): Promise<void>;
}
/** Web API Slack под токеном бота (отправка сообщений и скачивание вложений). */
@@ -38,6 +40,19 @@ export function createSlackApi(botToken: string, fetchFn: typeof fetch = fetch):
if (!j.ok || !f || typeof f.url_private_download !== "string") return null;
return { id: String(f.id), name: String(f.name ?? f.id), mimetype: String(f.mimetype ?? ""), size: Number(f.size ?? 0), urlPrivateDownload: f.url_private_download };
},
async uploadFile(channel, filename, data, title) {
const form = new URLSearchParams({ filename, length: String(data.length) });
const start = (await (await fetchFn("https://slack.com/api/files.getUploadURLExternal", {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded", authorization: `Bearer ${botToken}` },
body: form,
})).json()) as { ok?: boolean; error?: string; upload_url?: string; file_id?: string };
if (!start.ok || !start.upload_url || !start.file_id) throw new Error(`Slack files.getUploadURLExternal: ${start.error ?? "нет upload_url"}`);
const up = await fetchFn(start.upload_url, { method: "POST", body: new Uint8Array(data) });
if (!up.ok) throw new Error(`Slack upload: HTTP ${up.status}`);
const done = await call("files.completeUploadExternal", { files: [{ id: start.file_id, title: title ?? filename }], channel_id: channel });
if (!done.ok) throw new Error(`Slack files.completeUploadExternal: ${done.error}`);
},
async download(file, toPath) {
const res = await fetchFn(file.urlPrivateDownload, { headers: { authorization: `Bearer ${botToken}` } });
if (!res.ok) throw new Error(`скачивание ${file.name}: HTTP ${res.status}`);