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

Local webhook testing support #145

Merged

Conversation

mrashed-dev
Copy link
Collaborator

@mrashed-dev mrashed-dev commented Feb 3, 2023

Description

This PR enables support for local webhook development. 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.

Usage

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");

    WebhookTunnel webhookTunnel = new WebhookTunnel.Builder(application, new HandleNotifications()).build();
    webhookTunnel.connect();
  }
}

class HandleNotifications implements WebhookTunnel.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");
  }
}

License

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.

@mrashed-dev mrashed-dev marked this pull request as ready for review February 6, 2023 13:47
@mrashed-dev mrashed-dev merged commit 4dcd66e into main Feb 6, 2023
@mrashed-dev mrashed-dev deleted the TW-1787-java-release-minor-version-with-webhook-feature branch February 6, 2023 23:16
@mrashed-dev mrashed-dev mentioned this pull request Feb 6, 2023
mrashed-dev added a commit that referenced this pull request Feb 6, 2023
# Description
New Nylas Java SDK release contains the following additions:
* Added local webhook testing support (#145)
* Added new enums for `Webhook.Triggers` and `Webhook.State` (#145)

# 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.
@mrashed-dev mrashed-dev mentioned this pull request Feb 9, 2023
mrashed-dev added a commit that referenced this pull request Feb 9, 2023
# Description
This PR contains multiple small fixes for the Websocket implementation
provided in #145:
* Provide default implementations for `WebhookHandler` methods `onOpen`,
`onClose`, and `onError`
* Fix `Tunnel.onMessage` not emitting individual deltas
* Change `java-websocket` dependency to `api` configuration

# 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants