← back to Butlr

lib/call-overrides.js

28 lines

// Live human-in-the-loop overrides for in-progress calls.
//
// The listen page (gated to call owner) can POST one of:
//   /api/calls/:id/say     — speak this text (in caller's voice) on the next gather turn
//   /api/calls/:id/hangup  — say goodbye and hang up on the next gather turn
//
// The gather handler consumes any pending override BEFORE asking the LLM.
// Per-call queue; consumed once, then cleared.

const OVERRIDES = new Map(); // callId → { sayText?: string, hangup?: boolean }

function set(callId, patch) {
  const cur = OVERRIDES.get(callId) || {};
  OVERRIDES.set(callId, { ...cur, ...patch });
}

function consume(callId) {
  const cur = OVERRIDES.get(callId);
  if (cur) OVERRIDES.delete(callId);
  return cur || {};
}

function peek(callId) {
  return OVERRIDES.get(callId) || {};
}

module.exports = { set, consume, peek };