Attach call recording + transcript to the Odoo lead (Phase 3 item)
odoo_client.attach_call_artifacts posts the transcript to the lead's chatter (readable in place) and attaches transcript_<sid>.txt + the stereo call WAV. bot.py wires it post-call: extract_and_record now returns the Odoo ref (persisted_to), the in-call tool path stamps it too, the audiobuffer handler records the saved WAV path, and the attach runs in a thread after the lead lands (brief wait for the async WAV write; failures only log — the lead is already safe). Verified e2e against db1: create -> attach -> verify -> delete. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -145,3 +145,40 @@ def create_appointment_request(patient_name, callback_number, reason, preferred_
|
||||
vals["user_id"] = ODOO_USER_ID
|
||||
rec = _exec(uid, models, "crm.lead", "create", vals)
|
||||
return ("crm.lead", rec)
|
||||
|
||||
|
||||
def attach_call_artifacts(model, rec_id, wav_path=None, transcript=None, call_sid=None):
|
||||
"""Attach the call recording (WAV) and post the transcript to a lead's chatter.
|
||||
|
||||
Called post-call for the record created by create_appointment_request. The transcript
|
||||
goes in as a chatter note (readable in place) AND as a .txt attachment (downloadable);
|
||||
the WAV is attached as-is. Any failure raises — the caller logs and moves on (the lead
|
||||
itself is already safe)."""
|
||||
import base64
|
||||
|
||||
uid, models = _connect()
|
||||
sid = call_sid or "call"
|
||||
|
||||
if transcript:
|
||||
body = "<b>📼 Call transcript</b><br/>" + "<br/>".join(
|
||||
escape(line) for line in transcript.splitlines() if line.strip()
|
||||
)
|
||||
_exec(uid, models, model, "message_post", [rec_id], body=body)
|
||||
_exec(uid, models, "ir.attachment", "create", [{
|
||||
"name": f"transcript_{sid}.txt",
|
||||
"datas": base64.b64encode(transcript.encode()).decode(),
|
||||
"res_model": model,
|
||||
"res_id": rec_id,
|
||||
"mimetype": "text/plain",
|
||||
}])
|
||||
|
||||
if wav_path and os.path.isfile(wav_path):
|
||||
with open(wav_path, "rb") as fh:
|
||||
b64 = base64.b64encode(fh.read()).decode()
|
||||
_exec(uid, models, "ir.attachment", "create", [{
|
||||
"name": os.path.basename(wav_path),
|
||||
"datas": b64,
|
||||
"res_model": model,
|
||||
"res_id": rec_id,
|
||||
"mimetype": "audio/wav",
|
||||
}])
|
||||
|
||||
Reference in New Issue
Block a user