Ночная проверка: сообщение бота об ошибке не считается ответом, упавшие сообщения берутся всегда
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,17 @@ describe("ночная проверка упущенного", () => {
|
||||
expect(r[1]!.logged).toBeNull();
|
||||
});
|
||||
|
||||
it("сообщение об ошибке бота не считается ответом, упавшее сообщение берётся всегда", () => {
|
||||
const msgs = [
|
||||
m("1000", "Client confirmed paint for 734 Placido, ready for the order"),
|
||||
m("1100", "Sorry, I could not process your message. The IT team has been notified.", { userId: null, botId: "B1" }),
|
||||
m("5000", "Please meet Dan at 734 Placido on Monday about the driveway"),
|
||||
m("5100", "Saved", { userId: null, botId: "B1" }),
|
||||
];
|
||||
expect(pickUnanswered(msgs, new Map()).map((x) => x.msg.ts)).toEqual(["1000"]);
|
||||
expect(pickUnanswered(msgs, new Map([["5000", "failed"]])).map((x) => x.msg.ts)).toEqual(["1000", "5000"]);
|
||||
});
|
||||
|
||||
it("разбирает раздел «Упущенные»", () => {
|
||||
expect([...parseMissed("1 | сводка по Placido не записана\n#3: вопрос без ответа")]).toEqual([[1, "сводка по Placido не записана"], [3, "вопрос без ответа"]]);
|
||||
expect(parseMissed("нет").size).toBe(0);
|
||||
|
||||
@@ -36,12 +36,13 @@ const BATCH = 50;
|
||||
|
||||
/** Сообщения людей без ответа агента: нет сообщения бота в окне после него (и в его треде), текст не служебный. */
|
||||
export function pickUnanswered(msgs: SlackHistoryMessage[], logged: Map<string, string>): { msg: SlackHistoryMessage; logged: string | null }[] {
|
||||
const botTs = msgs.filter((m) => m.botId).map((m) => Number(m.ts));
|
||||
// «Sorry, I could not process your message» - сообщение об ошибке, а не ответ по существу
|
||||
const botTs = msgs.filter((m) => m.botId && !/could not process your message/i.test(m.text)).map((m) => Number(m.ts));
|
||||
return msgs
|
||||
.filter((m) => m.userId && !m.botId && m.text.trim().length >= MIN_TEXT && !/has (joined|left) the channel/i.test(m.text))
|
||||
.filter((m) => {
|
||||
const t = Number(m.ts);
|
||||
return !botTs.some((b) => b > t && b - t <= REPLY_WINDOW_SEC);
|
||||
return logged.get(m.ts) === "failed" || !botTs.some((b) => b > t && b - t <= REPLY_WINDOW_SEC);
|
||||
})
|
||||
.map((m) => ({ msg: m, logged: logged.get(m.ts) ?? null }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user