diff --git a/supabase/functions/autocall-result/index.ts b/supabase/functions/autocall-result/index.ts index 7fb1702..c379f8e 100644 --- a/supabase/functions/autocall-result/index.ts +++ b/supabase/functions/autocall-result/index.ts @@ -83,14 +83,23 @@ Deno.serve(async (request) => { const scenario = body.scenario || "A"; const wasTest = body.was_test_mode ?? false; - // ── Идемпотентность: повторный curl с тем же uniqueid не плодит строки ── + // ── Идемпотентность: повторный curl с тем же uniqueid обновляет строку ── const { data: existing } = await supabase .from("autocall_log") .select("id") .eq("asterisk_uniqueid", body.asterisk_uniqueid) .maybeSingle(); if (existing) { - return jsonResponse({ ok: true, duplicate: true }, 200, cors); + // Уже записано (клиент бросил трубку после фиксации, AGI шлёт повторно + // при следующем save). Обновляем outcome/слот, не плодя строки. + await supabase.from("autocall_log").update({ + outcome: body.outcome, + dtmf_day: body.dtmf_day ?? null, + dtmf_half: body.dtmf_half ?? null, + changed: body.changed ?? false, + was_test_mode: body.was_test_mode ?? false, + }).eq("id", existing.id); + return jsonResponse({ ok: true, updated: true }, 200, cors); } // ── Вставка в лог ──