Отчёт активности: сообщения сотрудника, записанные под менеджером проекта, считаются; ночная проверка: received_at по времени сообщения, молчание агента - не обработка
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -141,7 +141,7 @@ export const EVENT_COUNTS_SQL = `
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Сообщения сотрудника в чате с ассистентом и в проектных каналах Slack. Пока в журнале ассистента нет автора (до миграции 008) считаем,
|
* Сообщения сотрудника в чате с ассистентом и в проектных каналах Slack. Пока в журнале ассистента нет автора (до миграции 008) считаем,
|
||||||
* что писал сам менеджер канала. Сообщение проектного канала, которое уже есть в журнале ассистента, считается один раз.
|
* что писал сам менеджер канала. Сообщение проектного канала, которое уже есть в журнале ассистента как сообщение этого же сотрудника, считается один раз; сообщение сотрудника, записанное в журнал под менеджером проекта (его писал не менеджер, например бухгалтер или CFO, в том числе когда агент не смог ответить), считается по каналу.
|
||||||
*/
|
*/
|
||||||
export const CHAT_COUNTS_SQL = `
|
export const CHAT_COUNTS_SQL = `
|
||||||
with msgs as (
|
with msgs as (
|
||||||
@@ -154,7 +154,7 @@ export const CHAT_COUNTS_SQL = `
|
|||||||
from slack_channel_message c
|
from slack_channel_message c
|
||||||
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
|
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
|
||||||
where c.user_id = $5
|
where c.user_id = $5
|
||||||
and not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts)
|
and not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts and l.manager_person_id = $1 and (l.sender_slack_user_id is null or l.sender_slack_user_id = $5))
|
||||||
)
|
)
|
||||||
select (at at time zone $4)::date::text as day, count(*)::int as n
|
select (at at time zone $4)::date::text as day, count(*)::int as n
|
||||||
from msgs
|
from msgs
|
||||||
@@ -186,7 +186,7 @@ export const USER_ACTIVITY_DAYS_SQL = `
|
|||||||
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
|
join project_channel pc on pc.channel_id = c.channel_id and pc.track_activity
|
||||||
join person p on p.slack_user_id = c.user_id
|
join person p on p.slack_user_id = c.user_id
|
||||||
join jt_membership mb on mb.id = p.jt_membership_id
|
join jt_membership mb on mb.id = p.jt_membership_id
|
||||||
where not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts)
|
where not exists (select 1 from slack_message_log l where l.channel_id = c.channel_id and l.message_ts = c.message_ts and l.manager_person_id = p.id and (l.sender_slack_user_id is null or l.sender_slack_user_id = p.slack_user_id))
|
||||||
),
|
),
|
||||||
chat as (
|
chat as (
|
||||||
select user_name, (at at time zone $3)::date::text as day, count(*)::int as n
|
select user_name, (at at time zone $3)::date::text as day, count(*)::int as n
|
||||||
|
|||||||
@@ -103,13 +103,15 @@ async function processAsDailyLog(ctx: AgentContext, chat: ChatDeps, c: AuditCand
|
|||||||
const defaultJob = c.channel.jobId ? { id: c.channel.jobId, name: c.channel.jobName ?? null } : undefined;
|
const defaultJob = c.channel.jobId ? { id: c.channel.jobId, name: c.channel.jobName ?? null } : undefined;
|
||||||
const summary = await summaryContextFor(ctx.pool, chat.timezone, { channel: c.channel.id, ts: c.ts, text: fullText, senderName: c.author, defaultJob });
|
const summary = await summaryContextFor(ctx.pool, chat.timezone, { channel: c.channel.id, ts: c.ts, text: fullText, senderName: c.author, defaultJob });
|
||||||
await ctx.pool.query(
|
await ctx.pool.query(
|
||||||
"insert into slack_message_log (channel_id, message_ts, manager_person_id, has_files, status, sender_slack_user_id) values ($1,$2,$3,false,'processing',$4) on conflict (channel_id, message_ts) do update set status = 'processing'",
|
"insert into slack_message_log (channel_id, message_ts, manager_person_id, has_files, status, sender_slack_user_id, received_at) values ($1,$2,$3,false,'processing',$4, to_timestamp($2::numeric)) on conflict (channel_id, message_ts) do update set status = 'processing'",
|
||||||
[c.channel.id, c.ts, manager.personId, senderSlackUserId],
|
[c.channel.id, c.ts, manager.personId, senderSlackUserId],
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
const r = await handleManagerMessages(chat, manager, [{ channel: c.channel.id, ts: c.ts, text: fullText, fileIds: [], senderUserId: senderSlackUserId ?? undefined }], { summary, channel: c.channel.id });
|
const r = await handleManagerMessages(chat, manager, [{ channel: c.channel.id, ts: c.ts, text: fullText, fileIds: [], senderUserId: senderSlackUserId ?? undefined }], { summary, channel: c.channel.id });
|
||||||
await ctx.pool.query("update slack_message_log set status = 'done', processed_at = now() where channel_id = $1 and message_ts = $2", [c.channel.id, c.ts]);
|
await ctx.pool.query("update slack_message_log set status = 'done', processed_at = now() where channel_id = $1 and message_ts = $2", [c.channel.id, c.ts]);
|
||||||
return { outcome: "processed", note: (r.reply ?? "без ответа").slice(0, 200) };
|
// агент ответил «(без ответа)»: он решил ничего не записывать (например, по памяти копит такие сообщения для recap канала) - это не обработка
|
||||||
|
if (!r.reply) return { outcome: "skipped", note: "агент ничего не записал и не ответил (решил копить для recap или счёл несущественным)" };
|
||||||
|
return { outcome: "processed", note: r.reply.slice(0, 200) };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await ctx.pool.query("update slack_message_log set status = 'failed', processed_at = now() where channel_id = $1 and message_ts = $2", [c.channel.id, c.ts]);
|
await ctx.pool.query("update slack_message_log set status = 'failed', processed_at = now() where channel_id = $1 and message_ts = $2", [c.channel.id, c.ts]);
|
||||||
return { outcome: "failed", note: String(e).slice(0, 200) };
|
return { outcome: "failed", note: String(e).slice(0, 200) };
|
||||||
|
|||||||
Reference in New Issue
Block a user