From 1490632eaf0b57e6605f6251bb8f9a46899dd6e0 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:33:19 +0000 Subject: [PATCH 1/4] Add metadata field to SendMessageRequest model - Added metadata field to CreateDraftRequest which is inherited by SendMessageRequest - Added test cases for metadata in draft creation and message sending - Updated docstring to include metadata field description Fixes #394 Co-Authored-By: Aaron de Mello --- nylas/models/drafts.py | 4 +++- tests/resources/test_drafts.py | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) 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..c501e1b 100644 --- a/tests/resources/test_drafts.py +++ b/tests/resources/test_drafts.py @@ -143,6 +143,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 +370,26 @@ 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): + drafts = Drafts(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} + } + + drafts.send(identifier="abc-123", request_body=request_body) + + http_client_response._execute.assert_called_once_with( + "POST", + "/v3/grants/abc-123/messages/send", + None, + None, + request_body, + overrides=None, + ) + def test_send_draft_encoded_id(self, http_client_response): drafts = Drafts(http_client_response) From 977c695bf5b3d8fe9f64847e12ff5a85e0edcd0b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:39:23 +0000 Subject: [PATCH 2/4] Update test assertion to use keyword arguments Co-Authored-By: Aaron de Mello --- tests/resources/test_drafts.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/resources/test_drafts.py b/tests/resources/test_drafts.py index c501e1b..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: @@ -371,7 +372,7 @@ def test_send_draft(self, http_client_response): ) def test_send_message_with_metadata(self, http_client_response): - drafts = Drafts(http_client_response) + messages = Messages(http_client_response) request_body = { "subject": "Hello from Nylas!", "to": [{"name": "Jon Snow", "email": "jsnow@gmail.com"}], @@ -379,14 +380,13 @@ def test_send_message_with_metadata(self, http_client_response): "metadata": {"custom_field": "value", "another_field": 123} } - drafts.send(identifier="abc-123", request_body=request_body) + messages.send(identifier="abc-123", request_body=request_body) http_client_response._execute.assert_called_once_with( - "POST", - "/v3/grants/abc-123/messages/send", - None, - None, - request_body, + method="POST", + path="/v3/grants/abc-123/messages/send", + request_body=request_body, + data=None, overrides=None, ) From 4204bb220ba0730c19606d962d92496117ab5583 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:31:57 +0000 Subject: [PATCH 3/4] Update CHANGELOG.md for metadata field addition Co-Authored-By: Aaron de Mello --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5ecbb7..7fe592f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ nylas-python Changelog ====================== +v6.5.0 +---------------- +* Add metadata field support for drafts and messages through CreateDraftRequest model + v6.4.0 ---------------- * Add support for from field for sending messages From da7c1eee07bb0ae00303a47e35c779344f0bcc2e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:54:56 +0000 Subject: [PATCH 4/4] Update changelog format to match version entry style Co-Authored-By: Aaron de Mello --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f428c70..0b2bbd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ nylas-python Changelog ====================== -# Unreleased +Unreleased ---------------- * Add support for Scheduler APIs * Fixed attachment download response handling