diff --git a/chatbot-api/twenty_crm.py b/chatbot-api/twenty_crm.py index f16944b..00a813d 100644 --- a/chatbot-api/twenty_crm.py +++ b/chatbot-api/twenty_crm.py @@ -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(