v1.12.0
This release of the Nylas Java SDK comes with a few new features, changes, and fixes!
Release Notes
Added
- Added Outbox support
- Added support for Component CRUD
- Added support for Neural Categorizer
- Added support for
calendar
field in free-busy, availability, and consecutive availability queries - Added field for
phone_number
inParticipant
Changed
- Bump supported API version to v2.4
Fixed
- Fix null error message when
HostedAuthentication.fetchToken()
returns an API error
Deprecated
- Deprecated
checkFreeBusy(Instant, Instant, List<String>)
andcheckFreeBusy(Instant, Instant, String)
in favour ofcheckFreeBusy(FreeBusyQuery)
Using New Features
Outbox
To send a new message through the outbox:
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Outbox outbox = account.outbox();
// Create a new outbox message object
OutboxMessage message = new OutboxMessage();
message.setSubject("With Love, From Nylas");
message.setTo(Arrays.asList(new NameEmail("My Nylas Friend", "[email protected]")));
message.setBody("This email was sent using the Nylas email API. Visit https://nylas.com for details.");
message.setReplyTo(new NameEmail("Your Name", "[email protected]"));
message.setFrom(new NameEmail("Your Name", "[email protected]"));
// Set the outbox-specific parameters
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date dayAfter = calendar.getTime();
message.setSendAt(tomorrow);
message.setRetryLimitDatetime(dayAfter);
// Send the outbox message
OutboxJobStatus jobStatus = outbox.send(outboxMessage);
String outboxJobStatusId = jobStatus.getJobStatusId();
String outboxStatus = jobStatus.getStatus();
OutboxMessage sentMessage = jobStatus.getOriginalData();
You can also avoid creating an OutboxMessage
type, you can just pass in a draft object to send
:
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Outbox outbox = account.outbox();
// Create a new outbox message object
Draft draft = new Draft();
draft.setSubject("With Love, From Nylas");
draft.setTo(Arrays.asList(new NameEmail("My Nylas Friend", "[email protected]")));
draft.setBody("This email was sent using the Nylas email API. Visit https://nylas.com for details.");
draft.setReplyTo(new NameEmail("Your Name", "[email protected]"));
draft.setFrom(new NameEmail("Your Name", "[email protected]"));
// Prepare the outbox-specific parameters
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date dayAfter = calendar.getTime();
// Send the outbox message
OutboxJobStatus jobStatus = outbox.send(draft, tomorrow, dayAfter);
To update an outbox message after sending it
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Outbox outbox = account.outbox();
// Create and send the message object
OutboxMessage message = new OutboxMessage();
message.setSubject("With Love, From Nylas");
message.setTo(Arrays.asList(new NameEmail("My Nylas Friend", "[email protected]")));
message.setBody("This email was sent using the Nylas email API. Visit https://nylas.com for details.");
message.setReplyTo(new NameEmail("Your Name", "[email protected]"));
message.setFrom(new NameEmail("Your Name", "[email protected]"));
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date dayAfter = calendar.getTime();
message.setSendAt(tomorrow);
message.setRetryLimitDatetime(dayAfter);
OutboxJobStatus jobStatus = outbox.send(outboxMessage);
// Modify something in the job status
OutboxMessage sentMessage = jobStatus.getOriginalData();
calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY, 2);
Date newSendAt = calendar.getTime();
sentMessage.setSendAt(newSendAt);
// Update the outbox job
OutboxJobStatus updatedJobStatus = outbox.update(sentMessage, jobStatus.getJobStatusId());
To delete an outbox job
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Outbox outbox = account.outbox();
outbox.delete("JOB_STATUS_ID");
We also support SendGrid operations. To get the authentication and verification status
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Outbox outbox = account.outbox();
SendGridVerification verification = outbox.sendGridVerificationStatus();
verification.isDomainVerified();
verification.isSenderVerified();
To delete a SendGrid user:
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Outbox outbox = account.outbox();
outbox.deleteSendGridSubUser("email_address");
Component CRUD
To create a new component:
Component component = new Component();
component.setName("Java Component Test");
component.setType("agenda");
component.setPublicAccountId("ACCOUNT_ID");
component.setAccessToken(conf.get("access.token"));
component = application.components().save(component);
To get all components:
RemoteCollection<Component> componentList = application.components().list();
To get a specific component:
Component component = application.components().get("{COMPONENT_ID}");
To update a component:
Component component = application.components().get("{COMPONENT_ID}");
component.name = "Updated"
application.components().save(component);
To delete a component:
application.components().delete("{COMPONENT_ID}")
Neural Categorizer
To get the category of a message(s)
import com.nylas.NylasClient;
import com.nylas.NylasAccount;
import com.nylas.Neural;
import com.nylas.NeuralCategorizer;
import java.util.Collections;
import java.util.List;
public class NeuralExample {
public static void main(String[] args) throws RequestFailedException, IOException {
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Neural neural = account.neural();
List<String> messageIds = Collections.singletonList("MESSAGEL_ID");
List<NeuralCategorizer> categorizers = neural.categorize(messageIds);
// The resulting object is an extension of a Message object with a categorize field
NeuralCategorizer categorizer = categorizers.get(0);
String category = categorizer.getCategorizer().getCategory();
String modelVersion = categorizer.getCategorizer().getModelVersion();
Long categorizedAt = categorizer.getCategorizer().getCategorizedAt();
List<String> subcategories = categorizer.getCategorizer().getSubcategories();
}
}
To recategorize a single message
import com.nylas.NylasClient;
import com.nylas.NylasAccount;
import com.nylas.Neural;
import com.nylas.NeuralCategorizer.Category;
public class NeuralExample {
public static void main(String[] args) throws RequestFailedException, IOException {
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Neural neural = account.neural();
// NeuralCategorizer.Category options are "CONVERSATION" and "FEED"
neural.reCategorize("MESSAGEL_ID", Category.CONVERSATION);
}
}
New calendar
field in free-busy, availability, and consecutive availability queries
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Calendars calendars = account.calendars();
// To check free-busy with calendars:
FreeBusyCalendars freeBusyCalendars = new FreeBusyCalendars();
freeBusyCalendars.setAccountId("test_account_id");
freeBusyCalendars.addCalendarIds("example_calendar_id_A", "example_calendar_id_B");
FreeBusyQuery query = new FreeBusyQuery()
.startTime(1590454800)
.endTime(1590780800)
.calendars(freeBusyCalendars);
List<FreeBusy> freeBusyInfo = calendars.checkFreeBusy(query);
// To check availability with calendars:
SingleAvailabilityQuery query = new SingleAvailabilityQuery()
.durationMinutes(30)
.startTime(Instant.now())
.endTime(Instant.now().plus(1, ChronoUnit.HOURS))
.intervalMinutes(10)
.calendars(freeBusyCalendars);
Availability availability = calendars.availability(query);
// To check consecutive availability with calendars:
MultipleAvailabilityQuery consecutiveQuery = new MultipleAvailabilityQuery()
.durationMinutes(30)
.startTime(Instant.now())
.endTime(Instant.now().plus(1, ChronoUnit.HOURS))
.intervalMinutes(10)
.calendars(freeBusyCalendars);
List<List<ConsecutiveAvailability>> consecutiveAvailability = calendars.consecutiveAvailability(consecutiveQuery);