fix(autocall): edge fn обновляет по uniqueid вместо дубликата (клиент бросает трубку после выбора)

This commit is contained in:
Hermes 2026-09-01 22:50:39 +02:00
parent d6c3e02f24
commit a08612ef0d
1 changed files with 11 additions and 2 deletions

View File

@ -83,14 +83,23 @@ Deno.serve(async (request) => {
const scenario = body.scenario || "A"; const scenario = body.scenario || "A";
const wasTest = body.was_test_mode ?? false; const wasTest = body.was_test_mode ?? false;
// ── Идемпотентность: повторный curl с тем же uniqueid не плодит строки ── // ── Идемпотентность: повторный curl с тем же uniqueid обновляет строку ──
const { data: existing } = await supabase const { data: existing } = await supabase
.from("autocall_log") .from("autocall_log")
.select("id") .select("id")
.eq("asterisk_uniqueid", body.asterisk_uniqueid) .eq("asterisk_uniqueid", body.asterisk_uniqueid)
.maybeSingle(); .maybeSingle();
if (existing) { 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);
} }
// ── Вставка в лог ── // ── Вставка в лог ──