diff --git a/supabase/functions/autocall-result/index.ts b/supabase/functions/autocall-result/index.ts index 9f72199..ba8aad0 100644 --- a/supabase/functions/autocall-result/index.ts +++ b/supabase/functions/autocall-result/index.ts @@ -94,6 +94,13 @@ Deno.serve(async (request) => { const scenario = body.scenario || "A"; const callType = body.call_type === "pkp" ? "pkp" : "dlv"; const wasTest = body.was_test_mode ?? false; + // Дата, которую робот реально назвал в разговоре (AGI передаёт её в chosen_date). + // Нужна и для заказа, и для строки лога: в карточке автодозвона показываем дату, + // а не «завтра/послезавтра» — «день 1» это первый рабочий день окна, который + // в пятницу оказывается понедельником. + const chosenDate = /^\d{4}-\d{2}-\d{2}$/.test(body.chosen_date || "") + ? (body.chosen_date as string) + : null; // ── Идемпотентность: повторный curl с тем же uniqueid обновляет строку ── const { data: existing } = await supabase @@ -108,6 +115,7 @@ Deno.serve(async (request) => { outcome: body.outcome, dtmf_day: body.dtmf_day ?? null, dtmf_half: body.dtmf_half ?? null, + chosen_date: chosenDate, changed: body.changed ?? false, was_test_mode: body.was_test_mode ?? false, }).eq("id", existing.id); @@ -122,6 +130,7 @@ Deno.serve(async (request) => { attempt_no: attemptNo, scenario, call_type: callType, + chosen_date: chosenDate, call_started_at: body.call_started_at || new Date().toISOString(), answered_at: body.answered_at || null, duration_sec: body.duration_sec ?? null,