github nylas/nylas-nodejs v6.8.0

latest releases: v7.5.2, v7.5.1, v7.5.0...
19 months ago

This new release of the Nylas Node SDK brings a few couple of new features, 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

  • Local webhook testing support (#422)
  • Add hideParticipants field to Event (#420)

Usage

Webhook Tunnel

During the setup process you can pass in 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.

const Nylas = require('nylas');
const { openWebhookTunnel } = require('nylas/lib/services/tunnel');
const { WebhookTriggers } = require('nylas/lib/models/webhook');

// Initialize an instance of the Nylas SDK using the client credentials
Nylas.config({
  clientId: "CLIENT_ID",
  clientSecret: "CLIENT_SECRET",
});

// Define the callback for the onMessage event
const onMessageListener = (delta) => {
    if(delta.type === WebhookTriggers.MessageUpdated) {
      console.log("Got message from webhook. Data: " + delta.objectData);
   }
}

// Pass your config in to create, register, and open the webhook tunnel for testing
openWebhookTunnel({
    onMessage: onMessageListener,
    triggers: [WebhookTriggers.MessageUpdated]
}).then(r => console.log("Webhook connected and active. " + r))

Don't miss a new nylas-nodejs release

NewReleases is sending notifications on new releases.