diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f96548..0b2bbd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ nylas-python Changelog ====================== Unreleased --------------- +---------------- * Add support for Scheduler APIs * Fixed attachment download response handling +* Add metadata field support for drafts and messages through CreateDraftRequest model v6.4.0 ---------------- diff --git a/nylas/models/drafts.py b/nylas/models/drafts.py index f77a125..f6e3803 100644 --- a/nylas/models/drafts.py +++ b/nylas/models/drafts.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import List, get_type_hints +from typing import List, Dict, Any, get_type_hints from dataclasses_json import dataclass_json from typing_extensions import TypedDict, NotRequired @@ -87,6 +87,7 @@ class CreateDraftRequest(TypedDict): reply_to_message_id: The ID of the message that you are replying to. tracking_options: Options for tracking opens, links, and thread replies. custom_headers: Custom headers to add to the message. + metadata: A dictionary of key-value pairs storing additional data. """ body: NotRequired[str] @@ -101,6 +102,7 @@ class CreateDraftRequest(TypedDict): reply_to_message_id: NotRequired[str] tracking_options: NotRequired[TrackingOptions] custom_headers: NotRequired[List[CustomHeader]] + metadata: NotRequired[Dict[str, Any]] UpdateDraftRequest = CreateDraftRequest diff --git a/tests/resources/test_drafts.py b/tests/resources/test_drafts.py index ecd51eb..8613a2f 100644 --- a/tests/resources/test_drafts.py +++ b/tests/resources/test_drafts.py @@ -2,6 +2,7 @@ from nylas.models.drafts import Draft from nylas.resources.drafts import Drafts +from nylas.resources.messages import Messages class TestDraft: @@ -143,6 +144,27 @@ def test_create_draft(self, http_client_response): overrides=None, ) + def test_create_draft_with_metadata(self, http_client_response): + drafts = Drafts(http_client_response) + request_body = { + "subject": "Hello from Nylas!", + "to": [{"name": "Jon Snow", "email": "jsnow@gmail.com"}], + "cc": [{"name": "Arya Stark", "email": "astark@gmail.com"}], + "body": "This is the body of my draft message.", + "metadata": {"custom_field": "value", "another_field": 123} + } + + drafts.create(identifier="abc-123", request_body=request_body) + + http_client_response._execute.assert_called_once_with( + "POST", + "/v3/grants/abc-123/drafts", + None, + None, + request_body, + overrides=None, + ) + def test_create_draft_small_attachment(self, http_client_response): drafts = Drafts(http_client_response) request_body = { @@ -349,6 +371,25 @@ def test_send_draft(self, http_client_response): method="POST", path="/v3/grants/abc-123/drafts/draft-123", overrides=None ) + def test_send_message_with_metadata(self, http_client_response): + messages = Messages(http_client_response) + request_body = { + "subject": "Hello from Nylas!", + "to": [{"name": "Jon Snow", "email": "jsnow@gmail.com"}], + "body": "This is the body of my message.", + "metadata": {"custom_field": "value", "another_field": 123} + } + + messages.send(identifier="abc-123", request_body=request_body) + + http_client_response._execute.assert_called_once_with( + method="POST", + path="/v3/grants/abc-123/messages/send", + request_body=request_body, + data=None, + overrides=None, + ) + def test_send_draft_encoded_id(self, http_client_response): drafts = Drafts(http_client_response)