Долгоживущий агент чата (только для managerIds, тестовый менеджер) и тайминг чата (chat_timing, миграция 016); тесты; docs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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}` } });
|
||||
|
||||
Reference in New Issue
Block a user