Долгоживущий агент чата (только для managerIds, тестовый менеджер) и тайминг чата (chat_timing, миграция 016); тесты; docs
All checks were successful
ci / test (push) Successful in 23s
ci / deploy (push) Successful in 1m46s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 12:55:18 +03:00
parent 81634fbfa9
commit 65ab75d378
17 changed files with 733 additions and 29 deletions

View File

@@ -11,6 +11,8 @@ export interface SlackFile {
export interface SlackApi {
postMessage(channel: string, text: string, threadTs?: string): Promise<boolean>;
/** То же, но возвращает ts отправленного сообщения (null - не отправлено): по нему считается время ответа для chat_timing. */
postMessageTs?(channel: string, text: string, threadTs?: string): Promise<string | null>;
fileInfo(fileId: string): Promise<SlackFile | null>;
download(file: SlackFile, toPath: string): Promise<number>;
/** Загружает файл в канал (нужен scope files:write). */
@@ -25,13 +27,17 @@ export function createSlackApi(botToken: string, fetchFn: typeof fetch = fetch):
headers: { "content-type": "application/json; charset=utf-8", authorization: `Bearer ${botToken}` },
body: JSON.stringify(body),
});
return (await res.json()) as { ok?: boolean; error?: string; file?: Record<string, unknown> };
return (await res.json()) as { ok?: boolean; error?: string; ts?: string; file?: Record<string, unknown> };
};
const postTs = async (channel: string, text: string, threadTs?: string): Promise<string | null> => {
// Slack ограничивает текст ~40000 символов; режем с запасом
const r = await call("chat.postMessage", { channel, text: text.slice(0, 35000), ...(threadTs ? { thread_ts: threadTs } : {}) });
return r.ok === true ? (typeof r.ts === "string" ? r.ts : "") : null;
};
return {
postMessageTs: postTs,
async postMessage(channel, text, threadTs) {
// Slack ограничивает текст ~40000 символов; режем с запасом
const r = await call("chat.postMessage", { channel, text: text.slice(0, 35000), ...(threadTs ? { thread_ts: threadTs } : {}) });
return r.ok === true;
return (await postTs(channel, text, threadTs)) !== null;
},
async fileInfo(fileId) {
const res = await fetchFn(`https://slack.com/api/files.info?file=${encodeURIComponent(fileId)}`, { headers: { authorization: `Bearer ${botToken}` } });