Use bodyV2 markdown for CRM notes and transcripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-03-08 21:45:31 +00:00
parent 93288aa981
commit bc80f7667c

View file

@ -151,16 +151,19 @@ async def update_person(person_id: str, updates: dict) -> bool:
return False
async def create_note(title: str, person_id: str | None = None) -> str | None:
async def create_note(title: str, person_id: str | None = None, body: str = "") -> str | None:
"""Create a note in Twenty CRM, optionally linked to a person."""
if not settings.twenty_crm_api_key:
return None
try:
async with httpx.AsyncClient() as http:
note_data: dict = {"title": title}
if body:
note_data["bodyV2"] = {"markdown": body, "blocknote": None}
resp = await http.post(
f"{BASE_URL}/notes",
headers=HEADERS,
json={"title": title},
json=note_data,
timeout=10,
)
if resp.status_code != 201:
@ -282,11 +285,15 @@ async def save_conversation_transcript(
lines.append(f"🤖 Bot: {content}")
transcript = "\n".join(lines)
# Truncate to 4000 chars for CRM note
if len(transcript) > 4000:
transcript = transcript[:3950] + "\n\n... (truncated)"
# Truncate to 10000 chars for CRM note body
if len(transcript) > 10000:
transcript = transcript[:9950] + "\n\n... (truncated)"
return await create_note(transcript, person_id)
return await create_note(
f"💬 Chat transcript — {visitor_name}",
person_id,
body=transcript,
)
async def create_lead_in_crm(