Skip to content

v1.8.0

Choose a tag to compare

@mrashed-dev mrashed-dev released this 30 Jul 19:20
· 216 commits to main since this release

This new release of the Nylas Java SDK brings a few new features, most notably support for the Nylas Neural API! More information below on how to use each part of the Neural API through our Node SDK.

New Features

  • Enabled support for Nylas API v2.2
  • Add Event Metadata support (#8)
  • Add support for new RoomResource fields (#13)
  • Add missing getters for Event.Recurrence fields (#14)
  • Add support for Neural API Sentiment Analysis, OCR, Signature Extraction, and Clean Conversations (#15)
  • Add getters for Time.timezone, Timespan.start_timezone, Timespan.end_timezone (#16)

Using New Features

Neural API

To use Sentiment Analysis:

// To perform sentiment analysis on a message, pass in the list of message ID:
List<String> messageIds = new ArrayList<>(Collections.singletonList(MESSAGE_ID));
List<NeuralSentimentAnalysis> messageAnalysis = neural.sentimentAnalysisMessage(messageIds);

// To perform sentiment analysis on just text, pass in a string:
NeuralSentimentAnalysis textAnalysis = neural.sentimentAnalysisText("Hi, thank you so much for reaching out! We can catch up tomorrow.");

To use Signature Extraction:

List<String> messageIds = new ArrayList<>(Collections.singletonList(MESSAGE_ID));
List<NeuralSignatureExtraction> signature = neural.extractSignature(messageIds);

// The method also accepts two optional parameters
// parseContact, a boolean for whether Nylas should parse the contact from the signature (API defaults to true)
// options, an object of options that can be enabled for the Neural endpoint, of type NeuralMessageOptions:
NeuralMessageOptions options = NeuralMessageOptions options = new NeuralMessageOptions()
				.ignoreImages(true)
				.ignoreTables(false)
				.ignoreLinks(true)
				.removeConclusionPhrases(false)
				.imagesAsMarkdown(true)
				.parseContacts(false);
signature = neural.extractSignature(messageIds, true, options);

and to parse the contact and convert it to the standard Nylas contact object:

NeuralSignatureExtraction extractedSignature = extractSignature.get(0);
Contact contact = extractedSignature.getContacts().toContactObject();

To use Clean Conversations:

List<String> messageIds = new ArrayList<>(Collections.singletonList(MESSAGE_ID));
List<NeuralCleanConversation> cleanConversations = neural.cleanConversation(messageIds);

// You can also pass in an object of options that can be enabled for the Neural endpoint, of type NeuralMessageOptions
cleanConversations = neural.cleanConversation(messageIds, options);

and to extract images from the result:

NeuralCleanConversation cleanConvo = cleanConversations.get(0);
neural.extractImages(cleanConvo);

To use Optical Character Recognition:

NeuralOcr ocr = neural.ocrRequest( FILE_ID );

// This endpoint also supports a second, optional parameter for an array specifying the pages that the user wants analyzed:
ocr = neural.ocrRequest( FILE_ID, 2, 3 );

Event Metadata

To create a new event with event metadata, you can create a Map<String, String> with a mapping of key-value pairs for the metadata:

Event event = new Event(calendarId, new Timespan(startTime, endTime));
....
Map<String, String> metadata = new HashMap<>();
metadata.put("event_category", "gathering");
event.setMetadata(metadata);

To query events based on metadata, you can filter on three different parameters:

  • metadata_key (string or array) to filter based on the keys within the metadata object
  • metadata_value (string or array) to filter based on the value within the metadata object
  • metadata_pair (pair of strings; a key and a value) to filter based on the key-value pairs within the metadata object

You can invoke them as such and even chain them:

EventQuery query = new EventQuery()
                .calendarId(calendarId)
                .metadataKey("visitors", "parking")
                .metadataValue("garden")
                .metadataPair("event_category", "gathering");

Room Resources

Currently, the /resource endpoint only supports the GET operation without any extra functionality like filtering. To get a list of all room resource objects attached to your account, you can do the following:

// Initialize and connect to the Nylas client
NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("ACCESS_TOKEN");

RoomResources roomResource = account.roomResources();
List<RoomResource> roomResourceList = roomResource.list();