human hand off
This commit is contained in:
parent
d0fee5c8f7
commit
7af776196a
34 changed files with 2941 additions and 195 deletions
|
|
@ -1,13 +1,5 @@
|
|||
from dataclasses import dataclass, field
|
||||
|
||||
from app.services.handoff_email_templates import (
|
||||
build_mirror_handoff_html,
|
||||
build_mirror_handoff_text,
|
||||
build_mirror_update_html,
|
||||
build_mirror_update_text,
|
||||
format_sender_line,
|
||||
)
|
||||
from app.services.html_sanitizer import plain_text_to_html, sanitize_email_html
|
||||
from app.services.mime_body_extractor import ExtractedMimePart, MirroredMimeContent, extract_mirror_content
|
||||
from app.services.raw_mime_storage import get_raw_mime_storage
|
||||
|
||||
|
|
@ -21,11 +13,6 @@ class HandoffMirrorPayload:
|
|||
|
||||
|
||||
async def load_mirror_payload(external_message: dict) -> HandoffMirrorPayload:
|
||||
sender = external_message.get("sender") or {}
|
||||
sender_line = format_sender_line(sender)
|
||||
external_subject = external_message.get("subject", "")
|
||||
agent_email = external_message.get("_agent_email", "")
|
||||
|
||||
body_text = (external_message.get("body_text") or external_message.get("snippet") or "").strip()
|
||||
body_html = external_message.get("body_html")
|
||||
inline_parts: list[ExtractedMimePart] = []
|
||||
|
|
@ -44,29 +31,12 @@ async def load_mirror_payload(external_message: dict) -> HandoffMirrorPayload:
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
if body_html:
|
||||
original_html = sanitize_email_html(body_html)
|
||||
elif body_text:
|
||||
original_html = plain_text_to_html(body_text)
|
||||
else:
|
||||
original_html = plain_text_to_html("(No message body)")
|
||||
|
||||
if not body_text:
|
||||
body_text = external_message.get("snippet") or "(No message body)"
|
||||
|
||||
return HandoffMirrorPayload(
|
||||
body_text=build_mirror_handoff_text(
|
||||
sender_line=sender_line,
|
||||
external_subject=external_subject,
|
||||
original_body_text=body_text,
|
||||
agent_email=agent_email,
|
||||
),
|
||||
body_html=build_mirror_handoff_html(
|
||||
sender_line=sender_line,
|
||||
external_subject=external_subject,
|
||||
original_html=original_html,
|
||||
agent_email=agent_email,
|
||||
),
|
||||
body_text=body_text,
|
||||
body_html=body_html,
|
||||
inline_parts=inline_parts,
|
||||
file_attachments=file_attachments,
|
||||
)
|
||||
|
|
@ -77,32 +47,4 @@ async def load_mirror_update_payload(
|
|||
*,
|
||||
agent_email: str,
|
||||
) -> HandoffMirrorPayload:
|
||||
external_message = {**external_message, "_agent_email": agent_email}
|
||||
payload = await load_mirror_payload(external_message)
|
||||
sender = external_message.get("sender") or {}
|
||||
sender_line = format_sender_line(sender)
|
||||
external_subject = external_message.get("subject", "")
|
||||
body_text = (external_message.get("body_text") or external_message.get("snippet") or "").strip()
|
||||
|
||||
body_html = external_message.get("body_html")
|
||||
if body_html:
|
||||
original_html = sanitize_email_html(body_html)
|
||||
else:
|
||||
original_html = plain_text_to_html(body_text or "(No message body)")
|
||||
|
||||
return HandoffMirrorPayload(
|
||||
body_text=build_mirror_update_text(
|
||||
sender_line=sender_line,
|
||||
external_subject=external_subject,
|
||||
original_body_text=body_text,
|
||||
agent_email=agent_email,
|
||||
),
|
||||
body_html=build_mirror_update_html(
|
||||
sender_line=sender_line,
|
||||
external_subject=external_subject,
|
||||
original_html=original_html,
|
||||
agent_email=agent_email,
|
||||
),
|
||||
inline_parts=payload.inline_parts,
|
||||
file_attachments=payload.file_attachments,
|
||||
)
|
||||
return await load_mirror_payload(external_message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue