Приём сообщений от всех участников чата менеджера; отправитель в slack_message_log (миграция 008); правка промта; тест
Some checks failed
ci / test (push) Successful in 18s
ci / deploy (push) Failing after 23s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 16:01:23 +03:00
parent 95ddaa4d99
commit 5ff5a62c84
6 changed files with 16 additions and 8 deletions

View File

@@ -24,6 +24,8 @@ export interface IncomingMessage {
ts: string;
text: string;
fileIds: string[];
/** Slack-пользователь, приславший сообщение (любой участник чата; null - папка Drive). */
senderUserId?: string;
/** Локальные файлы, уже лежащие на диске (тесты, симуляция); копируются в папку материалов. */
localFiles?: string[];
}

View File

@@ -62,11 +62,12 @@ export class SlackIntake {
const user = String(ev.user ?? "");
const ts = String(ev.ts ?? "");
if (!channel || !user || !ts) return;
const manager = await this.findManagerBySlackUser(user);
// чат менеджера: пишет любой участник канала, обрабатывается как сообщение менеджера (отправитель сохраняется в журнале)
let manager = await this.findManagerByChannel(channel);
if (!manager && this.opts.channelIds.includes(channel)) manager = await this.findManagerBySlackUser(user);
if (!manager) return;
if (!this.opts.channelIds.includes(channel) && manager.slackChannelId !== channel) return;
const files = ((ev.files as { id?: string }[] | undefined) ?? []).map((f) => String(f.id)).filter(Boolean);
await this.accept(manager, { channel, ts, text: String(ev.text ?? ""), fileIds: files });
await this.accept(manager, { channel, ts, text: String(ev.text ?? ""), fileIds: files, senderUserId: user });
}
/** Менеджер чата (по slack_channel_id или единственный активный менеджер для каналов из настроек). */
@@ -91,8 +92,8 @@ export class SlackIntake {
/** Журнал (защита от дублей) + накопление в debounce-пакет менеджера. */
private async accept(manager: ManagerInfo, msg: IncomingMessage): Promise<boolean> {
const ins = await this.pool.query(
"insert into slack_message_log (channel_id, message_ts, manager_person_id, has_files, status) values ($1,$2,$3,$4,'received') on conflict do nothing returning message_ts",
[msg.channel, msg.ts, manager.personId, msg.fileIds.length > 0 || (msg.localFiles?.length ?? 0) > 0],
"insert into slack_message_log (channel_id, message_ts, manager_person_id, has_files, status, sender_slack_user_id) values ($1,$2,$3,$4,'received',$5) on conflict do nothing returning message_ts",
[msg.channel, msg.ts, manager.personId, msg.fileIds.length > 0 || (msg.localFiles?.length ?? 0) > 0, msg.senderUserId ?? null],
);
if (!ins.rowCount) return false; // дубль
const cur = this.pending.get(manager.personId);