v1.20.0
This release of the Nylas Java SDK includes a couple of changes, most notably the release of local webhook development support built directly into the SDK. When implementing this feature in your app, the SDK will create a tunnel connection to a websocket server and registers it as a webhook callback to your Nylas account. See below for a usage example.
Release Notes
Added
- Added local webhook testing support (#145)
- Added new enums for
Webhook.TriggersandWebhook.State(#145)
Usage
Webhook Tunnel
During the setup process you can pass in a class that implements WebhookTunnel.WebhookHandler with methods to override the websocket client's callback methods. The most important method is the onMessage method which returns a parsed delta event from the webhook server.
public class NylasWebhook {
public static void main(String[] args) throws Exception {
ExampleConf conf = new ExampleConf();
NylasClient client = new NylasClient();
NylasApplication application = client.application("CLIENT_ID", "CLIENT_SECRET");
Tunnel webhookTunnel = new Tunnel.Builder(application, new HandleNotifications()).build();
webhookTunnel.connect();
}
}
class HandleNotifications implements Tunnel.WebhookHandler {
private static final Logger log = LogManager.getLogger(HandleNotifications.class);
@Override
public void onOpen(short httpStatusCode) {
log.info("OnOpen");
}
@Override
public void onClose(int code, String reason, boolean remote) {
log.info("onClose");
}
@Override
public void onMessage(Notification notification) {
log.info("onMessage");
}
@Override
public void onError(Exception ex) {
log.info("onError");
}
}