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

Fix issue with sending scheduled messages & Add draft send support #181

Merged
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
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)
}
}