clean up bodyparams logic

This commit is contained in:
Taylor Wilsdon
2026-02-13 10:07:10 -05:00
parent a3107e900b
commit a336131558
2 changed files with 53 additions and 158 deletions

View File

@@ -11,7 +11,7 @@ import ssl
import mimetypes
from pathlib import Path
from html.parser import HTMLParser
from typing import Optional, List, Dict, Literal, Any
from typing import Annotated, Optional, List, Dict, Literal, Any
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
@@ -19,7 +19,6 @@ from email.mime.base import MIMEBase
from email import encoders
from email.utils import formataddr
from fastapi import Body as BodyParam
from pydantic import Field
from auth.service_decorator import require_google_service
@@ -989,36 +988,32 @@ async def get_gmail_attachment_content(
async def send_gmail_message(
service,
user_google_email: str,
to: str = BodyParam(..., description="Recipient email address."),
subject: str = BodyParam(..., description="Email subject."),
body: str = BodyParam(..., description="Email body content (plain text or HTML)."),
body_format: Literal["plain", "html"] = BodyParam(
"plain",
to: Annotated[str, Field(description="Recipient email address.")],
subject: Annotated[str, Field(description="Email subject.")],
body: Annotated[str, Field(description="Email body content (plain text or HTML).")],
body_format: Annotated[Literal["plain", "html"], Field(
description="Email body format. Use 'plain' for plaintext or 'html' for HTML content.",
),
cc: Optional[str] = BodyParam(None, description="Optional CC email address."),
bcc: Optional[str] = BodyParam(None, description="Optional BCC email address."),
from_name: Optional[str] = BodyParam(
None,
)] = "plain",
cc: Annotated[Optional[str], Field(description="Optional CC email address.")] = None,
bcc: Annotated[Optional[str], Field(description="Optional BCC email address.")] = None,
from_name: Annotated[Optional[str], Field(
description="Optional sender display name (e.g., 'Peter Hartree'). If provided, the From header will be formatted as 'Name <email>'.",
),
from_email: Optional[str] = BodyParam(
None,
)] = None,
from_email: Annotated[Optional[str], Field(
description="Optional 'Send As' alias email address. Must be configured in Gmail settings (Settings > Accounts > Send mail as). If not provided, uses the authenticated user's email.",
),
thread_id: Optional[str] = BodyParam(
None, description="Optional Gmail thread ID to reply within."
),
in_reply_to: Optional[str] = BodyParam(
None, description="Optional Message-ID of the message being replied to."
),
references: Optional[str] = BodyParam(
None, description="Optional chain of Message-IDs for proper threading."
),
attachments: Optional[List[Dict[str, str]]] = BodyParam(
None,
)] = None,
thread_id: Annotated[Optional[str], Field(
description="Optional Gmail thread ID to reply within.",
)] = None,
in_reply_to: Annotated[Optional[str], Field(
description="Optional Message-ID of the message being replied to.",
)] = None,
references: Annotated[Optional[str], Field(
description="Optional chain of Message-IDs for proper threading.",
)] = None,
attachments: Annotated[Optional[List[Dict[str, str]]], Field(
description='Optional list of attachments. Each can have: "path" (file path, auto-encodes), OR "content" (standard base64, not urlsafe) + "filename". Optional "mime_type". Example: [{"path": "/path/to/file.pdf"}] or [{"filename": "doc.pdf", "content": "base64data", "mime_type": "application/pdf"}]',
),
)] = None,
) -> str:
"""
Sends an email using the user's Gmail account. Supports both new emails and replies with optional attachments.
@@ -1161,38 +1156,34 @@ async def send_gmail_message(
async def draft_gmail_message(
service,
user_google_email: str,
subject: str = BodyParam(..., description="Email subject."),
body: str = BodyParam(..., description="Email body (plain text)."),
body_format: Literal["plain", "html"] = BodyParam(
"plain",
subject: Annotated[str, Field(description="Email subject.")],
body: Annotated[str, Field(description="Email body (plain text).")],
body_format: Annotated[Literal["plain", "html"], Field(
description="Email body format. Use 'plain' for plaintext or 'html' for HTML content.",
),
to: Optional[str] = BodyParam(
None, description="Optional recipient email address."
),
cc: Optional[str] = BodyParam(None, description="Optional CC email address."),
bcc: Optional[str] = BodyParam(None, description="Optional BCC email address."),
from_name: Optional[str] = BodyParam(
None,
)] = "plain",
to: Annotated[Optional[str], Field(
description="Optional recipient email address.",
)] = None,
cc: Annotated[Optional[str], Field(description="Optional CC email address.")] = None,
bcc: Annotated[Optional[str], Field(description="Optional BCC email address.")] = None,
from_name: Annotated[Optional[str], Field(
description="Optional sender display name (e.g., 'Peter Hartree'). If provided, the From header will be formatted as 'Name <email>'.",
),
from_email: Optional[str] = BodyParam(
None,
)] = None,
from_email: Annotated[Optional[str], Field(
description="Optional 'Send As' alias email address. Must be configured in Gmail settings (Settings > Accounts > Send mail as). If not provided, uses the authenticated user's email.",
),
thread_id: Optional[str] = BodyParam(
None, description="Optional Gmail thread ID to reply within."
),
in_reply_to: Optional[str] = BodyParam(
None, description="Optional Message-ID of the message being replied to."
),
references: Optional[str] = BodyParam(
None, description="Optional chain of Message-IDs for proper threading."
),
attachments: Optional[List[Dict[str, str]]] = BodyParam(
None,
)] = None,
thread_id: Annotated[Optional[str], Field(
description="Optional Gmail thread ID to reply within.",
)] = None,
in_reply_to: Annotated[Optional[str], Field(
description="Optional Message-ID of the message being replied to.",
)] = None,
references: Annotated[Optional[str], Field(
description="Optional chain of Message-IDs for proper threading.",
)] = None,
attachments: Annotated[Optional[List[Dict[str, str]]], Field(
description="Optional list of attachments. Each can have: 'path' (file path, auto-encodes), OR 'content' (standard base64, not urlsafe) + 'filename'. Optional 'mime_type' (auto-detected from path if not provided).",
),
)] = None,
) -> str:
"""
Creates a draft email in the user's Gmail account. Supports both new drafts and reply drafts with optional attachments.
@@ -1749,12 +1740,12 @@ async def list_gmail_filters(service, user_google_email: str) -> str:
async def create_gmail_filter(
service,
user_google_email: str,
criteria: Dict[str, Any] = BodyParam(
..., description="Filter criteria object as defined in the Gmail API."
),
action: Dict[str, Any] = BodyParam(
..., description="Filter action object as defined in the Gmail API."
),
criteria: Annotated[Dict[str, Any], Field(
description="Filter criteria object as defined in the Gmail API.",
)],
action: Annotated[Dict[str, Any], Field(
description="Filter action object as defined in the Gmail API.",
)],
) -> str:
"""
Creates a Gmail filter using the users.settings.filters API.