Skip to content

Commit

Permalink
Fix issue with sending scheduled messages & Add draft send support (#181
Browse files Browse the repository at this point in the history
)

# Description
This PR fixes an issue with handling the response of scheduled send.
Also adds support for sending drafts.

# License
<!-- Your PR comment must contain the following line for us to merge the
PR. -->
I confirm that this contribution is made under the terms of the MIT
license and that I have the authority necessary to make this
contribution on behalf of its copyright owner.
  • Loading branch information
mrashed-dev committed Dec 21, 2023
1 parent 58ceaaf commit 598fa65
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Nylas Java SDK Changelog

## [2.0.0-beta.4] - TBD

### Added
* Added support for sending drafts

### Changed
* Fixed issue with sending scheduled messages

## [2.0.0-beta.3] - Released 2023-12-18

### Added
Expand Down
35 changes: 24 additions & 11 deletions src/main/kotlin/com/nylas/models/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import com.squareup.moshi.Json
* Class representing a Nylas Message object.
*/
data class Message(
/**
* The unique identifier for the message.
*/
@Json(name = "id")
val id: String,
/**
* Grant ID of the Nylas account.
*/
Expand All @@ -21,17 +16,17 @@ data class Message(
*/
@Json(name = "from")
val from: List<EmailName>,
/**
* Unix timestamp of when the message was received by the mail server.
* This may be different from the unverified Date header in raw message object.
*/
@Json(name = "date")
val date: Long,
/**
* The type of object.
*/
@Json(name = "object")
private val obj: String = "message",
/**
* The unique identifier for the message.
* Note: The ID may not be present for scheduled messages until the message is sent.
*/
@Json(name = "id")
val id: String? = null,
/**
* An array of bcc recipients.
*/
Expand Down Expand Up @@ -106,11 +101,29 @@ data class Message(
*/
@Json(name = "created_at")
val createdAt: Long? = null,
/**
* Unix timestamp of when the message was received by the mail server.
* This may be different from the unverified Date header in raw message object.
*/
@Json(name = "date")
val date: Long? = null,
/**
* A list of key-value pairs storing additional data.
*/
@Json(name = "metadata")
val metadata: Map<String, Any>? = null,
/**
* The ID of the scheduled message.
* Only present if the message was scheduled to be sent.
*/
@Json(name = "schedule_id")
val scheduleId: String? = null,
/**
* The time the message was scheduled to be sent, in epoch time.
* Only present if the message was scheduled to be sent.
*/
@Json(name = "send_at")
val sendAt: Long? = null,
) : IMessage {
/**
* Get the type of object.
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/nylas/resources/Drafts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ class Drafts(client: NylasClient) : Resource<Draft>(client, Draft::class.java) {
val path = String.format("v3/grants/%s/drafts/%s", identifier, draftId)
return destroyResource(path)
}

/**
* Send a Draft
* @param identifier The identifier of the grant to act upon
* @param draftId The id of the Draft to send.
* @return The sent Draft
*/
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
fun send(identifier: String, draftId: String): Response<Message> {
val path = String.format("v3/grants/%s/drafts/%s", identifier, draftId)
val responseType = Types.newParameterizedType(Response::class.java, Message::class.java)
return client.executePost(path, responseType)
}
}

0 comments on commit 598fa65

Please sign in to comment.