Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata field to SendMessageRequest model #398

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
4 changes: 3 additions & 1 deletion nylas/models/drafts.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
41 changes: 41 additions & 0 deletions tests/resources/test_drafts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from nylas.models.drafts import Draft
from nylas.resources.drafts import Drafts
from nylas.resources.messages import Messages


class TestDraft:
Expand Down Expand Up @@ -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": "[email protected]"}],
"cc": [{"name": "Arya Stark", "email": "[email protected]"}],
"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 = {
Expand Down Expand Up @@ -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": "[email protected]"}],
"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)

Expand Down
Loading